A first look at OpenCV

VS2017 has been working on configuring OpenCV for a long time, which is annoying. . .

You can refer to the multiple configurations of this https://www.zhihu.com/question/24400428 province.

#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;
intmain()
{
	Mat srcImage = imread("cat.jpg");

	//Corrosion operation
	//imshow("[Original image] Corrosion operation", srcImage);
	//// Perform corrosion operation
	//Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
	// Mat dstImage;
	// erode (srcImage, dstImage, element);
	////Display renderings
	//imshow("[Rendering] Corrosion operation", dstImage);

	////Fuzzy operation
	//imshow("[Original image]Mean filter", srcImage);
	// Mat dstImage;
	//blur(srcImage, dstImage, Size(7, 7));//Mean filter
	//imshow("Mean filter [effect image]", dstImage);

	//edge detection
	//imshow("[Original image]Canny edge detection", srcImage);
	//Mat dstImage, edge, grayImage;
	//// Create a matrix of the same size type in src
	//dstImage.create (srcImage.size (), srcImage.type ());
	// cvtColor (srcImage, grayImage, COLOR_BGR2GRAY);
	//blur(grayImage, edge, Size(3, 3));//Blur operation
	//Canny(edge, edge, 3, 9, 3);
	//imshow("[Rendering]Edge Detection", edge);

	//play video
	VideoCapture capture(0);//The parameter is a file to play the file, if it is 0, the camera is called to capture
	Mat edges;
	while (1)
	{
		Mat frame;
		capture >> frame;

		// Convert original image to grayscale image
		cvtColor(frame, edges, CV_BGR2GRAY);
		//3*3 noise reduction
		blur(edges, edges, Size(7, 7));
		//edge detection
		Canny(edges, edges, 0, 30, 3);
		imshow("Processed video", edges);
		if (waitKey(30) >= 0)
			break;

		/*imshow("Read video", frame);
		waitKey(30);*/
	}
	waitKey(0);
	return 0;
}

Show the final result


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325935015&siteId=291194637