Home > Software engineering >  The open CV Marr - Hildreth method of assertion errors
The open CV Marr - Hildreth method of assertion errors

Time:09-18

When I was writing marrEdge testing always prompt assertion error


#include
#include
#include
#include
#include
#include
#include

using namespace std;
Using the namespace CV;

Void marrEdge (const Mat SRC, Mat result, int kerValue, double delta)
{
//calculate the LOG operator
Mat kernel;
 

//radius
Int kerLen=kerValue/2;
The kernel=Mat_ & lt; Double> (kerValue kerValue);
//sliding window
For (int I=- kerLen; I & lt;=kerLen; I++)
{
For (int j=- kerLen; J & lt;=kerLen; J++)
{
//generated nuclear factor
The kernel. At (I + kerLen, j + kerLen)=
Exp (- ((j, 2) + (pow pow (I, 2))/(delta, 2) * 2) (pow) * (((j, 2) + (pow pow (I, 2) - 2 * pow (delta, 2))/(2 * pow (delta, 4)))));
}
}
//set the output parameters
Int kerOffset=kerValue/2;
Mat Laplacian=(Mat_ & lt; Double> (SRC. Rows - kerOffset * 2, SRC, cols - kerOffset * 2));
Result=Mat: : zeros (SRC. Rows - kerOffset * 2, SRC cols - kerOffset * 2, SRC. The type ());
Double sumLaplacian;
//traversal calculation of Laplacian convolution image
For (int I=kerOffset; I & lt; The SRC. Rows - kerOffset; + + I)
{
For (int j=kerOffset; J{
SumLaplacian=0;
For (int k=- kerOffset; k <=kerOffset; + + k)
{
For (int m=- kerOffset; M & lt;=kerOffset; + + m)
{
//based on convolution image
SumLaplacian +=SRC. At (I + k, j + m) * kernel at (kerOffset + k, kerOffset + m);
}
}
Laplacian. Ats & lt; Double & gt; (I - kerOffset, j - kerOffset)=sumLaplacian;
}
}

//zero cross should be in accordance with the edge pixels
For (int y=1; Y & lt; Result. The rows 1; + + y)
{
For (int x=1; X & lt; Result. The cols; + + x)
{
Result. At (y, x)=0;
//neighborhood judging
If (Laplacian. At (y, x) * Laplacian at (y + 1, x) & lt; 0)
Result. At (y, x)=255;
If (Laplacian. At (y, x - 1) * Laplacian at (y, x + 1) & lt; 0)
Result. At (y, x)=255;
If (Laplacian. At (x + y - 1, 1) * Laplacian at (y + 1, x - 1) & lt; 0)
Result. At (y, x)=255;
If (Laplacian. At (x - y - 1, 1) * Laplacian at (y + 1, x + 1) & lt; 0)
Result. At (y, x)=255;
}
}
}

Int main ()
{
Mat srcImage=imread (" 1. JPG ");
if (! SrcImage. Data)
return -1;
Mat srcGray (srcImage. The size (), srcImage. The type ());
CvtColor (srcImage srcGray, CV_BGR2GRAY);
Mat edge;
MarrEdge (srcGray, edge, 9, 1.6);
Imshow (" SRC ", srcImage);
Imshow (" edge ", edge);
WaitKey (0);
return 0;
}
  • Related