高斯模糊
GaussianBlur
灰度转换
cvtColor
计算梯度
Sobel/Scharr
非最大信号抑制
高低阈值输出二值图像
API
cv::Canny(
InputArray src,//8-bit的输入图像
OutputArray edges,//输出边缘图像,一般都是二值图像,背景是黑色
double threshold1,//低阈值,常取高阈值的1/2或者1/3
double threshold2,//高阈值
int aptertureSize.//Soble算子的size,通常3*3,取值3
bool L2gradient//选择true表示是L2来归一化,否则用L1归一化
)
//OpenCV3图像上采样与下采样
//其实就是Mat对象的放大与缩小
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
const char* file = "a.jpg";
//读取图像
Mat img = imread(file);
//如果读取错误
if (img.empty()) {
cout << "img is null" << endl;
}
imshow("img", img);
//转换色彩空间
cvtColor(img, img, CV_BGR2GRAY);
imshow("gray", img);
//均值滤波-降噪声
blur(img, img, Size(3, 3), Point(-1, -1), BORDER_DEFAULT);
imshow("blur_img", img);
//Canny边缘检测
Canny(img, img, 50, 50 * 2, 3, false);
//50为边缘检测相关因素值
imshow("canny_img", img);
waitKey(0);
return 0;
}