How to crop circles (found with Hough Transform) in OpenCV?

前端 未结 4 1680
轻奢々
轻奢々 2021-01-25 13:04

I\'m using the code from the page. It works very well and I get a circle that I am looking for. All my image have only 1 circle and I have modified parameters of HoughCirc

4条回答
  •  南笙
    南笙 (楼主)
    2021-01-25 13:41

    To crop circle after circles=HoughCircles(...)

    if len(circles) == 1:
        x, y, r = circles[0][0]
        print x, y, r
        mask = np.zeros((w0,h0),dtype=np.uint8)
        cv2.circle(mask,(x,y),r,(255,255,255),-1,8,0)
        #cv2.imwrite(argv[2],mask)
        out = img*mask
        white = 255-mask
        cv2.imwrite(argv[2],out+white)
    

提交回复
热议问题