用python锥度加工的产品检测孔

2024-05-04 12:26:50 发布

您现在位置:Python中文网/ 问答频道 /正文

我想检测这个产品的钻孔和锥度

Original Image

钻孔环绕在圆形边界上。底部的红色圆圈是检测锥度的地方。在

What is to be detected

我试过用霍夫圆探测钻孔

import cv2
import cv2.cv as cv
import numpy as np

img = cv2.imread('DSC_1257.JPG',0)
img = cv2.medianBlur(img,5)
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)


circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,300,
                        param1=40,param2=20,minRadius=15,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)

imS2 = cv2.resize(cimg, (960, 540))
cv2.imshow('detected circles',imS2 )
cv2.waitKey(0)
cv2.destroyAllWindows()

这确实可以检测到钻孔,但也可以检测到其他地方不需要的7个孔。 我只想探测到两个钻孔,什么也没发现更多。可以你能告诉我一个解决这个问题的方法吗


Tags: theimportimgas地方npcv2cv