程序
#include "stdafx.h" //本节讲述 画线、点、矩形、圆形和椭圆.多边形,文本。 等函数; #include <opencv2/opencv.hpp> #include <iostream> using namespace std; using namespace cv; int threshold_value = 50; int threshold_max = 255; //Mat bgImage; //const char *drawdemo_win = "draw shapes and text demo"; Mat addSaltNoise(const Mat srcImage, int n); VideoCapture capture(0); Mat vidio, gray_src, dst4, dst5, frame; void Canny_Demo(int, void*); int main(int argc, char**argv) { Mat src, dst; src = imread("C:/Users/Rubison.DELL/Desktop\\杂物/壁纸/小白2.jpg"); //存放自己图像的路径 if (!src.data) { printf("could not load image...\r\n"); return -1; } //char input_title[] = "原图"; //char output_title[] = "模糊处理"; while (1) { capture >> frame; imshow("原图",frame); cvtColor(frame, vidio, CV_BGR2GRAY); Canny_Demo(0, 0); //imshow("相机", vidio); waitKey(30); } waitKey(0); return 0; } void Canny_Demo(int, void*) { blur(vidio, vidio, Size(3, 3), Point(-1, -1), BORDER_DEFAULT); Canny(vidio, dst4, 50, 100, 3, false); imshow("canny轮廓检测", dst4); dst5.create(frame.size(), frame.type()); //这两行代码是将原像素颜色拷贝到二值图中 imshow("检测dst5", dst5); frame.copyTo(dst5, dst4); //从而生成彩色边缘图 imshow("结果", dst5); }运行结果 头一晃就炸了!!!!!
