A little python helper script

19 views
Skip to first unread message

Yuval Levy

unread,
Dec 24, 2010, 9:15:35 PM12/24/10
to hugi...@googlegroups.com
Hello all,

first, many thanks to Kay for his Python pto parser that served as basis for
what follows.

second, a big disclaimer: my Python experience is very limited.

Nevertheless, in about half hour of googling and fiddling, I achieved what I
needed now.

We ask users to provide the pto file associated with bugs reports. Usually
just the pto is enough, so to save time, bandwidth, disk space we do not ask
for the actual images.

As a consequence the first thing that we need to do if we want to visualize a
project in the GUI is to create placeholder images.

This is what the attached script does. Tested in Ubuntu. Requires
ImageMagick, Python, Kay's pto parser and python-argparse

sudo apt-get install imagemagick python python-argparse
bzr branch lp:~kfj/+junk/script

save the script inside script/main (unless Kay adds it to the repo, then it
will come automatically)

call with ptoimggen.py -p <PTO-FILE>

Probably Kay will find plenty of ways to improve on this. More power to him.
I had enough difficulties finding my way around his code - about the same as I
have finding my way around the Hugin source code (hint hint comments hint).

Thank you, Kay!
Yuv

ptoimggen.py
signature.asc

kfj

unread,
Dec 25, 2010, 4:58:26 AM12/25/10
to hugin and other free panoramic software

On 25 Dez., 03:15, Yuval Levy <goo...@levy.ch> wrote:
> Hello all,
>
> first, many thanks to Kay for his Python pto parser that served as basis for
> what follows.

You're welcome. Glad someone found it useful!

> save the script inside script/main (unless Kay adds it to the repo, then it
> will come automatically)

Which repo do you mean, the one at sourceforge? I didn't put it there
because I found their terms of use too scary and preferred launchpad.
But since it's FOSS, I think you are free to put it there, if you feel
that's a good place for it to reside, if I understand the GPL right -
and you have agreed to their terms.

> Probably Kay will find plenty of ways to improve on this.  More power to him.  
> I had enough difficulties finding my way around his code - about the same as I
> have finding my way around the Hugin source code (hint hint comments hint).

I'll have a look promptly. Sorry you found my code hard to penetrate,
I really made an effort commenting everything liberally. So it seems I
have to do even better...

Kay

Lukáš Jirkovský

unread,
Dec 25, 2010, 5:02:14 AM12/25/10
to hugi...@googlegroups.com

Bruno has similar script in his Panotools-Script. It's called ptodummy [1].

http://search.cpan.org/dist/Panotools-Script/bin/ptodummy

kfj

unread,
Dec 25, 2010, 5:30:01 AM12/25/10
to hugin and other free panoramic software


On 25 Dez., 03:15, Yuval Levy <goo...@levy.ch> wrote:

> Probably Kay will find plenty of ways to improve on this.

Okay, first improvement. Your script assumes that all pto line members
are in static positions, like the filename being in the 34th field.
This may be the case, but it's much safer to use named member access
(and it's shorter as well ;-) - try:

def imgfile_to_i_lines ( scan ) :

scan.make_member_access() # makes accessing the data more
comfortable ;-)

for line in scan.i : # look at all i-lines
width = line.w.value # extract the desired values
height = line.h.value
name = line.n.value

# generate random RGB values for the placeholder image
# ..... continue here as you did

I also find it questionable that the dummy images are created with the
same path and name as they were stored in the original pto. What do
you do if the pto contains full path names (like /home/theUser/images/
xyz.tif) - the system won't be able to create the file, or, what would
be worse, it might overwrite something which is there already (your
imagemagick system command just overwrites any innocent victim living
there). I'll propose an alternative and post when it's done.

Kay

kfj

unread,
Dec 25, 2010, 6:17:01 AM12/25/10
to hugin and other free panoramic software
On 25 Dez., 03:15, Yuval Levy <goo...@levy.ch> wrote:

> Probably Kay will find plenty of ways to improve on this.

I adressed the second issue as well. I made the script to produce
dummy images in the current working directory, prefixing the original
image names with 'dummy_', and I also made it output a modified pto
file using these names. Here's the modified routine:

def imgfile_to_i_lines ( scan ) :

scan.make_member_access() # makes accessing the data more
comfortable ;-)

for line in scan.i : # look at all i-lines
width = line.w.value # extract the desired values
height = line.h.value

# take the path away from the filename
# and prefix the name with 'dummy_'
name = 'dummy_' + os.path.basename ( line.n.value )
line.n.value = name # we modify the data in the scan

# generate random RGB values for the placeholder image
r = random.randint(0, 255)
g = random.randint(0, 255)
b = random.randint(0, 255)
# comopose the ImageMagick convert command
cmd = 'convert -size %dx%d xc:"rgb(%d,%d,%d)" %s' % (width,
height, r, g , b, name)
# tell me you're doing something
print cmd
# execute it
os.system(cmd)

# now we output a modified pto using filenames without a path
dummified_pto = "dummified_" + scan.filename # that's what we call
it
outfile = open ( dummified_pto , 'w' ) # open the file for
writing
scan.pto ( outfile ) # and write the
modified pto

Kay

kfj

unread,
Dec 25, 2010, 6:26:37 AM12/25/10
to hugin and other free panoramic software


On 25 Dez., 11:02, Lukáš Jirkovský <l.jirkov...@gmail.com> wrote:

> Bruno has similar script in his Panotools-Script. It's called ptodummy [1].
>
> http://search.cpan.org/dist/Panotools-Script/bin/ptodummy

This probably went unnoticed when he announced it in September. Indeed
it does a very similar thing to Yuval's script, down to creating
randomly coloured images. If you have Panotools-Script installed
already, you might as well use it - but if you find the Python
approach tempting enough to bother yourselves with getting hold of the
code, please go ahead and try ;-)

Kay

Rogier Wolff

unread,
Dec 25, 2010, 9:07:50 AM12/25/10
to hugi...@googlegroups.com

I had the same idea....

https://answers.launchpad.net/hugin/+question/136883

Roger.


--
** R.E....@BitWizard.nl ** http://www.BitWizard.nl/ ** +31-15-2600998 **
** Delftechpark 26 2628 XH Delft, The Netherlands. KVK: 27239233 **
*-- BitWizard writes Linux device drivers for any device you may have! --*
Q: It doesn't work. A: Look buddy, doesn't work is an ambiguous statement.
Does it sit on the couch all day? Is it unemployed? Please be specific!
Define 'it' and what it isn't doing. --------- Adapted from lxrbot FAQ

kfj

unread,
Dec 25, 2010, 9:50:09 AM12/25/10
to hugin and other free panoramic software


On 25 Dez., 15:07, Rogier Wolff <rew-googlegro...@BitWizard.nl> wrote:
> I had the same idea....
>
> https://answers.launchpad.net/hugin/+question/136883
>
>         Roger.

so now you have two solutions ;-)

Kay

Yuval Levy

unread,
Dec 25, 2010, 11:00:14 AM12/25/10
to hugi...@googlegroups.com
On December 25, 2010 06:17:01 am kfj wrote:
> I made the script to produce
> dummy images in the current working directory, prefixing the original
> image names with 'dummy_', and I also made it output a modified pto
> file using these names. Here's the modified routine:


Danke Santa K. ;-)

Indeed I did not realize that I could use line.<param>.value also for reading;
and indeed what you did is what I would have done if I had more time to get
further into it.

I added your updates, and improved it to use JPG images even when the initial
project file was using another image format.

The repo I mentioned is your personal repo on Launchpad (it was in the
checkout instructions for Ubuntu, sorry for not being more verbose).

If Launchpad had a better SCM (bazaar has a very dangerous feature of
automatically adding any new file in the working directory to a commit,
polluting the repo over time) I'd be inclined to migrate also the SCM; but
this is unlikely to happen any time soon.

I was not aware of the Perl script. I did more Perl than Python in the past
and yet I love Python which I find much less cryptic to read and write. So I
am happy to use the Python scripts and contribute what I can to improve them.

Yuv

ptoimggen.py
signature.asc

kfj

unread,
Dec 25, 2010, 12:17:01 PM12/25/10
to hugin and other free panoramic software


On 25 Dez., 17:00, Yuval Levy <goo...@levy.ch> wrote:

> Danke Santa K. ;-)

War mir ein Vergnügen!

If anyone in the future should want to use the pto_parse python
module, to make your life easier, I have written a README file for it,
which is in my bazaar main branch:

http://bazaar.launchpad.net/%7Ekfj/%2Bjunk/script/annotate/head%3A/main/README.parse_pto

Yuval, you don't need the test

if line.header == 'i' : # look at all i-lines

since scan.i contains only the i-lines.

I should have written the docu earlier... well, I suppose it's better
late than never.

Kay

Yuval Levy

unread,
Dec 25, 2010, 12:23:56 PM12/25/10
to hugi...@googlegroups.com
On December 25, 2010 12:17:01 pm kfj wrote:
> Yuval, you don't need the test

fixed. do you want to add the script to your repo (I can't and I don't think
you can simply give write access to personal repos like that one)?


> I should have written the docu earlier... well, I suppose it's better
> late than never.

it's very helpful, thank you!
Yuv

ptoimggen.py
signature.asc

kfj

unread,
Dec 25, 2010, 12:36:58 PM12/25/10
to hugin and other free panoramic software


On 25 Dez., 18:23, Yuval Levy <goo...@levy.ch> wrote:

> fixed.  do you want to add the script to your repo (I can't and I don't think
> you can simply give write access to personal repos like that one)?

I think maybe one can. When I get round to it, I'll investigate. For
now, I'll gladly put it into my repo, if you think that's a good place
for it. Bit of an obscure location ;-)

Kay

Yuval Levy

unread,
Dec 25, 2010, 7:39:39 PM12/25/10
to hugi...@googlegroups.com
On December 25, 2010 12:36:58 pm kfj wrote:
> I'll gladly put it into my repo, if you think that's a good place
> for it. Bit of an obscure location ;-)

it surely is a better place than the oblivion of a mailing list memory. And
it is not so obscure, I found it when I needed it.

If you want a less obscure place, you can start a public project on Launchpad.
Call it Pythorama or PanoPython or PyPTO or whatever name is not taken yet ;-)

It is my honor to have my scribbling sharing repo with your code.

Yuv

signature.asc

kfj

unread,
Dec 26, 2010, 7:36:58 AM12/26/10
to hugin and other free panoramic software


On 26 Dez., 01:39, Yuval Levy <goo...@levy.ch> wrote:

> If you want a less obscure place, you can start a public project on Launchpad.  
> Call it Pythorama or PanoPython or PyPTO or whatever name is not taken yet ;-)

thought to maybe do something along these lines. Looks better than
having 'junk' in your path.

> It is my honor to have my scribbling sharing repo with your code.

It's there already. Since you already put me in as a joint copyright
holder, I may dabble with it a little. I think, though, that merely
importing a GPL'ed Python module in your script doesn't affect your
copyright or introduce mine into it - since it's GPL'ed, though, I
think you couldn't use it in a commercial setup. Is this not so?
Anyway, I feel honoured to share the copyright with you - it's maybe
only a little thing, but it's a start ;-)
I'll look into the matter of how to grant write access to my bazaar
repo soon - was busy all morning.

Kay
Reply all
Reply to author
Forward
0 new messages