1. 程式人生 > >OpenCV3.4呼叫攝像頭+CANNY運算元提取輪廓

OpenCV3.4呼叫攝像頭+CANNY運算元提取輪廓

這份程式碼算上網上的程式碼,修改後可以跑通。注意,如果視窗命名為中文的可能會造成問題,建議用英文的、


#include <opencv2/highgui/highgui.hpp>

#include <opencv2/imgproc/imgproc.hpp>

#include <opencv2/core/core.hpp>



using namespace cv;





int main()

{

	VideoCapture cap(0);

	if (!cap.isOpened())

	{

		return -1;

	}

	Mat frame;

	Mat edges;



	bool stop = false;

	while (!stop)

	{

		cap >> frame;

		cvtColor(frame, edges, CV_BGR2GRAY);

		GaussianBlur(edges, edges, Size(7, 7), 1.5, 1.5);

		Canny(edges, edges, 0, 30, 3);

		imshow("1", edges);

		if (waitKey(30) >= 0)

			stop = true;

	}

	return 0;

}

效果圖: