图像视差(最近物体)

发布于 2025-01-14 06:37:20 字数 1091 浏览 1 评论 0原文

我想从 Python OpenCV 中的图像中提取距离相机最近的物体。我有同一物体的两张图像,但第二张图像稍微旋转了一点。现在我想要的是根据我的视差图创建一个二进制掩码来提取我的对象(后面没有黄色矩形的球)。

1

因此,在读取照片中的两个输入图像(A)和(B)之后,我使用:

    stereo = cv.StereoSGBM_create(numDisparities=16,blockSize=5)
    disparity = stereo.compute(imgL, imgR)

并且由于某种原因,我得到了像(C)这样的结果。我的意思是它清楚地识别了前面的球,但由于某种原因,我在整个图像上看到了白色部分,这对我来说没有意义。所以问题是,由于像这样的视差图,当我使用闭合轮廓的代码来获取仅在球所在位置包含白色的二进制蒙版时:

   se = np.ones((2,2), dtype='uint8')
   image_close = cv.morphologyEx(disparity, cv.MORPH_CLOSE, se)
   plt.imshow(image_close,'gray')
   plt.show()
   cv.waitKey(0)

   thresh_image = image_close.astype(np.uint8)

   cnt = cv.findContours(thresh_image, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)[0]
   mask = np.zeros(disparity.shape[:2], np.uint8)
   cv.drawContours(mask, cnt, -1, 255, -1)

我得到的结果如(D)中所示。所以提取最近的物体(球)的最终结果在(E)中,这与我需要的甚至不接近。任何人都可以向我解释我在这里做错了什么吗?或者有没有更好的方法来提取最近的对象?球后面的黄色矩形存在是有原因的。测试程序是否仅将球识别为最近的物体。

I want to extract closest object to the camera from image in Python OpenCV. I have two images of the same object but second one is just a little bit rotated. Now what I want is to create a binary mask based on my disparity map to extract my object (ball without the yellow rectangle behind it).

1

So after reading my two input images (A) and (B) in the photo) I use:

    stereo = cv.StereoSGBM_create(numDisparities=16,blockSize=5)
    disparity = stereo.compute(imgL, imgR)

and for some reason I get result like (C). I mean it clearly recognizes the ball in the front but for some reason I get that white part across whole image, which dont make sense to me. So problem is that because of disparity map like this when i use the code for closing contours to get binary mask containing white only where the ball is:

   se = np.ones((2,2), dtype='uint8')
   image_close = cv.morphologyEx(disparity, cv.MORPH_CLOSE, se)
   plt.imshow(image_close,'gray')
   plt.show()
   cv.waitKey(0)

   thresh_image = image_close.astype(np.uint8)

   cnt = cv.findContours(thresh_image, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_NONE)[0]
   mask = np.zeros(disparity.shape[:2], np.uint8)
   cv.drawContours(mask, cnt, -1, 255, -1)

I get result like in (D). So the final result of extracting closest object (ball) is in (E), which is not even close to what I need. Can any1 explain to me what I am doing wrong here? Or is there any better method to extract closest object? Yellow rectangle behind the ball is there for a reason. To test if program will recognize only the ball as closest object.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文