[英]OpenCV: Reading the frames of a video sequence
任何人都可以帮助我,我正在尝试运行代码以从文件夹中的视频读取帧,从而成功地构建了该文件夹,但是在调试时没有任何输出*我正在使用Visual Studio 2012,opencv 2.4.11版本
代码是:
#include "stdafx.h"
#include <opencv2/opencv.hpp>
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
using namespace cv;
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
return 0;
}
int main()
{
// Open the video file
cv::VideoCapture capture("C:/Users/asus/Desktop/A.mp4");
// check if video successfully opened
if (!capture.isOpened())
return 1;
// Get the frame rate
int rate= capture.get(CV_CAP_PROP_FPS);
bool stop(false);
cv::Mat frame; // current video frame
cv::namedWindow("Extracted Frame");
// Delay between each frame in ms
// corresponds to video frame rate
int delay= 1000/rate;
// for all frames in video
while (!stop) {
// read next frame if any
if (!capture.read(frame))
break;
cv::imshow("Extracted Frame",frame);
// introduce a delay
// or press key to stop
if (cv::waitKey(delay)>=0)
stop= true;
}
// Close the video file.
// Not required since called by destructor
capture.release();
}
您的main()
函数永远不会执行。 唯一执行的是_tmain()
,它什么都不做,立即返回。
我有一段时间没有做太多的Windows编程了,但是如果我没记错的话,这就是它的工作方式:为编译器启用Unicode时
int _tmain(int argc, _TCHAR* argv[])
被编译为
int wmain(int argc, wchar * argv[])
然后用作程序入口点。
由于您似乎未在代码中使用任何Windows-API,因此我将忽略Microsoft特定的处理多字节字符串的方法,该方法不可移植,而只需像在main()
函数中那样使用纯ASCII字符串,您打算使用。
因此,要解决您的问题,只需丢弃_tmain()
函数。 如果出现链接器错误,也许还需要在项目设置中禁用Unicode。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.