img = cv2.imread('wings-bee.png')
# convert image to grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = np.float32(gray)
'''
args:
img - Input image, it should be grayscale and float32 type.
blockSize - It is the size of neighbourhood considered for corner detection
ksize - Aperture parameter of Sobel derivative used.
k - Harris detector free parameter in the equation.
'''
dst = cv2.cornerHarris(gray, 9, 5, 0.04)
# result is dilated for marking the corners
dst = cv2.dilate(dst,None)
# Threshold for an optimal value, it may vary depending on the image.
img_thresh = cv2.threshold(dst, 0.32*dst.max(), 255, 0)[1]
img_thresh = np.uint8(img_thresh)
# get the matrix with the x and y locations of each centroid
centroids = cv2.connectedComponentsWithStats(img_thresh)[3]
stop_criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)
# refine corner coordinates to subpixel accuracy
corners = cv2.cornerSubPix(gray, np.float32(centroids), (5,5), (-1,-1), stop_criteria)
for i in range(1, len(corners)):
#print(corners[i])
cv2.circle(img, (int(corners[i,0]), int(corners[i,1])), 5, (0,255,0), 2)
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
import cv2
import numpy as np
# load the image as grayscale
img = cv2.imread('xqXid.png',0)
# make a copy to display result
im_or = img.copy()
# convert image to larger datatyoe
img.astype(np.int32)
# create kernel
kernel = np.ones((7,7))
kernel[2:5,2:5] = 0
print(kernel)
#apply kernel
res = cv2.filter2D(img,3,kernel)
# filter results
loc = np.where(res > 2800)
print(len(loc[0]))
#draw circles on found locations
for x in range(len(loc[0])):
cv2.circle(im_or,(loc[1][x],loc[0][x]),10,(127),5)
#display result
cv2.imshow('Result',im_or)
cv2.waitKey(0)
cv2.destroyAllWindows()
您可以使用
Harris corner detector
算法检测上述图像中的静脉连接。与以前的技术相比,Harris corner detector
直接考虑了角点得分相对于方向的差异,而不是每45度角使用移动面片,并且已被证明在区分边和角方面更准确(来源:wikipedia)。你知道吗代码:
输出:
您可以从here检查
Harris Corner detector
算法背后的理论。你知道吗这是一个有趣的问题。我得到的结果并不完美,但可能是个好的开始。我用只看内核边缘的内核过滤图像。其思想是,一个连接至少有3条线穿过内核边缘,其中规则线只有2条。这意味着当内核在一个连接点上时,结果值会更高,因此阈值会显示它们。
由于线路的性质,有一些正值和一些负值。一个关节很可能会被发现好几次,所以你必须考虑到这一点。你可以通过画小点并检测这些小点来使它们独特。你知道吗
结果:
代码:
注意:您可以尝试调整内核和阈值。例如,使用上面的代码,我得到了126个匹配项。但当我使用
带阈值
我在这些地方找到了33根火柴:
相关问题 更多 >
编程相关推荐