Opencv divide contacted circles into single

后端 未结 2 1395
清歌不尽
清歌不尽 2020-12-09 14:19

I have an image to process.I need detect all the circles in the image.Here is it.

And here is my code.

import cv2
import cv2.cv as cv
img = cv2.imre         


        
2条回答
  •  不知归路
    2020-12-09 14:55

    I think the first mistake ist the value of thesh. In your example the command cv2.threshold converts all white areas to black and everything else to white. I would suggest using a smaller value for thesh so that all black pixel get converted to white and all white or "colored" pixels (inside the circles) get converted to black or vise versa. The value of thesh should be a little bigger than the brightest of the black pixels.
    See opencv docu for threshold for more information.
    Afterwards I would let opencv find all contours in the thresholded image and filter them for "valid" circles, e.g. by size and shape.
    If that is not sufficiant you could segment the inner circle from the rest of the image: First compute threasholdImageA with all white areas colored black. Then compute threasholdImageB with all the black areas being black. Afterwards combine both, threasholdImageA and threasholdImageB, (e.g. with numpy.logical_and) to have a binary image with only the inner circle being white and the rest black. Of course the values for the threshold have to be chosen wisely to get the specific result. That way also circles where the inner part directly touches the background will be segmented.

提交回复
热议问题