RenameAll.exe in Python
RenameAll.exe in Python

Download: (1K)

Someone wanted to use the tools I wrote for the cardboard bookscanner on a non-windows platform… et voilĂ , the same functionality in Python (2.7.3):

 Matti Kariluoma Jun 2011 

 A python rendition of RenameAll.exe (
 from the Cardboard Bookscanner project, Jan 2010.

 This script loads a directory of images, then renames them all such
 that the first half and the second half are intersperesed. The input
 directory is expected to contain 2n or 2n+1 images, where the first n
 images are of the right-hand side of a book, and the last n are the
 left-hand side of the book.

import os, sys, glob
import cv

images_filename = []
images_filename =	glob.glob1(sys.argv[1], "*.[j,J][p,P,pe,PE][g,G]")


NUM_PIC = len(images_filename)

n = 0

for filename in images_filename:
	image = cv.LoadImage(sys.argv[1]+"/"+filename)
	if (n < NUM_PIC / 2):
		#sprintf(temp, "%06d-a.jpg", n+1)
		cv.SaveImage(sys.argv[1]+"/%06d-a.jpg" % (n+1), image)
		#sprintf(temp, "%06d-b.jpg", n+1-NUM_PIC/2)
		cv.SaveImage(sys.argv[1]+"/%06d-b.jpg" % (n+1-NUM_PIC/2), image)
	n += 1

Truth be told, I only wrote the tools so windows users could play along too; I imagined non-windows users would write some shell one-liners.

Leave a Comment?

Send me an email, then I'll place our discussion on this page (with your permission).

Return | About/Contact