读取视频
使用#include
#ifndef __OPENCV_ALL_HPP__
#define __OPENCV_ALL_HPP__
#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/photo/photo.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#endif
#include<opencv2\opencv.hpp>
using namespace cv;//包含cv命名空间,所以省去了cv::Mat前的符号
int main(){
VideoCapture capture("E:\\Homework\\Video\\iss06-10-25_0.avi");
//读取摄像头
//VideoCapture capture(0);
while (1)
{
Mat frame,edges,grayImg;//定义一个 Mat 变量,用于存储每一帧的图像
capture >> frame;//读取当前帧
if (frame.empty())//若视频播放完成,退出循环
{
break;
}
cvtColor(frame, grayImg, CV_BGR2GRAY);
Canny(grayImg, edges, 3, 9, 3);
imshow("avi", frame);
imshow("Canny", edges);
waitKey(1);
}
return 0;
}
视频降噪
#include<opencv2\opencv.hpp>
using namespace cv;//包含cv命名空间,所以省去了cv::Mat前的符号
int main(){
VideoCapture capture("E:\\Homework\\Video\\iss06-10-25_0.avi");
//读取摄像头
//VideoCapture capture(0);
while (1)
{
Mat frame,edges,grayImg;//定义一个 Mat 变量,用于存储每一帧的图像
capture >> frame;//读取当前帧
if (frame.empty())//若视频播放完成,退出循环
{
break;
}
cvtColor(frame, grayImg, CV_BGR2GRAY);
blur(grayImg, grayImg, Size(5, 5));
Canny(grayImg, edges, 3, 9, 3);
imshow("avi", frame);
imshow("降噪处理Canny", edges);
waitKey(1);
}
return 0;
}
读取摄像头
#include "opencv2\opencv.hpp"
using namespace cv;//包含cv命名空间,所以省去了cv::Mat前的符号
int main(){
//读取摄像头
VideoCapture capture(0);
while (1)
{
Mat frame, edges, grayImg;//定义一个 Mat 变量,用于存储每一帧的图像
capture >> frame;//读取当前帧
//此句代码的 OpenCV2 版为:
//cvtColor(frame, grayImg, CV_BGR2GRAY);
//此句代码的 OpenCV3 版为:
cvtColor(frame, grayImg, COLOR_BGR2GRAY);//应用无法正常启动0xc000007b,这是Lib包含了X86和X64,opencv_world300.dll和opencv_world300d.dll要放在SysWOW64文件夹里
blur(grayImg, grayImg, Size(5, 5));
Canny(grayImg, edges, 3, 9, 3);
imshow("avi", frame);
imshow("降噪处理Canny", edges);
//waitKey(1);
if (waitKey(30) >= 0) break;//延时30ms,按空格键终止
}
return 0;
}
针对OpenCV3出现这个问题:
解决方法:
这是Lib包含了X86和X64,opencv_world300.dll和opencv_world300d.dll要放在SysWOW64文件夹里
成功运行结果: