您的位置:首页 > 编程语言 > Python开发

Python图像处理(13):brisk特征检测

2015-07-01 20:57 639 查看
快乐虾http://blog.csdn.net/lights_joy/欢迎转载,但请保留作者信息

BRISK是BRIEF描述子的一种改进,相比于BRIEF特征,它具有旋转不变性、尺度不变性和对噪声的鲁棒性。本节尝试在python下使用此特征检测方式,使用的测试图像为先前已经转换为灰度图的棉花图像:



首先读取图像:

# 读取原始图像
img = cv2.imread(r'F:\projects\src\opencv\images\cotton\39.gray.jpg')
plt.imshow(img)

接着创建一个brisk特征检测器:
# 创建brisk检测器
brisk = cv2.BRISK_create()

接下来计算图像的特征,此函数的原型为:
Help on built-in function detectAndCompute:

detectAndCompute(...)
    detectAndCompute(image, mask[, descriptors[, useProvidedKeypoints]]) -> keypoints, descriptors


调用它计算特征点并显示:
# 计算特征点并显示
(kpt, desc) = brisk.detectAndCompute(img, None)
bk_img = img.copy()
out_img = img.copy()
out_img = cv2.drawKeypoints(bk_img, kpt, out_img)
plt.figure(2)
plt.imshow(out_img)

结果就是这样的:


貌似对我们的叶片识别没有直接的帮助,需要自己寻找特征点才行。

直接将原图旋转30度:
# 原图像旋转30度
ang=np.pi/6
rot_mat = np.array([[np.cos(ang), np.sin(ang), 0], [-np.sin(ang), np.cos(ang), 200]])
img_30 = cv2.warpAffine(img, rot_mat, (600,500))
plt.figure(3)
plt.imshow(img_30)


计算新的特征值:
# 特征点检测
(kpt_30, desc_30) = brisk.detectAndCompute(img_30, None)
bk_img = img_30.copy()
out_img = img_30.copy()
out_img = cv2.drawKeypoints(bk_img, kpt_30, out_img)
plt.figure(4)
plt.imshow(out_img)



直接做特征点的匹配:
# 特征点匹配
matcher = cv2.BFMatcher()
matches = matcher.match(desc, desc_30)
print(matches)


最后用图像显示匹配的结果:
# 显示匹配结果,仅显示前面的5个点
matches.sort(None, None, True)
out_img = cv2.drawMatches(img, kpt, img_30, kpt_30, matches[0:5], out_img)
plt.figure(5)
plt.imshow(out_img)



匹配的效果也令人失望。


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: