Visual c++ 是否使用open cv显示视频中的第一帧?
我正在研究立体视觉。这里我有两个立体视频。我想做以下事情 1] 从视频中提取第一帧 2] 将帧转换为灰色通道(以便我可以应用冲浪功能) 3] 显示第一帧(下面给出的代码中出现错误) 4] 存储小尺寸的视频(目前为1600*1200) 有人能给我建议怎么做吗? 我的代码如下(用c++编写)Visual c++ 是否使用open cv显示视频中的第一帧?,visual-c++,opencv,image-processing,Visual C++,Opencv,Image Processing,我正在研究立体视觉。这里我有两个立体视频。我想做以下事情 1] 从视频中提取第一帧 2] 将帧转换为灰色通道(以便我可以应用冲浪功能) 3] 显示第一帧(下面给出的代码中出现错误) 4] 存储小尺寸的视频(目前为1600*1200) 有人能给我建议怎么做吗? 我的代码如下(用c++编写) #包括 #包括 #包括 #包括 #包括 #包括 #包括 #包括“opencv2\features2d\features2d.hpp” #包括“opencv2\nonfree\features2d.hpp” #包
#包括
#包括
#包括
#包括
#包括
#包括
#包括
#包括“opencv2\features2d\features2d.hpp”
#包括“opencv2\nonfree\features2d.hpp”
#包括“opencv2\nonfree\nonfree.hpp”
#包括“opencv2\flann\flann.hpp”
#包括“opencv2\contrib\contrib.hpp”
#包括
#包括
#pragma注释(lib,“opencv_core243d”)
#pragma注释(lib,“opencv_highgui243d”)
#pragma注释(lib,“opencv_imgproc243d”)
#pragma注释(lib,“opencv_特性243d”)
#pragma注释(lib,“opencv_nonfree243d”)
#pragma注释(lib,“opencv_flann243d”)
#pragma注释(lib,“opencv_contrib243d”)
#pragma注释(lib,“opencv_calib343d”)
#pragma注释(lib,“opencv_gpu243d”)
使用名称空间std;
使用名称空间cv;
int main(int argc,字符**argv)
{
时钟开始时间=时钟();
长lframecount=0;
//加载视频
视频捕获捕获1(argv[1]);
视频捕获捕获2(argv[2]);
cout您需要使用waitKey(30)或一些延迟来正确显示图像。
还可以使用OpenCV resize()函数调整框架大小。
这是参考资料
您遇到了什么错误?未处理的异常错误
#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";
}