栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何将Orb检测器用于图像单应性?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何将Orb检测器用于图像单应性?

这是我的结果。


代码(描述写为注释):

#!/usr/bin/python3# 2017.11.26 23:27:12 CST## Find object by orb features matchingimport numpy as npimport cv2imgname = "box.png"          # query image (small object)imgname2 = "box_in_scene.png" # train image (large scene)MIN_MATCH_COUNT = 4## Create ORB object and BF object(using HAMMING)orb = cv2.ORB_create()img1 = cv2.imread(imgname)img2 = cv2.imread(imgname2)gray2 = cv2.cvtColor(img2, cv2.COLOR_BGR2GRAY)gray1 = cv2.cvtColor(img1, cv2.COLOR_BGR2GRAY)## Find the keypoints and descriptors with ORBkpts1, descs1 = orb.detectAndCompute(gray1,None)kpts2, descs2 = orb.detectAndCompute(gray2,None)## match descriptors and sort them in the order of their distancebf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)matches = bf.match(descs1, descs2)dmatches = sorted(matches, key = lambda x:x.distance)## extract the matched keypointssrc_pts  = np.float32([kpts1[m.queryIdx].pt for m in dmatches]).reshape(-1,1,2)dst_pts  = np.float32([kpts2[m.trainIdx].pt for m in dmatches]).reshape(-1,1,2)## find homography matrix and do perspective transformM, mask = cv2.findHomography(src_pts, dst_pts, cv2.RANSAC,5.0)h,w = img1.shape[:2]pts = np.float32([ [0,0],[0,h-1],[w-1,h-1],[w-1,0] ]).reshape(-1,1,2)dst = cv2.perspectiveTransform(pts,M)## draw found regionsimg2 = cv2.polylines(img2, [np.int32(dst)], True, (0,0,255), 1, cv2.LINE_AA)cv2.imshow("found", img2)## draw match linesres = cv2.drawMatches(img1, kpts1, img2, kpts2, dmatches[:20],None,flags=2)cv2.imshow("orb_match", res);cv2.waitKey();cv2.destroyAllWindows()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/646593.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号