我试图使用PythonMagickWand在图像上使用Shepards distortion。您还可以看到ImageMagick使用的the source of distort.c。在
PythonMagickWand默认情况下不支持Shepards失真。为了解决这个问题,我添加了:
ShepardsDistortion = DistortImageMethod(15)
到PythonMagickWand(See here for my modified PythonMagicWand)的544行。15指针引用MagickWand源的distort.h(第51行),其中shepardstoration是列表中的第15项。这适用于所有其他支持的失真方法。在
现在,我可能做错了一件事,就是假设PythonMagickWand支持的现有失真方法使用与Shepards相同类型的参数。他们可能不会,但我不知道我怎么知道。我知道distort.c正在做这项工作,但我无法计算出它接受的参数是相同还是不同。在
我有以下代码(片段):
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')
我得到以下错误:
MagickDistortImage(wand,ShepardsDistortion, 8, pointsNew, False)
ctypes.ArgumentError: argument 4: <type 'exceptions.TypeError'>: expected LP_c_double instance instead of list
我知道pointsNew提供论点的方式是错误的。。但我不知道什么是正确的格式。以下是在终端中运行时有效的“扭曲”命令示例:
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
所以我想问题是:如何创建一个PythonMagickWand可以接受的c_double列表?或者我在PythonMagickWand中添加Shepards失真的方法是完全错误的吗?在
我基本上需要重新创建终端命令。我已经通过使用subprocess从Python运行命令使其正常工作,但我不想这样做。在
从NeedMoreBeer到Reddit.com:
更具体地说,是下面这句话:
^{pr2}$帮我修好了!再次感谢来自Reddit的NeedMoreBeer。在
这是OT,但是:
我真的很喜欢python magick wand,但是当我在600多个图像上使用它时,在某个地方出现了内存泄漏,耗尽了(32位)机器中的所有内存。我倾向于用ImageMagick本身来思考,但我可能错了。在
最后我发现:
GraphicsMagick是早期版本ImageMagick的一个端口;但是由于ImageMagick对API进行了很多更改,pythonmagickwent不能与GraphicsMagick一起工作。在
GraphicsMagick似乎也比ImageMagick(使用更好的多任务处理)更快。在
为了让我的脚本快速工作,几天后我对它进行了更改,这样脚本就不用ImageMagick,而是加载了gimp,然后gimp使用pythonscriptfu运行我的脚本。 一切似乎都很好。在
如果它对你有用,那就用它吧;而且Python人真的很有帮助,绑定也很不错。在
如错误消息所示,该函数需要一个指针(
LP_c_double
),但您只有一个数组。在为了将数组作为指向外部函数的指针传递,需要将数组显式转换为指针:
相关问题 更多 >
编程相关推荐