如何实现一个颜色一致的非舔深度地图实时?

2024-09-21 03:21:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从一个未校准的立体相机生成一个实时深度图。我知道算法大致是这样的:

  1. detect keypoints (SURF, SIFT)
  2. extract descriptors (SURF,SIFT)
  3. compare and match descriptors (BruteForce, Flann based approaches)
  4. find fundamental mat (findFundamentalMat()) from these pairs
  5. stereoRectifyUncalibrated()
  6. StereoSGBM

I found this algorithm here: 3d reconstruction from 2 images without info about the camera

我还发现了一个类似的实现:Github 3d reconstruction project

本教程:Stereo 3D reconstruction with OpenCV using an iPhone camera.

在这三个来源的帮助下,我构建了一个测试实现:

    # I size down the original frames
    IMG_L = cv2.resize(IMG_L,(int(WINDOW_WIDTH/3),int(WINDOW_HEIGHT/3)))
    IMG_R = cv2.resize(IMG_R,(int(WINDOW_WIDTH/3),int(WINDOW_HEIGHT/3)))

    window_size = 15
    left_matcher = cv2.StereoSGBM_create(
        minDisparity=0,
        numDisparities=16,
        blockSize=11,
        P1=8 * 3 * window_size ** 2,
        P2=32 * 3 * window_size ** 2,
        disp12MaxDiff=1,
        uniquenessRatio=3,
        speckleWindowSize=1,
        speckleRange=1,
        preFilterCap=63,
        mode=cv2.STEREO_SGBM_MODE_SGBM_3WAY
    )

    right_matcher = cv2.ximgproc.createRightMatcher(left_matcher)

    lmbda = 80000
    sigma = 1.2
    visual_multiplier = 1.0

    wls_filter = cv2.ximgproc.createDisparityWLSFilter(matcher_left=left_matcher)
    wls_filter.setLambda(lmbda)
    wls_filter.setSigmaColor(sigma)

    displ = left_matcher.compute(IMG_L, IMG_R)
    dispr = right_matcher.compute(IMG_R, IMG_L)
    displ = np.int16(displ)
    dispr = np.int16(dispr)
    filteredImg = wls_filter.filter(displ, IMG_L, None, dispr)  # important to put "imgL" here!!!

    filteredImg = cv2.normalize(src=filteredImg, dst=filteredImg, beta=0, alpha=255, norm_type=cv2.NORM_MINMAX);
    filteredImg = np.uint8(filteredImg)

使用这段代码,我生成以下输出:Video

现在你可能看到我的问题了:

  1. 我的深度图在闪烁,而且不是(我怎么称呼它)“颜色一致”
  2. 深度图的质量很差(模糊)
  3. 它太慢,因此不能实时使用

对于第一个问题,我需要一个好的解决方案来消除这种闪烁。有没有办法把之前的深度图考虑进去?你知道吗

对于第二个问题,我可能知道我应该怎么做:我需要校正我的立体图像(如算法的描述所示)。为了纠正这些图像,我需要使用筛选或冲浪。但是我读到SIFT和SURF太慢了,不能实时运行,所以我可能需要其他的解决方案?你知道吗

在我尝试优化程序之前,我将关注第一个和第二个问题,所以您现在可以忽略我的第三个问题(现在)。你知道吗

感谢您的帮助:)


Tags: imgsizematcherfilterwindowcv2leftsurf

热门问题