phaseCorrelate function in OpenCV Python

computer-vision, opencv, python

Solution

You don't need to convert it into cvMat.

The error says your input should be of `float32` or `float64` with single channel.

So convert the images accordingly.

And both the images should be of same size. Then apply phaseCorrelate function, as follows:

>>> src1 = cv2.imread('sudoku.jpg',0)   # load first image in grayscale
>>> src2 = cv2.imread('su1.png',0)      # load second image in grayscale
>>> src1 = np.float32(src1)             # convert first into float32
>>> src2 = np.float32(src2)             # convert second into float32  
>>> ret = cv2.phaseCorrelate(src1,src2) # now calculate the phase correlation
>>> ret
(-0.024777238426224812, 0.0011736626157130559)

(Both my images are same, except change in brightness.)

Regarding documentation, you can post a bug report at `code.opencv.org`.

Problem

The phaseCorrelate seems to be an undocumented function of the OpenCV Python wrapper. The doc of the C++ function is here. When I call the function from Python I get the following error: ``` cv2.error: ..\..\..\src\opencv\modules\imgproc\src\phasecorr.cpp:495: error: (-215) src1.type() == CV_32FC1 || src1.type() == CV_64FC1 ``` Every OpenCV 2 function uses numpy arrays, I suspect that this function has been left from the older wrapper. Maybe I need to convert the numpy arrays to CvMats before calling the function? How do I do that?

Original source