我正致力于立体视觉。我有两个立体视频。我想做以下事情
1]从视频中提取第一帧。
2]将帧转换为灰色通道(以便我可以应用SURF功能)
3]显示第一帧(在下面给出的代码中得到错误)
4]存储小尺寸的视频(目前为1600 * 1200)
任何人都可以提出建议怎么办? 我的代码如下(用c ++编写)
#include <stdio.h>
#include <iostream>
#include <vector>
#include <time.h>
#include <opencv2\core\core.hpp>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include "opencv2\features2d\features2d.hpp"
#include "opencv2\nonfree\features2d.hpp"
#include "opencv2\nonfree\nonfree.hpp"
#include "opencv2\flann\flann.hpp"
#include "opencv2\contrib\contrib.hpp"
#include <opencv2\calib3d\calib3d.hpp>
#include <opencv2\gpu\gpumat.hpp>
#pragma comment (lib, "opencv_core243d")
#pragma comment (lib, "opencv_highgui243d")
#pragma comment (lib, "opencv_imgproc243d")
#pragma comment (lib, "opencv_features2d243d")
#pragma comment (lib, "opencv_nonfree243d")
#pragma comment (lib, "opencv_flann243d")
#pragma comment (lib, "opencv_contrib243d")
#pragma comment (lib, "opencv_calib3d243d")
#pragma comment (lib, "opencv_gpu243d")
using namespace std;
using namespace cv;
int main(int argc, char**argv)
{
clock_t start_time=clock();
long lframecount=0;
//load the videos
VideoCapture capture1(argv[1]);
VideoCapture capture2(argv[2]);
cout << argv[1] << endl;
cout << argv[2] << endl;
if(!capture1.isOpened()||!capture2.isOpened())
{
cout<<"cant load stereo video";
return -1;
}
Mat frame1,frame2;
capture1>>frame1;
capture2>>frame2;
int num_rows=frame1.rows;
int num_cols=frame1.cols;
std::cout<<"number of rows and colums"<<num_rows<<":"<<num_cols<<std::endl;
int output_rows=num_rows/4;
int output_cols=num_cols/4;
long framecount1= capture1.get(CV_CAP_PROP_FRAME_COUNT);
long framecount2= capture2.get(CV_CAP_PROP_FRAME_COUNT);
VideoWriter write;
write.open("E:\\Vipil\\open_cv_learning\\video\\new22.avi",CV_FOURCC('D','I','V','X'), 30,cv::Size(output_rows,output_cols) ,true);
if (!write.isOpened())
{
std::cout << "cant open output video";
return -1;
}
namedWindow("depthmap",cv::WINDOW_NORMAL);
cv::Point tex(570, 50);
cv::Mat image1;
cv::Mat image2;
for(long i=1;i<6;i++)
{
lframecount++;
int number=lframecount;
string frame;
std::ostringstream convert;
convert<<number;
frame = convert.str();
capture1>> frame1;
capture2>> frame2;
cv::cvtColor(frame1,image1,CV_RGB2GRAY);
cv::cvtColor(frame2,image2,CV_RGB2GRAY);
imshow("image1",frame1);
//cout<<lframecount<<"\n";
}
答案 0 :(得分:0)
您需要使用waitKey(30)或一些延迟才能正确显示图像。 另外,要调整框架大小,您只需使用OpenCV resize()函数即可。 这是参考 http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html