one , Color image to grayscale

Opencv Provides a method , Color image can be changed into gray image .

Function name :cvtColor(src,dest,way);

src Denotes the initial mat object ;

dest Represents the converted mat object ;

way Indicates how to convert .

for instance :
int main() { // Define path string path = "Resources//test.png";
//Mat:opencv Matrix data types introduced , Process all images Mat img = imread(path); // Create a new mat object , Used to store the converted gray image
Mat imgGray; // Gray scale conversion function cvtColor(img, imgGray, COLOR_BGR2GRAY); // Show pictures , And name the picture
imshow("Image", img); // delay , Until we press the close button imshow("ImageGray", imgGray); waitKey(0);
return 0; }
Here's the way COLOR_BGR2GRAY,

That's the explanation :RGB colour to Grayscale .

Running screenshot : 

two , Gaussian blur  

Gaussian blur is essentially a low pass filter , Each pixel of the output image is the weighted sum of the corresponding pixel on the original image and the surrounding pixel .

function :GaussianBlur(src,dest,size(m,n),sigma1,sigma2);

Gaussian blur , third , fourth , The fifth parameter is the degree of Gaussian ambiguity .
Define the kernel size as m*n, The bigger the number, the more fuzzy it is ;
And then there is sigma1 and sigma2, These two numbers are also parameters of fuzzy degree , Can be defined as 0.
// Create a fuzzy object Mat imgBlur; // Gaussian blur , third , fourth , The fifth parameter is the degree of Gaussian ambiguity , // Define the kernel size as 7*7, The bigger the number, the more fuzzy it is ;
// And then there is sigma1 and sigma2, These two numbers can be defined as 0 GaussianBlur(img, imgBlur, Size(7, 7),0,0);
imshow("ImageBlur", imgBlur); waitKey(0);
Running screenshot :

three , edge detection  

We have a lot of edge detectors , Edge contour used to detect image .

The most commonly used is Canny edge detector .

Canny(src,dest,low,high);

Fuzzy processing is usually done before detection .
Two thresholds : Double threshold screening
Set a double threshold , Low threshold (low), High threshold (high).
The gray level change is greater than high Of , Set to strong edge pixel , lower than low Of , eliminate .
// Canny edge detector Mat imgCanny; // Fuzzy processing is usually done before detection // Two thresholds : Double threshold screening
// Set a double threshold , Low threshold (low), High threshold (high). // The gray level change is greater than high Of , Set to strong edge pixel , lower than low Of , eliminate . Canny(imgBlur,
imgCanny, 50, 150); imshow("ImageCanny", imgCanny);
Running screenshot : 

The threshold is 25,75:

 

 

Technology