Page 1 of 1
script to convert 360 degree image
Posted: 2013-09-11T17:04:55-07:00
by yds
Hi. Could use some help with a script to convert an image that is taken with a 360 degree camera into a rectilinear panoramic image. From a command line, the following ImageMagick command works wonderfully
Code: Select all
convert source_picture.jpg +distort DePolar 0 output_picture.jpg
I'd like to be able to create a web page, which runs that command on-the-fly to my original image and displays to the user the converted panoramic image. I believe I can do this using a php script, but I'm a relative newbie to writing php. Wonder if someone might be able to provide a simple php example script that would do this, that I can learn from??
Re: script to convert 360 degree image
Posted: 2013-09-11T18:21:12-07:00
by fmw42
I am not the best at PHP, but you can run any IM command via PHP exec()
exec("path2/convert path2/source_picture.jpg +distort DePolar 0 path2/output_picture.jpg");
See
http://www.rubblewebs.co.uk/imagemagick/index.php
If on Unix/Mac (or Windows w/Cygwin), you might like to see my script, fisheye2pano at the link below. It has a few more features, but is slower, since it was built before distort depolar.
Note that both distort depolar and my script require either a nadir (downlooking) or zenith (uplooking) fisheye view.
Re: script to convert 360 degree image
Posted: 2013-09-12T06:28:00-07:00
by yds
fmw42 wrote:
If on Unix/Mac (or Windows w/Cygwin), you might like to see my script, fisheye2pano at the link below. It has a few more features, but is slower, since it was built before distort depolar.
Thanks for this. I had actually tried your script previously. It's a bit too slow however for the "real-time" conversion I was hoping for. I will try playing around with the PHP exec option. Though I've never done any PHP scripting either, so I was hoping someone might be able to provide me with a basic script which I could learn from and build on possibly.
Re: script to convert 360 degree image
Posted: 2013-09-12T07:44:58-07:00
by Bonzo
php is quite simple in your case:
Code: Select all
<?php
exec("convert source_picture.jpg +distort DePolar 0 output_picture.jpg");
?>
You can replace the input and output images with variables containing the image paths and lots of other things.
Check my website out below - I would use Imagemagick with the command line as the example above rather than Imagick which can be built into php. Imagick might be quicker but can be a pain to get working and is lacking in a lot of the options.
Re: script to convert 360 degree image
Posted: 2013-09-12T09:50:54-07:00
by fmw42
Just one further comment. Unless your PHP is set up to know where IM resides, you may have to put the path to IM convert in your command
<?php
exec("path2/convert source_picture.jpg +distort DePolar 0 output_picture.jpg");
?>
You can often find where it resides by
<?php
echo "<pre>";
system("type -a convert");
echo "</pre>";
?>
Most likely it will be at either /usr/bin/convert or /usr/local/bin/convert. Also you may find more than one version of PHP on shared servers. So you need to be sure you are using the correct one.
<?php
exec("/usr/bin/convert -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
<?php
exec("/usr/local/bin/convert -version",$out,$returnval);
foreach($out as $text)
{echo "$text<br>";}
?>
Re: script to convert 360 degree image
Posted: 2013-09-12T18:54:38-07:00
by yds
Thanks all. The simple exec() code worked like a charm! Takes about 1-2 seconds to convert the image and display it. Many thanks.