一.图像的Canny算计运用与角点检测
1.1代码详解
# 角点检测
def work01():
img = ndimage.imread('flower.jpg', 'L')#这里是你图片的路径
img1 = feature.canny(img, low_threshold=100, high_threshold=200)
plt.imshow(img1), plt.gray(), plt.show()
dst = cv2.cornerHarris(img, 3, 5, 0.04)
dst = cv2.dilate(dst, None)
# Threshold for an optimal value, it may vary depending on the image.
# cv2.imshow('dst', img)
img[dst > 0.01 * dst.max()] = [255]
plt.imshow(img), plt.gray(), plt.show()
1.2 边缘检测结果
1.3 角点检测结果
二.利用霍夫变换的直线检测
2.1 代码详解
#直线检测
def work02():
img = misc.face()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = img
edges = cv2.Canny(gray, 50, 150, apertureSize=3)
minLineLength = 300
maxLineGap = 10
lines = cv2.HoughLinesP(edges, 1, np.pi / 180, 100, minLineLength, maxLineGap)
for x1, y1, x2, y2 in lines[0]:
cv2.line(img, (x1, y1), (x2, y2), (0), 2)
plt.imshow(img), plt.gray(), plt.show()
2.2 结果
三.利用霍夫变换的原的检测
3.1 代码详解
#圆环检测
def work03():
gray = misc.face(gray=True)
circles = cv2.HoughCircles(gray,cv.CV_HOUGH_GRADIENT,1,20,param1=50,param2=30,minRadius=10,maxRadius=50)
#这里的参数设置minRadius 和 maxRadius为检测的半径范围
circles = np.uint16(np.around(circles))
for i in circles[0, :]:
# draw the outer circle
cv2.circle(gray, (i[0], i[1]), i[2], (0, 255, 0), 2)
# draw the center of the circle
cv2.circle(gray, (i[0], i[1]), 2, (0, 0, 255), 3)
plt.imshow(gray),plt.gray(),plt.show()
3.2 结果