#include "opencv2/calib3d.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/ximgproc/disparity_filter.hpp"
#include <iostream>
#include <string>
using namespace cv;
using namespace cv::ximgproc;
using namespace std;
Point origin; //鼠标按下的起始点
Rect selection; //定义矩形选框
bool selectObject = false; //是否选择对象
Mat xyz;
Rect computeROI(Size2i src_sz, Ptr<StereoMatcher> matcher_instance);
void color_balance(Mat &input)
{
vector<Mat> imageRGB;
//RGB三通道分离
split(input, imageRGB);
//求原始图像的RGB分量的均值
double R, G, B;
B = mean(imageRGB[0])[0];
G = mean(imageRGB[1])[0];
R = mean(imageRGB[2])[0];
//需要调整的RGB分量的增益
double KR, KG, KB;
KB = (R + G + B) / (3 * B);
KG = (R + G + B) / (3 * G);
KR = (R + G + B) / (3 * R);
//调整RGB三个通道各自的值
imageRGB[0] = imageRGB[0] * KB;
imageRGB[1] = imageRGB[1] * KG;
imageRGB[2] = imageRGB[2] * KR;
//RGB三通道图像合并
merge(imageRGB, input);
}
/*****描述:鼠标操作回调*****/
static void onMouse(int event, int x, int y, int, void*)
{
if (selectObject)
{
selection.x = MIN(x, origin.x);
selection.y = MIN(y, origin.y);
selection.width = std::abs(x - origin.x);
selection.height = std::abs(y - origin.y);
}
switch (event)
{
case EVENT_LBUTTONDOWN: //鼠标左按钮按下的事件
origin = Point(x, y);
selection = Rect(x, y, 0, 0);
selectObject = true;
cout << fixed;
cout << origin << "in world coordinate is: " << xyz.at<Vec3f>(origin) << endl;
break;
case EVENT_LBUTTONUP: //鼠标左按钮释放的事件
selectObject = false;
if (selection.width > 0 && selection.height > 0)
break;
}
}
//const String keys =
//"{help h usage ? | | print this message }"
//"{@left |left07.jpg| left view of the stereopair }"
//"{@right |right07.jpg| right view of the stereopair }"
//"{GT || optional ground-truth disparity (MPI-Sintel or Middlebury format) }"
//"{dst_path || optional path to save the resulting filtered disparity map }"
//"{dst_raw_path || optional path to save raw disparity map before filtering }"
//"{algorithm |bm | stereo matching method (bm or sgbm) }"
//"{filter |wls_conf | used post-filtering (wls_conf or wls_no_conf) }"
//"{no-display || don't display results }"
//"{no-downscale || force stereo matching on full-sized views to improve quality }"
//"{dst_conf_path || optional path to save the confidence map used in filtering }"
//"{vis_mult |1.0 | coefficient used to scale disparity map visualizations }"
//"{max_disparity |160 | parameter of stereo matching }"
//"{window_size |-1 | parameter of stereo matching }"
//"{wls_lambda |8000.0 | parameter of post-filtering }"
//"{wls_sigma |1.5 | parameter of post-filtering }"
//;
int main(int argc, char** argv)
{
//CommandLineParser parser(argc, argv, keys);
//parser.about("Disparity Filtering Demo");
//if (parser.has("help"))
//{
// parser.printMessage();
// return 0;
//}
//String left_im = parser.get<String>(0);
//String right_im = parser.get<String>(1);
//String GT_path = parser.get<String>("GT");
//String dst_path = parser.get<String>("dst_path");
//String dst_raw_path = parser.get<String>("dst_raw_path");
//String dst_conf_path = parser.get<String>("dst_conf_path");
//String algo = parser.get<String>("algorithm");
//String filter = parser.get<String>("filter");
//bool no_display = parser.has("no-display");
//bool no_downscale = parser.has("no-downscale");
//int max_disp = parser.get<int>("max_disparity");
//double lambda = parser.get<double>("wls_lambda");
//double sigma = parser.get<double>("wls_sigma");
//double vis_mult = parser.get<double>("vis_mult");
String left_im = "left4.jpg";
String right_im = "right4.jpg";
String GT_path = "None";
String dst_path = "dst.jpg";
String dst_raw_path = "dst_raw.jpg";
String dst_conf_path = "None";
String algo = "bm";
String filter = "wls_conf";
bool no_display = false;
bool no_downscale = false;
int max_disp = 160;
double lambda = 8000.0;
double sigma = 1.5;
double vis_mult = 1.0;
//添加部分
std::string intrinsic_filename = "intrinsics.yml";
std::string extrinsic_filename = "extrinsics.yml";
float scale = 1.;
/*int color_mode = alg == STEREO_BM ? 0 : -1;*/
int color_mode = 0;
Mat img1 = imread(left_im, color_mode);
Mat img2 = imread(right_im, color_mode);
//Mat img1 = imread(img1_filename, 0);
//Mat img2 = imread(img2_filename, 0);
//Mat kernal = (Mat_<int>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
//medianBlur(img1, img1, 3);
//medianBlur(img2, img2, 3);
//filter2D(img1, img1, img1.depth(), kernal);
//filter2D(img2, img2, img2.depth(), kernal);
if (img1.empty())
{
printf("Command-line parameter error: could not load the first input image file\n");
return -1;
}
if (img2.empty())
{
printf("Command-line parameter error: could not load the second input image file\n");
return -1;
}
if (scale != 1.f)
{
Mat temp1, temp2;
int method = scale < 1 ? INTER_AREA : INTER_CUBIC;
resize(img1, temp1, Size(), scale, scale, method);
img1 = temp1;
resize(img2, temp2, Size(), scale, scale, method);
img2 = temp2;
}
Size img_size = img1.size();
Rect roi1, roi2;
Mat Q;
if (!intrinsic_filename.empty())
{
// reading intrinsic parameters
FileStorage fs(intrinsic_filename, FileStorage::READ);
if (!fs.isOpened())
{
printf("Failed to open file %s\n", intrinsic_filename.c_str());
return -1;
}
Mat M1, D1, M2, D2;
fs["M1"] >> M1;
fs["D1"] >> D1;
fs["M2"] >> M2;
fs["D2"] >> D2;
M1 *= scale;
M2 *= scale;
fs.open(extrinsic_filename, FileStorage::READ);
if (!fs.isOpened())
{
printf("Failed to open file %s\n", extrinsic_filename.c_str());
return -1;
}
Mat R, T, R1, P1, R2, P2;
fs["R"] >> R;
fs["T"] >> T;
stereoRectify(M1, D1, M2, D2, img_size, R, T, R1, R2, P1, P2, Q, CALIB_ZERO_DISPARITY, -1, img_size, &roi1, &roi2);
Mat map11, map12, map21, map22;
initUndistortRectifyMap(M1, D1, R1, P1, img_size, CV_16SC2, map11, map12);
initUndistortRectifyMap(M2, D2, R2, P2, img_size, CV_16SC2, map21, map22);
Mat img1r, img2r;
remap(img1, img1r, map11, map12, INTER_LINEAR);
remap(img2, img2r, map21, map22, INTER_LINEAR);
img1 = img1r;
img2 = img2r;
/* Mat canvas;
double sf;
int w, h;
sf = 600. / MAX(img_size.width, img_size.height);
w = cvRound(img_size.width*sf);
h = cvRound(img_size.height*sf);
canvas.create(h, w * 2, CV_8UC3);
cvtColor(img1r, img1r, COLOR_GRAY2BGR);
cvtColor(img2r, img2r, COLOR_GRAY2BGR);
Mat canvasPart = canvas(Rect(w*0, 0, w, h));
resize(img1r, canvasPart, canvasPart.size(), 0, 0, INTER_AREA);
Rect vroiL(cvRound(roi1.x*sf), cvRound(roi1.y*sf),
cvRound(roi1.width*sf), cvRound(roi1.height*sf));
rectangle(canvasPart, vroiL, Scalar(0, 0, 255), 3, 8);
canvasPart = canvas(Rect(w * 1, 0, w, h));
resize(img2r, canvasPart, canvasPart.size(), 0, 0, INTER_AREA);
Rect vroiR(cvRound(roi2.x*sf), cvRound(roi2.y*sf),
cvRound(roi2.width*sf), cvRound(roi2.height*sf));
rectangle(canvasPart, vroiR, Scalar(0, 0, 255), 3, 8);
for (int j = 0; j < canvas.rows; j += 16)
line(canvas, Point(0, j), Point(canvas.cols, j), Scalar(0, 255, 0), 1, 8);
imshow("rectified", c
没有合适的资源?快使用搜索试试~ 我知道了~
双目测距立体匹配BM post filter方法
共50个文件
jpg:19个
tlog:6个
cpp:4个
1星 需积分: 50 23 下载量 101 浏览量
2018-04-01
14:47:33
上传
评论
收藏 14.72MB RAR 举报
温馨提示
立体匹配BM post fiter 算法比BM算法效果好很多,比SGBM算法要快,视差图效果也要好。
资源推荐
资源详情
资源评论
收起资源包目录
stereo_match_fliter.rar (50个子文件)
stereo_match_fliter
x64
Debug
stereo_match.exe 195KB
stereo_match.pdb 3.07MB
stereo_match.ilk 5.09MB
stereo_match
x64
Debug
stereo_match.Build.CppClean.log 2KB
vc140.idb 523KB
stereo_match.obj 602KB
vc140.pdb 900KB
stereo_match.tlog
link.read.1.tlog 14KB
link.command.1.tlog 5KB
stereo_match.lastbuildstate 242B
CL.command.1.tlog 842B
CL.write.1.tlog 908B
CL.read.1.tlog 19KB
link.write.1.tlog 878B
stereo_match.log 1012B
stereo_match_source.cpp 12KB
right6.jpg 518KB
left5.jpg 504KB
left4.jpg 504KB
point_cloud.xyz 7.06MB
left6.jpg 507KB
stereo_calib_c.cpp 10KB
extrinsics.yml 2KB
stereo_match.cpp 17KB
stereo_calib.xml 433B
stereo_match.vcxproj.filters 953B
stereo_calib.vcxproj.filters 953B
stereo_calib.vcxproj 7KB
left1.jpg 504KB
left3.jpg 503KB
left7.jpg 501KB
right1.jpg 518KB
xyz.jpg 416KB
right7.jpg 514KB
stereo_match.vcxproj 7KB
left0.jpg 507KB
left2.jpg 507KB
intrinsics.yml 809B
point_cloud.stl 450KB
right0.jpg 519KB
stereo_calib.cpp 13KB
right3.jpg 518KB
dst.jpg 120KB
right4.jpg 518KB
right2.jpg 519KB
right5.jpg 520KB
dst_raw.jpg 598KB
.vs
stereo_match
v14
.suo 40KB
stereo_match.sdf 16.19MB
Debug
stereo_match.sln 1KB
共 50 条
- 1
资源评论
- tanlichun7892019-01-04效果这么差,也说效果好
Insfan
- 粉丝: 2
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功