theory :
In the second derivative , The value at the maximum change is 0, That is, the edge is zero , Calculation by second derivative , According to this theory, we can calculate the second derivative of the image , Extract edge .
Laplance operator
Second derivative I won't , don't worry -> Laplace operator (Laplanceoperator)
Opencv Relevant information has been provided APl- cv::Laplance
Processing flow :
Gaussian blur - De noise GaussianBlur()
Convert to grayscale image cvtColor()
Laplace - Second derivative calculation Laplacian()
Take absolute value convertScaleAbs()
Display results
code :
#include<opencv2/opencv.hpp> #include<iostream> using namespace cv; int
main(int argc, char** argv) { Mat src, dst; src =
imread("C:/Users/ThinkPad/Desktop/1.PNG"); if (!src.data) { printf("could not
find"); return -1; } namedWindow("demo", cv::WINDOW_AUTOSIZE); imshow("demo",
src); Mat gray_src, edge_image; // Gaussian blur GaussianBlur(src, dst, Size(3, 3), 0,
0); // Convert to grayscale cvtColor(dst, gray_src, COLOR_BGR2GRAY); // Laplace operation
Laplacian(gray_src, edge_image, CV_16S, 3); // Absolute value conversion convertScaleAbs(edge_image,
edge_image); // Process edge image threshold(edge_image, edge_image, 0, 255, THRESH_OTSU |
THRESH_BINARY); imshow("final result", edge_image); waitKey(0); return 0; }
Laplace operation without processing , You can see that the noise is a little serious .
add to threshold After processing :
threshold(edge_image, edge_image, 0, 255, THRESH_OTSU | THRESH_BINARY);
Technology
Daily Recommendation