使用Flow vs SURF进行图像校正

时间:2018-01-11 13:36:18

标签: python-3.x opencv3.0 multiview stereoscopy

我正在尝试运动中的多视图和立体声,但我遇到了一个无法解释或无法正常工作的问题。

我在两个图像(** SURFflow **)上使用了两种不同的方法进行关键点提取,当我并排绘制经过校正的图像时,两种方法的区别太大了,似乎光流技术不适合整改。

(左:SURF,右:光流)Ransac参数(0.1,0.99):

Using SURF Using FLOW

在这里,您可以看到我用来纠正和绘制图像的部分代码:(我在Michael Beleyer's book获得了很多启发)

    self.matcher.extract_keypoints(use_flow=use_flow)
    self.matcher.set_fundamental_matrix()
    self.matcher.set_essential_matrix()
    self.matcher.find_camera_matrices()

    R = self.matcher.Rt2[:, :3]
    T = self.matcher.Rt2[:, 3]

    R1, R2, P1, P2, Q, roi1, roi2 = cv2.stereoRectify(self.matcher.K, self.matcher.d,
                                                      self.matcher.K, self.matcher.d,
                                                      self.matcher.image1.image.shape[:2],
                                                      R, T, alpha=1.0)

    mapx1, mapy1 = cv2.initUndistortRectifyMap(self.matcher.K, self.matcher.d, R1, self.matcher.K,
                                               self.matcher.image1.image.shape[:2],
                                               cv2.CV_32F)
    mapx2, mapy2 = cv2.initUndistortRectifyMap(self.matcher.K, self.matcher.d, R2, self.matcher.K,
                                               self.matcher.image2.image.shape[:2],
                                               cv2.CV_32F)

    rectified1 = cv2.remap(self.matcher.image1.image, mapx1, mapy1, cv2.INTER_LINEAR)
    rectified2 = cv2.remap(self.matcher.image2.image, mapx2, mapy2, cv2.INTER_LINEAR)

    # draw the images side by side
    total_size = (max(rectified1.shape[0], rectified2.shape[0]),
                  rectified1.shape[1] + rectified2.shape[1], 3)
    stacked_images = np.zeros(total_size, dtype=np.uint8)
    stacked_images[:rectified1.shape[0], :rectified1.shape[1]] = rectified1
    stacked_images[:rectified2.shape[0], rectified1.shape[1]:] = rectified2

    # draw horizontal lines every 25 px accross the side by side image
    for i in range(20, stacked_images.shape[0], 25):
        cv2.line(stacked_images, (0, i), (stacked_images.shape[1], i), (255, 0, 0))

    cv2.imshow('Rectified Image', stacked_images)
    cv2.waitKey()

有人可以向我解释为什么两者之间存在这样的差异以及为什么图片中有这么多黑色?

QEdit :为什么图片中有这么多黑色?为什么Ransac参数会如此改变结果呢?我们需要根据以后使用的算法来改变它们吗?

编辑:我发现用于基本矩阵计算(0.1-0.99)的Ransac算法参数太宽,并且捕获了太多不需要的异常值。 (我不确定,所以也欢迎这样的解释)

这就是我得到的(左:SURF,右:光流)Ransac参数(1,0.99):

Using SURF (1-0.99) With flow (1-0.99)

0 个答案:

没有答案