Ask Your Question

Revision history [back]

phaseCorrelate fails with Rectangle ROI type of arguments due to their incorrect .type()

Hi, I'm trying to compute phase correlation between two square 256x256 pixel blocks using the code below. Unfortunately, the following ASSERT fails in the phaseCorrelate(): CV_Assert( src1.type() == CV_32FC1 || src1.type() == CV_64FC1 );

Surprisingly, grayRefRoi64f.type() = 22, so that's a reason but I don't understand why and how to fix this problem. Thanks in advance,

AndrewK

interestingly, very similar routine operating on the full size video frame i.e. using fReference and fUnderTest as arguments to phaseCorrelate() works without any problem

Point2d two_ROIblocks_phcorrelation(double* response, Mat& fReference, Mat& fUnderTest) { // fReference.type(); fReference.depth(); fReference.size(); int block_width = 256; int block_height = 256; // Mat grayReference, grayUnderTest, hann; Mat grayRefRoi, grayUTestRoi; Mat grayRefRoi64f, grayUTestRoi64f; //
cvtColor(fReference, grayReference, COLOR_RGB2GRAY); cvtColor(fUnderTest, grayUnderTest, COLOR_RGB2GRAY); Rect refRectangle = Rect((grayReference.size().width - block_width) >> 1, (grayReference.size().height - block_height) >> 1, block_width, block_height); //draw rectangle on video frame // rectangle(fReference, refRectangle, Scalar(255), 1, 8, 0); rectangle(fUnderTest, refRectangle, Scalar(255), 1, 8, 0); // grayRefRoi = fReference(refRectangle); grayUTestRoi = fUnderTest(refRectangle); createHanningWindow(hann, grayRefRoi.size(), CV_64F); // grayRefRoi.convertTo(grayRefRoi64f, CV_64F); grayUTestRoi.convertTo(grayUTestRoi64f, CV_64F);

//M, N numbers below imply numbers to be used for DFT which are lower than image size and any multiple of 2, 3 and 5 numbers incl. 540x960!
int M = getOptimalDFTSize(grayUTestRoi.rows);       
int N = getOptimalDFTSize(grayUTestRoi.cols);
cout << "PhC ROISize = " << M << "x" << N << endl;

Point2d shift = { 1, 1 };
if (grayRefRoi64f.type()    != grayUTestRoi64f.type())                              return shift;
if (grayRefRoi64f.type()    != CV_64F)                                              return shift;
cout << "type = " << grayRefRoi64f.type() << endl;
if (grayRefRoi64f.size      != grayUTestRoi64f.size)                                return shift;

shift = phaseCorrelate(grayRefRoi64f, grayUTestRoi64f, hann, response);

return shift;

}

click to hide/show revision 2
None

updated 2018-04-17 21:04:10 -0500

berak gravatar image

phaseCorrelate fails with Rectangle ROI type of arguments due to their incorrect .type()

Hi, I'm trying to compute phase correlation between two square 256x256 pixel blocks using the code below. Unfortunately, the following ASSERT fails in the phaseCorrelate(): CV_Assert( src1.type() == CV_32FC1 || src1.type() == CV_64FC1 );

Surprisingly, grayRefRoi64f.type() = 22, so that's a reason but I don't understand why and how to fix this problem. Thanks in advance,

AndrewK

interestingly, very similar routine operating on the full size video frame i.e. using fReference and fUnderTest as arguments to phaseCorrelate() works without any problem

Point2d two_ROIblocks_phcorrelation(double* response, Mat& fReference, Mat& fUnderTest)
{
//  fReference.type(); fReference.depth(); fReference.size();
    int block_width = 256;
    int block_height = 256;
//
    Mat grayReference, grayUnderTest, hann;
    Mat grayRefRoi,    grayUTestRoi;
    Mat grayRefRoi64f, grayUTestRoi64f;
// 
cvtColor(fReference, grayReference, COLOR_RGB2GRAY); cvtColor(fUnderTest, grayUnderTest, COLOR_RGB2GRAY); Rect refRectangle = Rect((grayReference.size().width - block_width) >> 1, (grayReference.size().height - block_height) >> 1, block_width, block_height); //draw rectangle on video frame // rectangle(fReference, refRectangle, Scalar(255), 1, 8, 0); rectangle(fUnderTest, refRectangle, Scalar(255), 1, 8, 0); // grayRefRoi = fReference(refRectangle); grayUTestRoi = fUnderTest(refRectangle); createHanningWindow(hann, grayRefRoi.size(), CV_64F); // grayRefRoi.convertTo(grayRefRoi64f, CV_64F); grayUTestRoi.convertTo(grayUTestRoi64f, CV_64F);

CV_64F);

    //M, N numbers below imply numbers to be used for DFT which are lower than image size and any multiple of 2, 3 and 5 numbers incl. 540x960!
 int M = getOptimalDFTSize(grayUTestRoi.rows);       
 int N = getOptimalDFTSize(grayUTestRoi.cols);
 cout << "PhC ROISize = " << M << "x" << N << endl;

 Point2d shift = { 1, 1 };
 if (grayRefRoi64f.type()    != grayUTestRoi64f.type())                              return shift;
 if (grayRefRoi64f.type()    != CV_64F)                                              return shift;
 cout << "type = " << grayRefRoi64f.type() << endl;
 if (grayRefRoi64f.size      != grayUTestRoi64f.size)                                return shift;

 shift = phaseCorrelate(grayRefRoi64f, grayUTestRoi64f, hann, response);

 return shift;
}

}