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
#!/usr/bin/python
# -*- coding: utf-8 -*-
gpl = r"""
ptoimggen.py - scan a pto file and generate placeholder images
and project file to use when debugging
Copyright (C) 2010 Kay F. Jahnke
Copyright (C) 2010 Yuval Levy
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
import argparse
import parse_pto
import random
import os
# I needed a routine to scan i-lines in pto files and make sure Hugin does
# not complain about missing images or other things.
def imgfile_to_i_lines ( scan ) :
scan.make_member_access() # makes accessing the data more comfortable ;-)
for line in scan.i :
# parse the i lines
if line.header == 'i' : # look at all i-lines
# get the width, height, and image file name from the i line
width = line.w.value # extract the desired values
height = line.h.value
# remove the path from the filename
# postfix the name with '_dummy.jpg' to avoid overwriting
# existing files and to save space by using the jpg format
name = os.path.basename ( line.n.value ) + '_dummy.jpg'
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)" -quality 1 %s' % (width, height, r, g , b, name)
# tell me you're doing something
print cmd
# execute it
os.system(cmd)
# 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 )
def main() :
# we create an argument parser
parser = argparse.ArgumentParser (
formatter_class=argparse.RawDescriptionHelpFormatter ,
description = gpl + '''
We ask users to post pto files that cause errors
with their bug reports, but not the actual images to
avoid straining bandwidth and online storage.
The first thing a bug hunter does to analyze the pto
file is to fix the images. This script does it by
creating placeholder images and a dummy project file
to play with.
''' )
parser.add_argument('-p', '--pto',
metavar='<pto file>',
type=str,
help='pto file to be processed')
if len ( sys.argv ) < 2 :
parser.print_help()
return
args = parser.parse_args( sys.argv[1:] )
scan = parse_pto.pto_scan ( args.pto )
imgfile_to_i_lines ( scan )
# are we main? if so, do the main thing...
if __name__ == "__main__":
main()
signature.asc
Description: This is a digitally signed message part.
