0

I have an image that I've for the most part isolated all the information I'd like to work with in. In the image I have several "circles" that I want the contour function to be able to identify. Currently it's settings don't identify them and instead focus on singular pixels in the image.

Link to isolated image (can't embed images yet) : https://i.stack.imgur.com/CmXGK.jpg

contours, hierarchy = cv2.findContours(opening.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)

This is the code I've got to actually identify the contours in the image and it works in a similar image with larger "circles".

I'd like for the image to have circles drawn over the isolated circle areas but I first need to ID them. I'm having trouble figuring out how to do that through the OpenCV documentation and was hopeful someone can help/give advice, thanks!

--Edit This is my pre-processing code

height, width, depth = image.shape
newimg = cv2.resize(image,(int(width/2.5),int(height/2.5)))
img_thresholded = cv2.inRange(newimg, (86, 31, 4), (220, 88, 50))
kernel = np.ones((1,1),np.uint8)
opening = cv2.morphologyEx(img_thresholded, cv2.MORPH_OPEN, kernel)
  • you should mask the image before 'findContours' – Zhubei Federer Aug 02 '19 at 02:01
  • I'm changing the image value to just contain the relevant pixels if that's what you mean, I'll edit the original question to contain my pre-processing code – Ronoc Eroom Aug 02 '19 at 02:06
  • might you provide the original image before and after processing ? – Zhubei Federer Aug 02 '19 at 02:13
  • There are plenty of examples if you just search this forum. For example, see the answer by nathancy at https://stackoverflow.com/questions/57297612/measuring-the-diameter-pictures-of-holes-in-metal-parts-photographed-with-telec/57300051#57300051. That should give you an example to study. – fmw42 Aug 02 '19 at 02:14
  • That's a very interesting thread, I'm looking over it closely, thank you! – Ronoc Eroom Aug 02 '19 at 02:18
  • @Zhubei-Federer I am not allowed to post the original image, sorry – Ronoc Eroom Aug 02 '19 at 02:18
  • @fmw42 Do you think that inverting the current color scheme and the running the dilate mask over it would be a good idea? – Ronoc Eroom Aug 02 '19 at 02:27
  • Okay so I was able to clean up the image a bit more so now it's much less noisy and looks like this --> https://imgur.com/a/T9Un9IR. I can still not detect any circles at all – Ronoc Eroom Aug 02 '19 at 03:00
  • How do you know you have no contours? Have you drawn them onto your image? Perhaps you need to show the whole code and not just snippets. – fmw42 Aug 02 '19 at 03:56
  • I’ve drawn contours onto the image using the regular tutorial method, all the contours that cv2.findContours returns are located in the upper left corner and are about 10-45pixels in size, it doesn’t draw any on the holes it should. – Ronoc Eroom Aug 02 '19 at 03:59

0 Answers0