test_ransac.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:prototype 作者: chutsu 项目源码 文件源码
def setUp(self):
        self.image_height = 600
        self.ransac = VerticalRANSAC(self.image_height)

        # Load test images
        data_path = test.TEST_DATA_PATH
        img0 = cv2.imread(os.path.join(data_path, "vo", "0.png"))
        img1 = cv2.imread(os.path.join(data_path, "vo", "1.png"))

        # Detect features
        tracker = FeatureTracker()
        f0 = tracker.detect(img0)
        f1 = tracker.detect(img1)

        # Convert Features to cv2.KeyPoint and descriptors (np.array)
        kps0 = [cv2.KeyPoint(f.pt[0], f.pt[1], f.size) for f in f0]
        des0 = np.array([f.des for f in f0])
        kps1 = [cv2.KeyPoint(f.pt[0], f.pt[1], f.size) for f in f1]
        des1 = np.array([f.des for f in f1])

        # Perform matching and sort based on distance
        # Note: arguments to the brute-force matcher is (query descriptors,
        # train descriptors), here we use des1 as the query descriptors becase
        # des1 represents the latest descriptors from the latest image frame
        matcher = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
        matches = matcher.match(des1, des0)
        matches = sorted(matches, key=lambda x: x.distance)

        # Prepare data for RANSAC outlier rejection
        self.src_pts = np.float32([kps0[m.trainIdx].pt for m in matches])
        self.dst_pts = np.float32([kps1[m.queryIdx].pt for m in matches])
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号