OpenCV findContours – What it is?

OpenCV findContours detects change in the image color and marked it as contour.

In this example using archery target face, findContours detects the outer circle, yellow circle, bullseye circle, logos on top left and bottom left.

In this case, findContours doesn’t detect the red circle contour.

The Original Image

archery target face
archery target face

The Image Gray

image gray of target face
image gray of target face

The Find Contours Image

Green color is the contours found on the image.

opencv findcontours on archery target face
opencv findcontours on archery target face

The OpenCV Python Code

 

Conclusion

findContours is an easy way to automatically detect an image shape or outline.

References:

  1. https://docs.opencv.org/4.x/d4/d73/tutorial_py_contours_begin.html
  2. https://medium.com/analytics-vidhya/opencv-findcontours-detailed-guide-692ee19eeb18

 

OpenCV Python Image Perspective Transform

I wanted to learn OpenCV Perspective Transform. Tutorials that I found on the internet bit complex for me to really understand what it is all about. I have to read few tutorials before really understand it.

In layman term, perspective transform is taking a rectangle area from original image and re-project the cut rectangle to our defined size canvas.

To do this, you just need 4 corner pixel points and perspective transform will do all other pixels calculation automatically based on those 4 pixels points.

The Required Pixel Points

The corner pixels points must follow the order as shown in below image.

source pixels positions order
source pixels positions order

This is considered the source pixel points.

The destination points are where you want to re-project those source points into new plane.

The size of destination plane is:

width: 1000 pixels
height: 200 pixels

I just take the source rectangle width and height.

Image Used for the Perspective Transform

I used below image to do the perspective transform.

restaurant original image
restaurant original image

Code on Perspective Transform

Filename: Main.py

To run the program, type at the terminal

 

Folder Structure:

source code folder structure
source code folder structure

Reference

OpenCV Perspective Transform Youtube