在opencv c++中播放视频文件
Playing a video file in opencv c++
我正在尝试使用以下代码播放视频文件。
当运行时,它只显示带有窗口名称(视频)的黑屏,有人能帮我修复它吗?
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2corecore.hpp>
#include "opencv2/opencv.hpp"
using namespace cv;
int main( int argc, char** argv )
{
CvCapture* capture = cvCreateFileCapture( "1.avi" );
Mat frame= cvQueryFrame(capture);
imshow("Video", frame);
waitKey();
cvReleaseCapture(&capture);
}
如果您只想播放视频:
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
#include <opencv2corecore.hpp>
#include "opencv2/opencv.hpp"
int main(int argc, char** argv)
{
cvNamedWindow("Example3", CV_WINDOW_AUTOSIZE);
//CvCapture* capture = cvCreateFileCapture("20051210-w50s.flv");
CvCapture* capture = cvCreateFileCapture("1.wmv");
/* if(!capture)
{
std::cout <<"Video Not Openedn";
return -1;
}*/
IplImage* frame = NULL;
while(1) {
frame = cvQueryFrame(capture);
//std::cout << "Inside loopn";
if (!frame)
break;
cvShowImage("Example3", frame);
char c = cvWaitKey(33);
if (c == 27) break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("Example3");
std::cout << "Hello!";
return 0;
}
实际上,您发布的代码甚至不会编译。
看看OpenCV文档:阅读和撰写图像和视频
#include "opencv2/opencv.hpp"
using namespace cv;
int main(int, char**)
{
VideoCapture cap(0); // open the default camera
//Video Capture cap(path_to_video); // open the video file
if(!cap.isOpened()) // check if we succeeded
return -1;
namedWindow("Video",1);
for(;;)
{
Mat frame;
cap >> frame; // get a new frame from camera
imshow("Video", frame);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
相关文章:
- 如何在 c++ 中通过 http 发送大型视频文件?
- 媒体基础将音频流添加到视频文件
- 帧提取 使用OpenCV的视频文件开头只有几秒钟
- 使用 OpenCV C++ 每 1 分钟创建新的视频文件
- 如何检查给定文件是否是C++中的有效视频文件?
- 媒体基础获得视频文件的精确帧(样本)计数
- 如何在不重写整个视频文件的情况下仅替换流中的一个数据框架?(ffmpeg)
- 创建可用的H.264视频文件
- 如何避免在 c++ 中使用 libssh scp 命令压缩从远程 ssh 下载的图像、音频和视频文件?
- 如何使用Windows Media Foundation直接将视频文件直接解码为Direct3D11纹理
- ARtoolkit加载从4k相机索尼捕获的视频文件
- 读取视频文件"Open CV WARNING: Couldn't read movie file bird.avi"时出现问题
- 将视频文件的帧总数保存到.txt文件中
- 从OpenCV C 中的视频文件中检索每三个帧
- 使用来自视频文件或网络摄像头的 Kinect 面部跟踪
- 来自视频文件的QVideo帧列表
- 如何在OpenCV 2.4.3中编写视频文件
- 如何在不使用QMediaPlayer的情况下获取Qt中音频和视频文件的持续时间
- 无法使用 QFileSystemModel 解析不同音频/视频文件的系统目录
- 如何在QT中播放视频文件