我有一个来自摄像头的视频文件(360角度)我想打开这个视频文件而不是分离帧但是我不能打开这个视频文件另一方面我可以打开另一个视频文件,它来自vebcam而不是360度角度摄像头 我的代码在这里:
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <stdio.h>
#include <opencv2/objdetect/objdetect.hpp>
#include <sstream>
using namespace std;
using namespace cv;
int main()
{
int counter;
VideoCapture cap("out.avi");
if( !cap.isOpened()){
cout << "Cannot open the video file" << endl;
return -1;
}
double count = cap.get(CV_CAP_PROP_FRAME_COUNT); //get the frame count
cap.set(CV_CAP_PROP_POS_FRAMES,count-1); //Set index to last frame
namedWindow("MyVideo",CV_WINDOW_AUTOSIZE);
Mat frame;
while(1)
{
stringstream file;
bool success = cap.read(frame);
if (!success){
cout << "Cannot read frame " << endl;
break;
}
file << "C:\\" << counter << ".png";
counter++;
// imshow("MyVideo", frame);
imwrite(file.str(),frame);
// if(waitKey(0) == 27) break;
}
}