- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
作为我项目的一部分,我将 SteroBM 类用于立体视觉。我正在从 2 个网络摄像头获取输入帧,并在不进行校正的情况下对输入帧灰度帧运行立体 block 匹配计算。我得到的输出与基本事实相去甚远(非常不完整)。我想知道,是不是因为我没有对输入帧进行整改。此外,我选择的基线保持在 20 厘米。我使用的是 opencv-3.2.0 版本的 c++。
我正在运行的代码如下。
#include <opencv2/core.hpp>
#include <opencv2/opencv.hpp>
#include </home/eswar/softwares/opencv_contrib-3.2.0/modules/contrib_world/include/opencv2/contrib_world.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/imgproc.hpp>
#include <stdio.h>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
//initialize and allocate memory to load the video stream from camera
VideoCapture camera0(0);
VideoCapture camera1(1);
if( !camera0.isOpened() ) return 1;
if( !camera1.isOpened() ) return 1;
Mat frame0,frame1;
Mat frame0gray,frame1gray;
Mat dispbm,dispsgbm;
Mat dispnorm_bm,dispnorm_sgbm;
Mat falseColorsMap, sfalseColorsMap;
int ndisparities = 16*5; /**< Range of disparity */
int SADWindowSize = 21; /**< Size of the block window. Must be odd */
Ptr<StereoBM> sbm = StereoBM::create( ndisparities, SADWindowSize );
Ptr<StereoSGBM> sgbm = StereoSGBM::create(0, //int minDisparity
96, //int numDisparities
5, //int SADWindowSize
600, //int P1 = 0
2400, //int P2 = 0
10, //int disp12MaxDiff = 0
16, //int preFilterCap = 0
2, //int uniquenessRatio = 0
20, //int speckleWindowSize = 0
30, //int speckleRange = 0
true); //bool fullDP = false
//-- Check its extreme values
double minVal; double maxVal;
while(true)
{
//grab and retrieve each frames of the video sequentially
camera0 >> frame0;
camera1 >> frame1;
imshow("Video0", frame0);
imshow("Video1", frame1);
cvtColor(frame0,frame0gray,CV_BGR2GRAY);
cvtColor(frame1,frame1gray,CV_BGR2GRAY);
sbm->compute( frame0gray, frame1gray, dispbm );
minMaxLoc( dispbm, &minVal, &maxVal );
dispbm.convertTo( dispnorm_bm, CV_8UC1, 255/(maxVal - minVal));
sgbm->compute(frame0gray, frame1gray, dispsgbm);
minMaxLoc( dispsgbm, &minVal, &maxVal );
dispsgbm.convertTo( dispnorm_sgbm, CV_8UC1, 255/(maxVal - minVal));
imshow( "BM", dispnorm_bm);
imshow( "SGBM",dispnorm_sgbm);
//wait for 40 milliseconds
int c = cvWaitKey(40);
//exit the loop if user press "Esc" key (ASCII value of "Esc" is 27)
if(27 == char(c)) break;
}
return 0;
}
尽管在代码中您看到也使用了 block 匹配,但请忽略它,因为它给出的输出更差。我发现 SGBM 输出更接近真实情况,因此我决定对其进行改进。但是,如果对如何改进 block 匹配结果有任何帮助。太棒了,我当然会很感激。
最佳答案
不,StereoBM不做校正,只是 block 匹配和一些前后处理,但是opencv提供了相机校准和校正检查的功能this link
此外,在 opencv 示例中还有针对此过程的现成示例,因此不必从头开始编写代码。
关于结果,StereoBM是基于SAD算法(local stereo-matching),鲁棒性不强,可以试试wls filter ,这可以显着改善您的结果。
StereoSGBM是基于SGM算法(实际上与原论文介绍的略有不同)的半全局算法,在视差图生成中考虑全局优化,产生更好的视差但速度较慢。
关于c++ - opencv 中的 StereoBM 类是否对输入图像或帧进行校正?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45855725/
我看过很多关于这个问题的帖子,但这个是不同的。我的代码适用于一对图像,但不适用于另一对图像。 稍后,我想将两个摄像头的视频输入转换为立体声输出。我试过了,但也有与下面显示的图像(第二对图像)相同的问题
result left right import numpy as np import cv2 imgL = cv2.imread("C:/Users/admin/jupyter/c
我正在使用这段代码来计算两幅图像之间的差异: l1 = cv2.cvtColor(imgL, cv2.COLOR_BGR2GRAY) l2 = cv2.cvtColor(imgR, cv2.COLOR
我正在尝试在 OpenCV 中使用 StereoBM 从一对图像中提取视差图。忽略下面的视差图质量不好,你可以看到它的左边有一些黑色的柱子对应于参数 ndisparities。我认为 ndispari
我正在尝试增强 stereobm(Opencv 立体 block 匹配)。他们声称该算法使用 SAD cost_function 方法。 (ABOSLUE 差异的 SAD 总和)。 但是在代码中他们以
如果我像这样 decalre 一个 stereoBM 的实例 cv::StereoBM bmState; 编译器抛出错误: cannot declare field ‘bmState’ to be o
我一直致力于使用 StereoBM 类根据两个摄像头输入源生成视差图。 我可以创建一个指向变量 StereoBM *sbm;但是每当我调用一个函数时,都会出现发布版本的段错误。由于 malloc():
我正在尝试使用 StereoBM 获取两幅图像的视差图。我尝试了一些示例代码和图像。他们工作正常。然而,当我尝试自己的图像时,我得到了非常糟糕的 map ,非常嘈杂。 我的 StereoBM 参数 s
作为我项目的一部分,我将 SteroBM 类用于立体视觉。我正在从 2 个网络摄像头获取输入帧,并在不进行校正的情况下对输入帧灰度帧运行立体 block 匹配计算。我得到的输出与基本事实相去甚远(非常
我组装了一个立体摄像头装置,但在使用它制作良好的视差图时遇到了问题。这是两个校正后的图像和我用它们制作的视差图的示例: 如您所见,结果非常糟糕。更改 StereoBM 的设置不会有太大变化。 设置 两
我正在使用 opencv 库进行立体重建。我目前正在测试整流和立体匹配。我使用了 opencv 2.4.9 中的 stereoRectify 函数,我让它工作正常。我使用了来自该站点的测试数据: ht
Konolige 的 block 匹配算法的应用在 OpenCV 文档中没有充分解释。 CvStereoBMState 的参数影响由 cv::StereoBM 计算的差异的准确性。但是,没有记录这些参
当我初始化 StereoBM 对象时,出现错误“无法定义抽象类的对象”。我检查了 calib3d.hpp,发现 StereoBM 是一个抽象类。请给我一个解决方案,如何在 StereoBM 类中定义所
这是我的测试代码,用于实现一个简单的 testBM 算法,没有预过滤。但当窗口尺寸较大时,它需要大约 400 毫秒甚至更多,而 opencv 的 StereoBM(CPU 而非 GPU)需要 20 毫
我正在运行 cv::cuda::StereoBM,它可以在 Tesla K80 上运行。 (计算能力 3.7。)完全相同的代码,具有完全相同的系统库,它卡在 Geforce RTX 2080 Ti 上
我需要你的帮助来解决 OpenCV cv::StereoBM 中的一个问题,因为当我尝试编译以下代码时遇到错误: std::string myImgLeftString = myImgLeft.to
我是一名优秀的程序员,十分优秀!