5

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?

2 Answers 2

7

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.

Sign up to request clarification or add additional context in comments.

2 Comments

I almost forgot to mention that I love your blog, extremely helpful.
Can I calculate the angle of difference of the two pictures using the phasecorrelate() results?
1

Accordingly to the docs you can convert a numpy array into a CvMat as follows:

>>> import cv, numpy
>>> a = numpy.ones((480, 640))
>>> mat = cv.fromarray(a)
>>> print mat.rows
480
>>> print mat.cols
640

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.