#include<opencv.hpp>#include<highgui.h>
using namespace cv;voidmain(){
Mat img =imread("opencv-logo.png");// 显示窗口namedWindow("第一课");// 显示图片imshow("第一课", img);// 显示时间为6000mswaitKey(6000);}
图像腐蚀
#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>
using namespace cv;intmain(){
Mat srcimg =imread("1.jpg");imshow("原图", srcimg);
Mat element =getStructuringElement(MORPH_RECT,Size(50,50));
Mat dstimg;erode(srcimg, dstimg, element);imshow("效果图", dstimg);waitKey(0);return0;}
调用摄像头的Canny边缘检测
#include<opencv.hpp>#include<highgui.h>
using namespace cv;voidmain(){
VideoCapture cap;
cap.open(0);if(!cap.isOpened())return;
Mat img;while(1){
cap >> img;Canny(img, img,30,200);if(img.empty())break;imshow("video", img);if(waitKey(20)>0)break;}
cap.release();
destroyAllWindows;}