이미지에 Shepards distortion을 사용하려면 PythonMagickWand을 사용하려고합니다. ImageMagick에서 사용하는 the source of distort.c을 볼 수도 있습니다.PythonMagickWand 셰퍼드 왜곡 (ctypes LP_c_double 문제)
PythonMagickWand는 기본적으로 셰퍼드 왜곡을 지원하지 않습니다. 이 문제를 해결하려면, 나는에 추가 :
ShepardsDistortion = DistortImageMethod(15)
이 PythonMagickWand의 544 (See here for my modified PythonMagicWand)을 줄 수 있습니다. 15 포인터는 ShepardsDistortion이 목록의 15 번째 항목 인 MagickWand 소스의 distort.h (51 행)을 참조합니다. 이것은 지원되는 다른 모든 왜곡 방법과도 맞습니다.
내가 잘못했을 수도있는 부분은 PythonMagickWand에서 지원하는 기존의 왜곡 방법이 셰퍼드와 동일한 유형의 인수를 사용한다고 가정합니다. 그들은 모르지만 나는 내가 어떻게 말할 수 있는지 모른다. 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
기본적으로 터미널 명령을 다시 작성해야합니다. 파이썬에서 명령을 실행하기 위해 subprocess를 사용하여 작동시키고 있지만 어떻게하고 싶지는 않습니다.
죄송합니다. 방금 단순화 된 스 니펫을 작성하고 그 가져 오기를 추가하는 것을 잊어 버렸습니다. 지금 내 소식을 편집했습니다. – betamax
감사합니다. 정말로 도와 주셔서 감사합니다. 함수 *는 이것을 입력으로 받아들입니다. * 그러나 *, 아무 것도하지 않습니다. 필자는 왜 PythonMagickWand를 수정했는지에 대해서는 언급하지 않았지만 의심의 여지없이 이것이 왜 작동하지 않는가에 대한 중요한 힌트입니다. 나는 내가 뭘하려고하는지 더 자세하게 반영하기 위해 내 글을 수정했다. – betamax