Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I reduce complexity of contour by cv2 python?

Tags:

python

opencv

I have some contour image and I want to obtain more simple contour. For example if there is some litle curves such wool of animal or beard of man than I would like to change it woth simple line. For instance on this image from first picture I want to get second. I use cv2 in it.

like image 916
Nourless Avatar asked Oct 17 '25 13:10

Nourless


1 Answers

OpenCV gives you very basic control with the ContourApproximationModes enum that you pass to the findContours() function:

CHAIN_APPROX_NONE
stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and (x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is, max(abs(x1-x2),abs(y2-y1))==1.

CHAIN_APPROX_SIMPLE
compresses horizontal, vertical, and diagonal segments and leaves only their end points. For example, an up-right rectangular contour is encoded with 4 points.

CHAIN_APPROX_TC89_L1
applies one of the flavors of the Teh-Chin chain approximation algorithm [241]

CHAIN_APPROX_TC89_KCOS
applies one of the flavors of the Teh-Chin chain approximation algorithm [241]

like image 146
Michael Litvin Avatar answered Oct 19 '25 01:10

Michael Litvin