perspective distorsion problem

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

perspective distorsion problem

Post by javismiles »

dear friends, got an issue with perspective distorsion,maybe you can help me

1) ive been using imagemagick for a long time, all works great, now im trying for the first time to do a simple perspective distorsion, like any of these, in php :

$command= "convert ".$source." -matte -virtual-pixel transparent -distort Perspective '7,40 124,330 4,124 4,223 85,122 400,123 85,2 200,30' ".$target;
$command= "convert ".$source." -matte -virtual-pixel transparent -distort Perspective '0,0,0,0 0,90,0,90 90,0,90,25 90,90,90,65' ".$target;

but nothing happens, no change in the result, anything im doing wrong? my version of imagemagick is the latest

2) the other thing is, if i have a sequence like this

$command= 'convert -size 1000x631 xc:none ';
$command .='-draw "image over 0,0 0,0 \''.$source1.'\'" ';
$command .='-draw "image over 0,0 0,0 \''.$source2.'\'" ';
$command .='-draw "image over 0,0 0,0 \''.$source3.'\'" ';
$command.=' -quality 85 '.$target;

can i apply to one of those sources a perspective distorsion with resizing included and include it all in the same command? if so, how?

thanks so very much for your help as always :)

Jav :)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

regarding 2)
basically im uniting many images within a large virtual canvas
and i need to distort in perspective one of them, so how do i include it all within the same command?
thanks very much :)
Jav
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

mmm i dont get it, now i tried this example you have and still nothing no change, i tried both in windows and linux, mmm, what do u think?


$p1="0,0";
$p2="680,0";
$p3="680,952";
$p4="0,952";

$w1="298,488";
$w2="431,472";
$w3="497,590";
$w4="370,616";

$points="$p1 $w1 $p2 $w2 $p3 $w3 $p4 $w4";

echo "***";
echo $points;
echo "***";

# process picture in perspective and overlay on wizard
$command= " convert ".$source1." ( ".$pic." -channel rgba -alpha set -virtual-pixel transparent +distort perspective '".$points."' ) -compose over -layers merge ".$target2;


passthru($command);
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: perspective distorsion problem

Post by Bonzo »

What version of IM are you using as the distort options changed at some point and why not get distort working on its own and then build it into the long convert comand?
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

i have tried with these 2 versions

6.7.0-6
and also
6.6.8-5 2011-03-18 Q16

i would prefer it all in one command for not generating temporary files, this is very important for my application :)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

i may have found a solution, not sure yet, im testing it

in the meantime, which of the perspective distorts produces the sharpest results yet being fast enough?

thanks so much
jav
:)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

ok progress

this works: $command ='convert '.$source.' -matte -virtual-pixel transparent -distort Perspective "'.$points.'" '.$target;

but this doesnt work
$command= "convert ".$canvas." ( ".$source." -matte -virtual-pixel transparent -distort Perspective '".$points."' ) -compose over -layers merge ".$target;

so how can i apply the distortion and at the same time compose it over a larger canvas?
thanks so much, and is that the technique that produce sharp yet fast results?


$p1="0,0";
$p2="680,0";
$p3="680,952";
$p4="0,952";
$w1="298,488";
$w2="431,472";
$w3="497,590";
$w4="370,616";
$points="$p1 $w1 $p2 $w2 $p3 $w3 $p4 $w4";
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

mamma mia, it was a matter of changing quotes to the reversed ones, insane...

$command= 'convert '.$canvas.' ( '.$source.' -matte -virtual-pixel transparent -distort Perspective "'.$points.'" ) -compose over -layers merge '.$target;

uffff

thank u :)

so final question, is this a fast method with quite sharp results? or is there any other method that is as fast but sharper? or is this the generally used one?

thank u my friends
jav
:)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

one more question, can i mix that command with a -draw command to compose yet another image with them?

$command= 'convert '.$source1.' ( '.$pic.' -matte -virtual-pixel transparent -distort Perspective "'.$points.'" ) ( -draw "image over 0,0 0,0 \''.$source2.'\'" ) -compose over -layers merge '.$target2;

it doesnt seem to work, thanks for any help :)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

so the question really is if i can mix both -draw and -distort in same command to compose multiple images one of which can be put in perspective, all in one command,

i already manage to make 2, the canvas + the perspective one, now how can i add more in the same command? didnt manage yet, tried with -draw but didnt work

thank u :)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

ah, magic of imagemagick :)
it works now, its just all matter of formatting, quotes etc
ay ay ay
thank u my friends :)

so this is the best command for perspective isnt it? seems quite fast, any other recommendation?

smiles
jav :)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

question

it works in windows with 6.7.0-6
but it doesnt work in linux with 6.6.8-5

is this a problem of the version? or of the syntax?

thank u :)
javismiles
Posts: 180
Joined: 2010-11-27T01:42:06-07:00
Authentication code: 8675308

Re: perspective distorsion problem

Post by javismiles »

uff it works now
in linux i needed to add the \ special character before the ( and ) :)

so final question
i see it takes a while, is there any other faster command? or this is the fastest?
i mean, its fast :) but just wondering if this one is the fastest?
$command =$magic.' '.$source.' -matte -virtual-pixel transparent -distort Perspective "'.$points.'" '.$target;

thank u so much
jav :)
Post Reply