opencv就这么简单, 就这么任性
Posted Montauk
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了opencv就这么简单, 就这么任性相关的知识,希望对你有一定的参考价值。
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
using namespace cv;
#if 0
//腐蚀
int main() {
Mat srcImage = imread("C:\\\\pics\\\\index.jpg");
imshow("srcpic", srcImage);
Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
Mat dstImage;
erode(srcImage, dstImage, element);
imshow("dstpic", dstImage);
waitKey(0);
return 0;
}
#endif
#if 0
int main() {
Mat srcImage = imread("C:\\\\pics\\\\index.jpg");
imshow("均值滤波[原图]", srcImage);
Mat dstImage;
blur(srcImage, dstImage, Size(7, 7));
imshow("均值滤波[效果图]", dstImage);
waitKey(0);
}
int main() {
Mat srcImage = imread("C:\\\\pics\\\\index.jpg");
imshow("均值滤波[原图]", srcImage);
Mat edge,grayImage;
cvtColor(srcImage, grayImage, CV_BGR2GRAY);
blur(grayImage, edge, Size(3, 3));
Canny(edge, edge, 3, 9, 3);
imshow("均值滤波[效果图1]", edge);
Canny(edge, edge, 5, 9, 3);
imshow("均值滤波[效果图2]", edge);
waitKey(0);
}
#endif
int main() {
VideoCapture capture(1);
Mat edges;
while (1) {
Mat frame;
capture >> frame;
cvtColor(frame, edges, COLOR_BGR2GRAY);
blur(edges, edges, Size(7, 7));
Canny(edges, edges, 0, 30, 3);
imshow("canny后的视频", edges);
if (waitKey(30) >= 0) break;
}
return 0;
}
以上是关于opencv就这么简单, 就这么任性的主要内容,如果未能解决你的问题,请参考以下文章
OpenCV这么简单为啥不学——1.5解决putText中文乱码问题
OpenCV这么简单为啥不学——1.9cvtColor颜色空间转换(全色值效果演示)
OpenCV这么简单为啥不学——1.11蓝背景证件照替换白色或红色
OpenCV这么简单为啥不学——2逐帧播放视频(VideoCapture函数waitKey函数0xFF == ord(‘1‘))