Ask Your Question
1

How to access ThinPlateSpline ShapeTransformer functions in python

asked 2017-01-07 19:03:53 -0500

MrGiskard gravatar image

I'd like to use the TPS shape transformer in a python project but the bindings appear to be incomplete - I can see the constructor but the other functions (applyTransformatio,warpImage) don't seem to exist. Do Python bindings exist for these?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-01-08 02:16:49 -0500

berak gravatar image

thing is, to call help() properly here, you have to create an instance of it

>>> help(cv2.createThinPlateSplineShapeTransformer()) ## () braces matter !!
Help on ThinPlateSplineShapeTransformer object:

class ThinPlateSplineShapeTransformer(ShapeTransformer)
 |  Method resolution order:
 |      ThinPlateSplineShapeTransformer
 |      ShapeTransformer
 |      Algorithm
 |      builtins.object
 |
 |  Methods defined here:
 |
 |  __new__(*args, **kwargs) from builtins.type
 |      Create and return a new object.  See help(type) for accurate signature.
 |
 |  __repr__(self, /)
 |      Return repr(self).
 |
 |  getRegularizationParameter(...)
 |      getRegularizationParameter() -> retval
 |
 |  setRegularizationParameter(...)
 |      setRegularizationParameter(beta) -> None
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from ShapeTransformer:
 |
 |  applyTransformation(...)
 |      applyTransformation(input[, output]) -> retval, output
 |
 |  estimateTransformation(...)
 |      estimateTransformation(transformingShape, targetShape, matches) -> None
 |
 |  warpImage(...)
 |      warpImage(transformingImage[, output[, flags[, borderMode[, borderValue]]]]) -> output
 |
 |  ----------------------------------------------------------------------
 |  Methods inherited from Algorithm:
 |
 |  clear(...)
 |      clear() -> None
 |
 |  getDefaultName(...)
 |      getDefaultName() -> retval
 |
 |  save(...)
 |      save(filename) -> None
edit flag offensive delete link more

Comments

Thank you - I was expecting my IDE to display the options since it should automatically read all members of the classes in cv2 but this did not happen - I don't know why.

I am trying to execute a Thin Plate Spline transformation on a single image using two pre-calculated source and target points. I have seen that the estimateTransformation method requires a set of matches as its third argument but as I am not in fact using a second image it is not relevant. In similar C++ implementations I have seen that they explicitly create a set of "dummy" DMatch objects with identical index values which they then pass to the parameter but in Python i cannot see how I can create a DMatch object - the definition does not appear to exist. How can I call the function?

MrGiskard gravatar imageMrGiskard ( 2017-01-08 08:25:03 -0500 )edit

i can only guess here: you probably have to do some keypoint detection/matching on both original shapes/images, and then feed that back into the estimation.

if you can find a link to an c++ example, i'll look into it !

berak gravatar imageberak ( 2017-01-08 08:32:49 -0500 )edit

Hi Berak,

I have this link which is in fact an older question posted in the forum. As you can see a number of DMatch objects were created and then passed on to the estimateTransformation method but they are "dummy" ones in the sense that they do not refer to any real matches between two images - the objective is to warp a single image by moving a set of control points on that same image

MrGiskard gravatar imageMrGiskard ( 2017-01-08 08:41:15 -0500 )edit

sorry, but idk.

if it helps, it looks fairly easy, to create a DMatch object:

>>> help(cv2.DMatch)
Help on built-in function DMatch:

DMatch(...)
    DMatch() -> <DMatch object>  or  DMatch(_queryIdx, _trainIdx, _distance) -> <DMatch object>  or  DMatch(_queryIdx, _trainIdx, _imgIdx, _distance) -> <DMatch object>
berak gravatar imageberak ( 2017-01-08 08:53:24 -0500 )edit
1

Thanks for your help Berak, I have managed to create the DMatch object. I'm having other difficulties with implementing the TPS class but since this post had a very specific subject I've decided to close it and post a new question specific to the problems I'm having. Thanks for your assistance

Regards, Savvas

MrGiskard gravatar imageMrGiskard ( 2017-01-08 10:10:24 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-01-07 19:03:53 -0500

Seen: 976 times

Last updated: Jan 08 '17