PythonMagickWand Shepards Distortion (ctypes LP_c_double problem)
Posted
by betamax
on Stack Overflow
See other posts from Stack Overflow
or by betamax
Published on 2010-06-07T12:43:46Z
Indexed on
2010/06/08
11:02 UTC
Read the original article
Hit count: 436
I am trying to use PythonMagickWand to use a Shepards distortion on an image. You can also see the source of distort.c that is used by ImageMagick.
I have the following code (snippet):
from PythonMagickWand import *
arrayType = c_double * 8
pointsNew = arrayType()
pointsNew[0] = c_double(eyeLeft[0])
pointsNew[1] = c_double(eyeLeft[1])
pointsNew[2] = c_double(eyeLeftDest[0])
pointsNew[3] = c_double(eyeLeftDest[1])
pointsNew[4] = c_double(eyeRight[0])
pointsNew[5] = c_double(eyeRight[1])
pointsNew[6] = c_double(eyeRightDest[0])
pointsNew[7] = c_double(eyeRightDest[1])
MagickWandGenesis()
wand = NewMagickWand()
MagickReadImage(wand,path_to_image+'image_mod.jpg')
MagickDistortImage(wand,ShepardsDistortion, 8, pointsNew, False)
MagickWriteImage(wand,path_to_image+'image_mod22.jpg')
I get the following error:
MagickDistortImage(wand,ShepardsDistortion, 8, pointsNew, False)
ctypes.ArgumentError: argument 4: <type 'exceptions.TypeError'>: expected LP_c_double instance instead of list
I am aware that pointsNew is the wrong way of providing the arguments.. But I just don't know what is the right format. This is an example distort command that works when run in Terminal:
convert image.jpg -virtual-pixel Black -distort Shepards 121.523809524,317.79638009 141,275 346.158730159,312.628959276 319,275 239.365079365,421.14479638 232,376 158.349206349,483.153846154 165,455 313.015873016,483.153846154 300,455 0,0 0,0 0,571.0 0,571.0 464.0,571.0 464.0,571.0 0,571.0 0,571.0 image_out.jpg
So I guess the question is: How do I create a list of c_doubles that will be accepted by PythonMagickWand? I basically need to re-create the terminal command. I have got it working by using subprocess to run the command from Python but that is not how I want to do it.
© Stack Overflow or respective owner