opencv 基础操作总结

//#include
//using namespace cv;
#include 
#include 

#include 
#include "opencv2/video.hpp"
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"

using namespace cv;
using namespace std;

/*读取图像*/
int readimg()
{
	Mat img = imread("D://1.jpg");
	imshow("载入图像", img);
	waitKey(0);
	return 0;
}

/*腐蚀*/
int erode()
{
	Mat img = imread("D://1.jpg");
	imshow("原图",img);
	Mat element = getStructuringElement(MORPH_RECT,Size(15,15));
	Mat dstImage;
	erode(img,dstImage,element);
	imshow("效果",dstImage);
	waitKey(0);

	return 0;
}

/*模糊*/
int blur()
{
	Mat srcImage = imread("D://1.jpg");
	imshow("原图",srcImage);
	Mat dstImage;
	blur(srcImage,dstImage,Size(7,7));
	imshow("模糊",dstImage);

	waitKey(0);

	return 0;
}

/*Canny边缘检测*/
int canny()
{
	Mat srcImg=imread("D://1.jpg");
	imshow("原图",srcImg);
	Mat gray,dstImg;
	cvtColor(srcImg,gray,CV_RGB2GRAY);
	blur(gray,dstImg,Size(3,3));
	
	Canny(dstImg,dstImg,50,150,3);

	imshow("canny图像",dstImg);

	waitKey(0);

	return 0;
}

/*读取视频*/
int readvideo()
{
	VideoCapture capture("D:\\工作项目\\模拟视频\\1-上午.MP4");
	while (1)
	{
		Mat frame;
		capture >> frame;

		if (frame.empty())
		{
			break;
		}

		imshow("读取视频",frame);
		waitKey(30);
	}
	return 0;
}

/*读取摄像头*/
int main1()
{
	VideoCapture capture(0);
	while (1)
	{
		Mat frame;
		capture >> frame;
		imshow("camera", frame);
		waitKey(30);
	}
	return 0;
}

/*处理视频*/
int main2()
{
	VideoCapture capture("D:\\工作项目\\模拟视频\\1-上午.MP4");
	while (1)
	{
		Mat frame;
		capture >> frame;
		
		cvtColor(frame,frame,COLOR_RGB2GRAY);
		blur(frame,frame,Size(7,7));

		Canny(frame,frame,50,150,3);
		imshow("被处理后的视频",frame);
		if (waitKey(30) >= 0)break;
	}
	return 0;

}

你可能感兴趣的:(opencv)