我有一个项目,其中一部分将视频处理为一批图像。我在网上找到了一段代码,可以帮助我处理一批图像(如下图所示)
string Img_seq[] = {"flying_plane"};
int size_of_Img_seq = sizeof(Img_seq) / sizeof(Img_seq[0]);
imgpath = argv[1];
if (argc >= 3)
{
TrackingResPath = argv[2];
cout << "The image path is: " << imgpath << endl;
int Seg_num = 1; //for OPE
for (int j = 0; j < size_of_Img_seq; ++j)
{
folder = imgpath + Img_seq[j] + "/*.jpg";
string imgInFormat, imgOutFormat, imgOutFormat1, imgOutFormat2;
ofstream outBB;
imgInFormat = imgpath + Img_seq[j] + "/%05d.jpg";
if (argc >= 3)
{
//add process here
}
}
// get the total number of images in folder
glob(folder, filenames);
int Frames_per_seg = filenames.size(); // for OPE
cout << "Frames_per_seg = " << Frames_per_seg << endl;
for (int k = 1; k <= Seg_num; ++k)
{
sprintf(imgInPath, imgInFormat.c_str(), startFrame);// read image path
sprintf(imgOutPath, imgOutFormat.c_str(), startFrame);
}
我需要使用此过程来处理来自目录或网络摄像头的视频。我尝试了下面提供的一种方法,但它会吐出错误
VideoCapture capture(videoFilename);
if(!capture.isOpened()){
cerr << "Unable to open video file:" << videoFilename << endl;
exit(EXIT_FAILURE);
}
while( (char)keyboard != 'q' && (char)keyboard != 27){
if(!capture.read(frame)){
cerr << "Unable to read next frame" << endl;
cerr << "Exiting" << endl;
exit(EXIT_FAILURE);
}}
stringstream ss;
rectangle(frame, cv::Point(10, 2), cv::Point(100, 20),
cv::Scalar(255, 255, 255), -1);
ss << capture.get(CV_CAP_PROP_POS_FRAMES);
string Img_seq[] = ss.str();
keyboard = waitKey( 30 );
这些错误基本上是由于上述两个代码之间的Img_seq[]
未正确链接。
任何人都可以帮助我了解如何将视频用于批处理逻辑。