一段能用的OpenCV3中利用VideoCapture类进行视频的处理

来源:互联网 发布:win10无法更改mac地址 编辑:程序博客网 时间:2024/06/03 22:53
# 基于OpenCV3.0+ 的VideoCapture类进行本机视频文件的处理OpenCV3.0+ 的各版本已经上线有一两年了,博主接触OpenCV也只是从上月开始,也就是2016年的12月,所以,本着“要学就学新的”的所谓理念,开始了混沌的OpenCV3.0+的应用和学习。之所以称之为“混沌”,因为手头靠谱的资料实在太少了,网上资料很多,但是要么写的简单,要么都是OpenCV2.0+的应用,很多都没法拿来用,贴出一段博主找到的OpenCV3.0+的VideoCapture类的应用代码,附加了Canny的两行。顺便吐个槽:这自学就TM混沌啊,太混沌了,连个帮忙的都没有转载的是下面这位仁兄的代码:http://blog.csdn.net/dengshuaifei/article/details/51213609在此表示感谢。
#include<opencv2\core\core.hpp>#include<opencv2\imgproc\imgproc.hpp>#include<opencv2\highgui\highgui.hpp>#include<iostream>#include<stdio.h>#include <time.h>using namespace std;using namespace cv;int main(){VideoCapture capture("d:\\ipman\\ipman.mkv");if (!capture.isOpened())return 1;double rate = capture.get(CV_CAP_PROP_FPS);bool stop(false);Mat frame;namedWindow("Canny Video");int delay = 1000 / rate;while (!stop){if (!capture.read(frame))break;Mat result;Canny(frame, result, 100, 200);threshold(result, result, 128, 255, THRESH_BINARY);imshow("Canny Video", result);if (waitKey(delay) >= 0)stop = false;}//capture.release();}

0 0