回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我试图使用<a href="http://public.procoders.net/PythonMagickWand/docs/html/index.html" rel="nofollow noreferrer">PythonMagickWand</a>在图像上使用<a href="http://www.imagemagick.org/Usage/distorts/#shepards" rel="nofollow noreferrer">Shepards distortion</a>。您还可以看到ImageMagick使用的<a href="http://trac.imagemagick.org/browser/ImageMagick/trunk/magick/distort.c" rel="nofollow noreferrer">the source of distort.c</a>。在</p>
<p>PythonMagickWand默认情况下不支持Shepards失真。为了解决这个问题,我添加了:</p>
<p><code>ShepardsDistortion = DistortImageMethod(15)</code></p>
<p>到PythonMagickWand(<a href="http://pastebin.com/bVjCL1w4" rel="nofollow noreferrer">See here for my modified PythonMagicWand</a>)的544行。15指针引用MagickWand源的<a href="http://trac.imagemagick.org/browser/ImageMagick/trunk/magick/distort.h" rel="nofollow noreferrer">distort.h</a>(第51行),其中shepardstoration是列表中的第15项。这适用于所有其他支持的失真方法。在</p>
<p>现在,我可能做错了一件事,就是假设PythonMagickWand支持的现有失真方法使用与Shepards相同类型的参数。他们可能不会,但我不知道我怎么知道。我知道<a href="http://trac.imagemagick.org/browser/ImageMagick/trunk/magick/distort.c" rel="nofollow noreferrer">distort.c</a>正在做这项工作,但我无法计算出它接受的参数是相同还是不同。在</p>
<p>我有以下代码(片段):</p>
<pre><code>from PythonMagickWand import *
from ctypes 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')
</code></pre>
<p>我得到以下错误:</p>
<p><code>MagickDistortImage(wand,ShepardsDistortion, 8, pointsNew, False)
ctypes.ArgumentError: argument 4: <type 'exceptions.TypeError'>: expected LP_c_double instance instead of list</code></p>
<p>我知道pointsNew提供论点的方式是错误的。。但我不知道什么是正确的格式。以下是在终端中运行时有效的“扭曲”命令示例:</p>
<p><code>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</code></p>
<p>所以我想问题是:如何创建一个PythonMagickWand可以接受的c_double列表?<strong>或者</strong>我在PythonMagickWand中添加Shepards失真的方法是完全错误的吗?在</p>
<p>我基本上需要重新创建终端命令。我已经通过使用subprocess从Python运行命令使其正常工作,但我不想这样做。在</p>