OpenCV dot target detection not finding all targets, and found circles are offset

前端 未结 3 660
醉酒成梦
醉酒成梦 2020-12-08 12:20

I\'m trying to detect the center of black/white dot targets, like in this picture. I\'ve tried to use the cv2.HoughCircles method but 1, am only able to detect 2 to 3 target

3条回答
  •  死守一世寂寞
    2020-12-08 12:53

    Most Detect Circles using Python Code

    import cv2
    import numpy as np
    
    img = cv2.imread('coin.jpg')
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray,(7,9),6)
    cimg = cv2.cvtColor(blur,cv2.COLOR_GRAY2BGR)
    circles = cv2.HoughCircles(blur,cv2.HOUGH_GRADIENT,1,50,
                                param1=120,param2=10,minRadius=2,maxRadius=30)
    
    
    circles = np.uint16(np.around(circles))
    for i in circles[0,:]:
        # draw the outer circle
        cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
        # draw the center of the circle
        cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)
    
    cv2.imshow('detected circles',cimg)
    cv2.waitKey(0)
    cv2.destroyAllWindows()
    

提交回复
热议问题