OpenCV视频读取、显示、保存
发布日期:2021-05-09 12:08:06 浏览次数:3 分类:技术文章

本文共 2058 字,大约阅读时间需要 6 分钟。

提前配置:

OpenCV:

代码:

(1)Iplimage类型

#include 
#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"using namespace std;using namespace cv;int main(){ string video_dir = "F:\\1.mp4"; string saveDir = "./image/"; CvCapture *capture = NULL; IplImage *frame = NULL; IplImage* temp = NULL; IplImage *dst = NULL; capture = cvCreateFileCapture(video_dir.c_str());//最后要cvReleaseCapture(&capture); int src_frame_width = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_WIDTH);//获取视频的宽 int src_frame_height = (int)cvGetCaptureProperty(capture, CV_CAP_PROP_FRAME_HEIGHT);//获取视频的高 CvSize size; size.width = src_frame_width; size.height = src_frame_height; temp = cvCreateImage(size, IPL_DEPTH_8U, 1);//创建目标图像 CvSize dstSize = cvSize(temp->width / 8, temp->height / 8); dst = cvCreateImage(dstSize, temp->depth, temp->nChannels); char savePath[100]; int pictureNumbers = 0; cvNamedWindow("video"); while (1) { frame = cvQueryFrame(capture); cvCvtColor(frame, temp, CV_BGR2GRAY);//cvCvtColor(src,des,CV_BGR2GRAY) cvResize(temp, dst, CV_INTER_LINEAR); cvShowImage("video", dst); sprintf(savePath, "%s/%04d.jpg", saveDir, pictureNumbers); cvSaveImage(savePath, dst); cvWaitKey(1); } cvReleaseCapture(&capture); cvReleaseImage(&dst); cvDestroyAllWindows(); return 0;}

更多《计算机视觉与图形学》知识,可关注下方公众号:

 

 

#include 
#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"using namespace std;using namespace cv;int main(int argc, char **argv) { //视频路径 string videoPath = "D:\\1.mp4"; //图像保存路径 string saveImagePath = "D:/image/1"; char saveChar[200]; // 创建了一个名为video的窗口用来显示帧 cv::namedWindow("video", cv::WINDOW_AUTOSIZE); cv::VideoCapture cap; // 读取视频文件 cap.open(videoPath); cv::Mat frame; int imageCount = 0; while (true) { // 按帧读取 cap >> frame; if (frame.empty()) break; cv::imshow("video", frame); sprintf(saveChar, "%s/%04d.jpg", saveImagePath, imageCount); cout << saveChar << endl; imwrite(saveChar, frame); imageCount++; if (cv::waitKey(33) >= 0) break; } destroyAllWindows(); return 0;}

转载地址:https://blog.csdn.net/CSS360/article/details/89418994 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:CVPR2019资源汇总
下一篇:GAN原理介绍及论文&代码汇总

发表评论

最新留言

第一次来,支持一个
[***.219.124.196]2023年09月08日 20时11分39秒