I haven't made a summary for a while. I don't know what I'm busy with every day! Now it takes an hour to summarize the learning in the last few days.
Edge detection technology is the first step in image analysis. It uses the extreme values of the first derivative of the image or the zero point information of the second derivative to extract the edge.
To put it simply, it is the problem of gray-scale image changes. In some places, image changes are slow, so the first derivative of the image is small or even zero, and the change is large in areas where changes are intense. The gradient mentioned in the book is equivalent to the derivative, but it has its own direction. The second derivative is used to determine whether the pixel is on the bright side of the edge or on the dark side.
These words illustrate the basic theories and methods of edge detection.
How to implement it in opencv! Convolution is implemented by using images and different operators. Here I divide opencv into two camps.
First camp: there is a letter: there are specific functions in opencv, we just need to call it. This is easy to do.
Mainly include Sobel, canny, and Laplace.
cvSmooth(img_Elged_src,img_Elged_8u,CV_GAUSSIAN,3,0,0);
//cvShowImage("Elged",img_Elged_8u);cvSobel(img_Elged_8u,img_Elged_16S,m_nSobelx,m_nSobely,m_nKernel);//cvSobel(img_Elged_8u,img_Elged_16S,0,1,3);cvConvertScaleAbs(img_Elged_16S,img_Elged_dest,1,0);cvShowImage("Elged",img_Elged_dest);
cvSmooth(img_Elged_src,img_Elged_8u,CV_GAUSSIAN,3,0,0); cvCanny(img_Elged_8u,img_Elged_dest,m_nCanny1,m_nCanny2,m_nKernel); cvShowImage("Elged",img_Elged_dest);
cvSmooth(img_Elged_src,img_Elged_8u,CV_GAUSSIAN,3,0,0); cvLaplace(img_Elged_8u,img_Elged_16S,m_nKernel); cvConvertScaleAbs(img_Elged_16S,img_Elged_dest,1,0); cvShowImage("Elged",img_Elged_dest);
When using these functions, there are several points to note.
1. the Dest image required by the cvsobel and cvlaplace functions is ipl_depth_16s;
2. How to convert ipl_depth_16s to ipl_depth_8u type? The required function is cvconvertscaleabs.
3. An error occurs when the size of the kernel core is greater than,. Currently, this is the case.
Second camp: no function school, such as: Robert \ prewit \ Krish. There is no function that can be called directly. It does not mean that it cannot be implemented in opencv. These algorithms can be implemented more flexibly than the preceding functions. The functions used here are:
Cvfilter2d function, which is a convolution function. It is precisely because this function can help us save the for loop like Visual C ++. Edge processing is a convolution process. How can this problem be achieved?
First, you must have your own kernel, which is also a popular template. The specific form of this function is as follows;
Cvfilter2d (
Const cvarr * SRC,
Cvarr * DST,
Const cvmat * kernel,
Cvpoint anchor = cvpoint (-1,-1 ));
It can be seen that this template must be of the cvmat * type. There are several methods to create a cvmat:
Pointer type:
CvMat* Tempt3;Tempt3=cvCreateMat(3,3,CV_32F);float a[9]={-3,5,5,-3,0,5,-3,-3,-3};cvInitMatHeader(Tempt3,3,3,CV_32F,a);
Variable type:
CvMat Tempt3;Tempt3=cvCreateMat(3,3,CV_32F);float a[9]={-3,5,5,-3,0,5,-3,-3,-3};Tempt3=cvMat(3,3,CV_32F,a);
Then you can call cvfilter2d to implement it. This template is mainly defined by arrays first.
Note the following:
1. The template cvmat must be of the floating point type; cv_f32 and other forms;
2. The definition of array a must also be floating point;
3. If you want to define the variable type, add & tempt3;