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

 

Python Unit Test Error: AttributeError has no attribute test

I got AttributeError: has no attribute ‘test’ when I run python unit test.

The cause of the error is due to file naming that has ‘filename.test.py’. So I change into test_filename.py then it works!

 

Python Circular Import Error if Import CSV or Pandas read_csv

I faced issue of circular import error when import CSV or pandas to read cvs file.
My python file name is csv.py

To rectify this is very easy. Ensure your file name is not CSV. If file name is CVS it will cause circular import.

Circular Import when file name is csv.py

python import csv or pandas cause circular import
python import csv or pandas cause circular import

No more circular import error when file name change to csv-reader.py

python import csv or pandas caused circular import if file name is csv
python import csv or pandas caused circular import if file name is csv

What is Python Numpy Array Dimension or Axis?

I’m beginner in Python & Numpy. Most tutorials I found seems for expert without really explaining the basic of it.

Even understanding what axis represents in Numpy array is difficult.

I have to read few tutorials and try it out myself before really understand it.

I will update it along with my growing knowledge.

1. Numpy Array Properties

1.1 Dimension

Important to know dimension because when to do concatenation, it will use axis or array dimension.

python array and axis - source oreilly
python array and axis – source oreilly

Row – in Numpy it is called axis 0

Columns – in Numpy it is called axis 1

Depth – in Numpy it is called axis 2

Python Example

Output

Snippet

References

https://www.datacamp.com/community/tutorials/python-numpy-tutorial
https://www.oreilly.com/library/view/elegant-scipy/9781491922927/ch01.html