Image Processing with OpenCV

Abhishek Kumar
3 min readJun 9, 2021

--

In this article, we will see various practical tasks of image processing in Python.

Task 4.1: Create an image with python code in cv2.

Step 1: Code of creating an chessboard image with opencv and numpy

Step 2 : Output displayed with ‘imshow()’ method of cv2 showing the 8X8 chessboard.

8X8 chessboard created with python.

Task 4.2: Swapping the faces of two images after cropping.

Step 1: First we loaded both images with ‘imread()’ method. After loading we detected and selected the face on photo 1 using Cascade Classifier method of cv2.

Step 2: Output of detected face on photo 1.

Photo 1

Step 3: Then we detected and selected the face on photo 2.

Step 4: Output of detected face on photo 1.

Photo 2

Step 5: Swapped the face of photo 1 with photo 2 detected face.

Step 6: Final output with swapped faces.

Final output with the swapped face of photo 2 in photo 1.

Task 4.3: Combining two images into one by forming a collage.

Step 1: First loaded two images using ‘imread()’ method of cv2 and resized both the photo with the same dimensions. After, combined both the resized photo in a horizontal manner using ‘hstack()’ method of numpy.

Step 2: Output of the two loaded pictures which will be combined.

Photo 1
Photo 2

Step 3: Final output displaying a collage image of both pictures into one picture

Collage of Photo 1 and Photo 2 into a single picture.

Thanks for reading this article :)

--

--