Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Error when calling estimateTransformation of ThinPlateSplineShapeTransformer

I am trying to implement an image warp using the ThinPlateSplineShapeTransformer in OpenCV using Python. I am using a C++ example posted earlier in the forum (link) but I am encountering various problems due to the differences in the OpenCV Python API.

As in the linked example, I am working with a single image onto which I will define a small number of source points and the corresponding target points. The end result should be a warped copy of the image.

tps=cv2.createThinPlateSplineShapeTransformer()

sourceshape= np.array([[200,10],[400,10]],np.int32)
targetshape= np.array([[250,10],[450,30]],np.int32)

matches=list()
matches.append(cv2.DMatch(1,1,0))
matches.append(cv2.DMatch(2,2,0))

tps.estimateTransformation(sourceshape,targetshape,matches)

But I am getting an error in the estimateTransformation method as follows:

cv2.error: D:\Build\OpenCV\opencv-3.1.0\modules\shape\src\tps_trans.cpp:193: error: (-215) (pts1.channels()==2) && (pts1.cols>0) && (pts2.channels()==2) && (pts2.cols>0) in function cv::ThinPlateSplineShapeTransformerImpl::estimateTransformation

I can understand that something is incorrect in the data structures that I have passed onto estimateTransformation and I'm guessing it has to do with the channels since the rows and columns seem to be correct but I do not know how I can satisfy the assertion (pts1.channels()==2) since the parameter is an array of points which I am creating and not an array generated from an image load

I'd be grateful for any pointers to a TPS implementation with Python or indeed any help on how to resolve this particular issue. I've tried to find the Python documentation for the ThinPlateShapeTransformer class but it has proved impossible - all I've found is the C++ docs and the only thing i have to go on are the results of the help() function - apologies if I am missing something obvious