- Create an image by yourself Using Python Code.
- Take 2 images, crop some parts of both images, and swap them.
- Take 2 images and combine them to form a single image.
We will be using the cv2 library of python which is the Computer Vision library. It is the huge open-source library for computer vision, machine learning, and image processing and now it plays a major role in real-time operation which is very important in today’s systems and it supports various languages, the default color order is BGR i.e Blue Green Red.
Pip install opencv-python
OpenCV can be downloaded with the help of this command.
img = cv2.imread(‘by.jpg’,1)
Here the ‘img’ is the variable in which we are storing the image and imread() is used to read the image, followed by the path of an image and integer 0 and 1 where 0 is for grayscale and 1 for colored.
In these examples imshow() is used to display the image and waitkey() functions display the image until any key is pressed and destroyAllWindows() destroys the image when a key is clicked.
Task 4.1 Create an image by yourself Using Python Code.
For this, first I have taken a black picture for the canvas and drawn elements like line, circle, square, etc to form an image.
The syntax for line is photo_name = cv2.line(photo_name, (start_x,start_y), (end_x,end_y), (B,G,R), thickness)
The syntax for circle is photo_name = cv2.circle(photo_name, (centre_x,centre_y), radius, (B,G,R), thickness)
The syntax for rectangle is photo_name = cv2.rectangle(photo_name, (point1_x,point1_y), (point2_x, point2_y), radius, (B,G,R), thickness)
Task 4.2 Take 2 images, crop some parts of both images, and swap them.
For this, two images are taken first loaded and read in the python then one part of the image is cropped by specifying its coordinates and replacing that cropped part with another image with the help of a third variable.
crop_img = img[20:200, 40:240]
photo[20:200, 40:240] = crop_img
Task 4.3 Take 2 images and combine them to form a single image.
For this we have taken two images and combined them to form a collage, it is done with the help of hstack and vstack function which arranges it horizontally and vertically respectively.
Thank you for reading!!!