How can I highlight the contours of touching objects using an ereda?

I get this problem:

http://img38.imageshack.us/img38/5856/questao.png

I use Python and OpenCV. I am trying to separate the contours of touching coins using erosion. I spawned an image and then tried to apply erosion, but nothing happened. I read the documentation and still do not understand very well how getStruturingElement and erode work.

  • I set the image.

  • an erection on the threshold image is used.

and still nothing. What am I misusing here?

Here is the piece of code:

 import cv2, numpy as np #1.Reads Image objectImage = cv2.imread('P1000713s.jpg') #2.Converts to Gray level cvtcolorImage = cv2.cvtColor(objectImage,cv2.cv.CV_RGB2GRAY) #3.Thresholds imgSplit = cv2.split(objectImage) flag,b = cv2.threshold(imgSplit[2],0,255,cv2.THRESH_OTSU) #4.Erodes the Thresholded Image element = cv2.getStructuringElement(cv2.MORPH_CROSS,(3,3)) cv2.erode(b,element) cv2.imshow('Eroded',b) 
+4
source share
2 answers

Looking at your image, it is possible that a 3x3 cross-mask will always be within the threshold area. Instead of using MORPH_CROSS, use MORPH_ELLIPSE.

If the coins still β€œtouch” after one call, you can always start several calls for erosion, but be careful that this will have a devastating effect on your image.

+1
source

I know this is an old question, but I had similar problems, and I found this problem through Google.

As far as I know, cv2.erode () does not change the original image, instead it returns a new image with the change applied.

changing your line containing the erode call to:

 b = cv2.erode(b,element) 

should see changes when you call cv2.imshow (..., b)

+1
source

Source: https://habr.com/ru/post/1446674/


All Articles