Home > other >  The image contour extraction
The image contour extraction

Time:10-24

Have an image as shown below, wrote a piece of code take its contour, the result is bad, which master can see what's the problem? Have plagued several days, watched a lot of posts, but still didn't find a way, please help!

The import cv2

# read source map
Img=cv2. Imread (" 1. JPG ")

Cv2. NamedWindow (" image ", 0)
Cv2. Imshow (' image 'img)

Imgray=cv2. CvtColor (img, cv2 COLOR_BGR2GRAY)
Ret, binary=cv2. Threshold (imgray, 127255, cv2. THRESH_BINARY)

# for contour
Contours, hierarchy=cv2. FindContours (binary, cv2. RETR_TREE, cv2 CHAIN_APPROX_SIMPLE)

# draw the outline of different
For contour in contours:
If len (contour) & gt; 50:
Img=cv2. DrawContours (img, contour, 1, (0, 0, 255), 3)

# display and save the results
Cv2. Imshow (contour "  ", img)

Cv2. WaitKey (0)
Cv2. DestroyAllWindows ()

CodePudding user response:

Their top, which can help look at it?
  • Related