OpenCV Error: an Assertion failed (DataType <_Tp> : : channels==m.c hannels ()) in CV: :
Mat_
\ opencv2 \ core \ mat HPP, line 896
# include
# include
# include
# include
Using the namespace CV;
Int main ()
{
Mat srcImage=imread (" 005 JPG ");
if(! SrcImage. Data)
{
Printf (" Reading files failed! \n");
return false;
}
Imshow (" the Original image, "srcImage);
//ShowHelpText ();
Int m=getOptimalDFTSize (srcImage. Rows);
Int n=getOptimalDFTSize (srcImage cols);
Mat padded.
CopyMakeBorder (srcImage, padded, 0, m - srcImage rows, 0, n - srcImage. Cols, BORDER_CONSTANT, Scalar: : all (0));
Mat planes []={Mat_
Mat complexI.
Merge (planes, 2, complexI);
DFT (complexI, complexI);
The split (complexI, planes);
Magnitude (planes [0], planes [1], the planes [0]).
Mat magnitudeImage=planes [0];
MagnitudeImage +=Scalar: : all (1);
The log (magnitudeImage magnitudeImage);
MagnitudeImage=magnitudeImage (the Rect (0, 0, magnitudeImage cols & 2, magnitudeImage. Rows & - 2));
Cx=magnitudeImage int. Cols/2;
Int cy=magnitudeImage. Rows/2;
Mat q0 (magnitudeImage, the Rect (0, 0, cx, cy));
Cx, Mat q1 (magnitudeImage, the Rect (0, cx, cy));
Mat q2 (magnitudeImage, the Rect (0, cy, cx, cy));
Mat q3 (magnitudeImage, the Rect (cx, cy, cx, cy));
Mat TMP.
Q0. CopyTo (TMP);
Q3. CopyTo (q0);
TMP. CopyTo (q3);
Q1. CopyTo (TMP);
Q2. CopyTo (q1);
TMP. CopyTo (q2);
The normalize (magnitudeImage magnitudeImage, 0, 0, CV_MINMAX);
The normalize (magnitudeImage magnitudeImage, 0, 0, NORM_MINMAX);
Imshow (" Magnitude values ", magnitudeImage);
waitKey(0);
return 0;
}