Python+OpenCV:Feature Matching + Homography to find Objects

####################################################################################################
# 图像特征匹配(Feature Matching with Homography)
def lmc_cv_image_feature_matching_homography():"""函数功能: 图像特征匹配(Feature Matching with FLANN)。"""# 读取图像image1 = lmc_cv.imread('D:/99-Research/Python/Image/Brochure01.jpg', lmc_cv.IMREAD_GRAYSCALE)image2 = lmc_cv.imread('D:/99-Research/Python/Image/Brochure02.jpg', lmc_cv.IMREAD_GRAYSCALE)# Initiate SIFT detectormin_match_count = 10sift = lmc_cv.SIFT_create()# find the keypoints and descriptors with SIFTkeypoints1, descriptors1 = sift.detectAndCompute(image1, None)keypoints2, descriptors2 = sift.detectAndCompute(image2, None)flann_index_kdtree = 1index_params = dict(algorithm=flann_index_kdtree, trees=5)search_params = dict(checks=50)flann = lmc_cv.FlannBasedMatcher(index_params, search_params)matches = flann.knnMatch(descriptors1, descriptors2, k=2)# store all the good matches as per Lowe's ratio test.good = []for m, n in matches:if m.distance < 0.7 * n.distance:good.append(m)if len(good) > min_match_count:src_pts = np.float32([keypoints1[m.queryIdx].pt for m in good]).reshape(-1, 1, 2)dst_pts = np.float32([keypoints2[m.trainIdx].pt for m in good]).reshape(-1, 1, 2)m, mask = lmc_cv.findHomography(src_pts, dst_pts, lmc_cv.RANSAC, 5.0)matches_mask = mask.ravel().tolist()h, w = image1.shapepts = np.float32([[0, 0], [0, h - 1], [w - 1, h - 1], [w - 1, 0]]).reshape(-1, 1, 2)dst = lmc_cv.perspectiveTransform(pts, m)img2 = lmc_cv.polylines(image2, [np.int32(dst)], True, 255, 3, lmc_cv.LINE_AA)else:print("Not enough matches are found - {}/{}".format(len(good), MIN_MATCH_COUNT))matches_mask = Nonedraw_params = dict(matchColor=(0, 255, 0),  # draw matches in green colorsinglePointColor=None,matchesMask=matches_mask,  # draw only inliersflags=2)# cv.drawMatchesKnn expects list of lists as matches.result_image = lmc_cv.drawMatches(image1, keypoints1, image2, keypoints2, good, None, **draw_params)# 显示图像pyplot.figure('Feature Matching with FLANN and Homography')pyplot.subplot(1, 1, 1)pyplot.imshow(result_image, 'gray')pyplot.title('Feature Matching with FLANN and Homography')pyplot.xticks([])pyplot.yticks([])# 根据用户输入保存图像if ord("q") == (lmc_cv.waitKey(0) & 0xFF):# 销毁窗口pyplot.close('all')return

Python+OpenCV:Feature Matching + Homography to find Objects相关推荐

  1. Python+OpenCV:特征匹配(Feature Matching)

    Python+OpenCV:特征匹配(Feature Matching) Basics of Brute-Force Matcher Brute-Force matcher is simple. It ...

  2. Python+OpenCV:尺度不变特征变换 (SIFT, Scale-Invariant Feature Transform)

    Python+OpenCV:尺度不变特征变换 (SIFT, Scale-Invariant Feature Transform) 理论 A corner in a small image within ...

  3. Python+OpenCV:模板匹配(Template Matching)

    Python+OpenCV:模板匹配(Template Matching) Template Matching with Single Objects ######################## ...

  4. Python+OpenCV:ORB: An efficient alternative to SIFT or SURF

    Python+OpenCV:ORB: An efficient alternative to SIFT or SURF 理论 As an OpenCV enthusiast, the most imp ...

  5. Python+OpenCV:图像二进制鲁棒独立基本特征(BRIEF, Binary Robust Independent Elementary Features)

    Python+OpenCV:图像二进制鲁棒独立基本特征(BRIEF, Binary Robust Independent Elementary Features) 理论 We know SIFT us ...

  6. Python+OpenCV:尺度不变特征变换(SIFT)的加速健壮特性(SURF)

    Python+OpenCV:尺度不变特征变换(SIFT)的加速健壮特性(SURF) 理论 In SIFT, Low approximated Laplacian of Gaussian with Di ...

  7. Python+OpenCV:训练级联分类器(Cascade Classifier Training)

    Python+OpenCV:训练级联分类器(Cascade Classifier Training) Introduction Working with a boosted cascade of we ...

  8. Python+OpenCV:级联分类器(Cascade Classifier)

    Python+OpenCV:级联分类器(Cascade Classifier) 目标 We will learn how the Haar cascade object detection works ...

  9. Python+OpenCV:图像修复(Image Inpainting)

    Python+OpenCV:图像修复(Image Inpainting) 理论 Most of you will have some old degraded photos at your home ...

最新文章

  1. Apache Maven 安装与配置-修改源
  2. luogu Cantor表
  3. 简述相关与回归分析的关系_分类数据与分类数据的相关关系分析
  4. hdu 3371 Connect the Cities(prim算法)
  5. 汇编proto、proc、invoke伪指令与函数声明、函数定义、函数调用
  6. 计算机毕业设计java+SSM网上购物超市网站(源码+系统+mysql数据库+Lw文档)
  7. WordPress清理和优化数据库,推荐几个优秀插件
  8. ONLYOFFICE历史版本功能的开发技术之一
  9. 嵌入式——模块化编程
  10. 解读txt文件中的乱码
  11. Facebook POP 进阶指南
  12. UE4开关门简单记录
  13. Tushare数据获取(python)
  14. 【notes|奇点临近】chapter1
  15. 卧操,女性私密数据曝光,原来富婆都在广西…
  16. 11.9 leetcode打卡
  17. 零基础学习数据分析路线,学习到什么程度可以找到工作
  18. java潜龙谍影,我的世界:三个选择下界合金装备的理由!下界合金到底有多稀有?...
  19. CVE-2014-6271“破壳”漏洞
  20. 潭州学院java大型企业内部技术_【JAVA教程】分享5款课提高Java开发性能的调试工具-潭州JAVA...

热门文章

  1. C++11 POD 类型
  2. tomcat的acceptCount、maxThreads、connectionTimeout参数调整
  3. 6月14 空控制器和空操作及命名空间
  4. oracle DML错误日志(笔记)
  5. 省市区三级联动菜单(附数据库)
  6. Linux之文件属性详解
  7. Linux之cd命令
  8. docker执行容器内的shell_为什么不建议把数据库部署在docker容器内?
  9. 互联网搜索的哪些环节 机器学习_什么是机器学习?有哪些分类?到底有什么用?终于有人讲明白了...
  10. 数学 - 线性代数导论 - #9 Ax=b的解:存在性、解法、解的结构、解的数量