Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ImageMagick-在不知道图像尺寸的情况下计算透视图_Imagemagick_Imagemagick Convert - Fatal编程技术网

ImageMagick-在不知道图像尺寸的情况下计算透视图

ImageMagick-在不知道图像尺寸的情况下计算透视图,imagemagick,imagemagick-convert,Imagemagick,Imagemagick Convert,如何获得图像的最大宽度和高度,对其执行一些数学运算,然后将其用于透视失真 我有一堆图像,我想对它们应用透视失真 唯一的问题是,每个图像的大小不同 此代码适用于我知道大小(1440*900)的图像 我知道我可以通过使用%h和%w获得最大值,但我找不到将这些数字相乘的方法 基本上,我想做的是定义如下所示的点: -distort Perspective '0,0 75,0 \ 0,%h 0,(%h/2) \

如何获得图像的最大宽度和高度,对其执行一些数学运算,然后将其用于透视失真

我有一堆图像,我想对它们应用透视失真

唯一的问题是,每个图像的大小不同

此代码适用于我知道大小(1440*900)的图像

我知道我可以通过使用
%h
%w
获得最大值,但我找不到将这些数字相乘的方法

基本上,我想做的是定义如下所示的点:

    -distort Perspective '0,0        75,0 \ 
                          0,%h       0,(%h/2) \ 
                          %w,0       %w,200 \ 
                          %w,%h      (%w*0.75),%h'

为了获得额外积分,我希望能够使用
-cortext perspective'@points.txt'
调用透视图。您可以使用ImageMagick内置的
fx
操作符为您计算数学,而不涉及
bash
数学、
bc
eval

像这样:

persp=$(convert image.jpg -format "0,0 75,0 0,%h 0,%[fx:int(h/2)] %w,0,%w,200 %w,%h %[fx:int(w*0.75)],%h" info:)

echo $persp
0,0 75,0 0,900 0,450 1440,0,1440,200 1440,900 1080,900
然后做:

convert image.jpg ... -distort Perspective "$persp" ... distorted.jpg
哦,为了那些额外的积分…;-)


哇!没想到会得到回答。太好了,谢谢:-)
convert image.jpg ... -distort Perspective "$persp" ... distorted.jpg
convert image.jpg -format "0,0 75,0 0,%h 0,%[fx:int(h/2)] %w,0,%w,200 %w,%h %[fx:int(w*0.75)],%h" info: > points.txt
convert image.jpg ... -distort Perspective @points.txt distorted.jpg