使用houghCircles(OpenCV和Python)检测轮廓中的点

时间:2019-06-01 15:06:58

标签: python opencv object-detection hough-transform

我正在尝试使用houghcircles()检测拍摄轮廓图像中的点。我尝试更改其参数,但查找点时效率不高,还尝试使用一些OpenCV方法,但无法准确检测到点

这是原始图像:
enter image description here

申请方法及最终结果: 具有功能的图像(左),检测结果(右)

enter image description here

这是我的代码:

import numpy as np
import cv2

im = cv2.imread('silhouette.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret0,thresh0 = cv2.threshold(imgray,180,200,cv2.THRESH_TRUNC)

ret,thresh = cv2.threshold(thresh0,40,255,cv2.THRESH_BINARY)

kernel = np.ones((2, 2), np.uint8)
mask = cv2.erode(thresh, kernel, iterations=2)
mask = cv2.GaussianBlur(mask,(7,7),0)

circles = cv2.HoughCircles(mask,cv2.HOUGH_GRADIENT,2,6,
                        param1=50,param2=8,minRadius=1,maxRadius=13)

imgray = cv2.cvtColor(imgray, cv2.COLOR_GRAY2BGR) 

if circles is not None:
    circles = np.uint16(np.around(circles))

for i in circles[0,:]:
    cv2.circle(imgray,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center imof the circle
    cv2.circle(imgray,(i[0],i[1]),2,(0,0,255),2)


cv2.imshow('detecion', imgray)
cv2.waitKey(0)
cv2.destroyAllWindows()

请问,有什么想法可以改善对点的检测?

0 个答案:

没有答案