Write on pictures these are basic operations needed to create a base before moving on to be able to use all the advanced features that opencv offers. For the following examples we will use jupyter as the python ide. Import images in opencv to be able to import images in opencv, follow these steps: 1) import the necessary libraries import images 1 2) read the image using the imread function . For this example we will use the image of the mandrel (you can download it here ) import images 2 3) choose the type and shape of the matrix .
With the following code we will transform the image into a numpy matrix with a shape of 1300×1950 and with 3 channels. Import images 3 4) see the image e commerce photo editing service import images 4 import images 5 what we get as a result is a bit different with respect to color. We expected a brightly colored image, but what we get is an image with a slight bluish tint. That happens because opencv and matplotlib have different primary color orders . While opencv reads images in the form of bgr , matplotlib on the other hand follows the rgb order . Therefore, when we read a file through opencv, we read it as if it contained channels in the order of blue, green, and red.
However, when we display the image using matplotlib, the red and blue channels are swapped and hence the blue tint. To avoid this problem, we will transform the channel to the way matplotlib expects the cvtcolor function to be used . Import images 6 import images 7 save images images can be saved to the working directory as follows: save picture where “ final_image ” is the name of the image to be saved. Basic image operations finally we are going to see how we can draw various shapes on an existing