【发布时间】:2012-03-21 08:59:06
【问题描述】:
在如何连接迭代列表(声明为 fileListL)方面需要帮助,该列表是从子目录(左)中的一系列图像文件动态构建的,并循环直到到达帧范围的末尾。所有脚本都在单个帧上按预期工作,但我无法让它循环多个帧。想法,想法?
# this module runs within a root directory that contains one sub folder named 'left' and 15 sub folders expressed in the dirL as ('left/01','left/02, . . . .)
# each folder can have any number of sequential .jpg images in the format 'name.0000.jpg'
import os
import sys
import glob
import Image
from itertools import izip, count
# create Master List of files in Left Directories along with a count of files
global fileListL
fileListL = []
for root, dirs, files in os.walk(r'left/'):
for file in files:
if file.endswith('.jpg'):
fileListL.append('left/'+file)
print fileListL
# Iterator
global inFrame
global outFrame
inFrame = 'left/test.0000.jpg' # testing temp needs dynamic variable, trying to use fileList L list to dynamically increment thru frames
outFrame = inFrame[5:-5]
crops = ((0, 0, 1920, 1080),(1920, 0, 3840, 1080), (3840, 0, 5760, 1080), (5760, 0, 7680, 1080), (7680, 0, 9600, 1080), (9600, 0, 11520, 1080), (11520, 0, 13440, 1080), (13440, 0, 15360, 1080), (15360, 0, 17280, 1080), (17280, 0, 19200, 1080), (19200, 0, 21120, 1080), (21120, 0, 23040, 1080), (23040, 0, 24960, 1080), (24960, 0, 26880, 1080), (26880, 0, 28800, 1080))
quads = ('01_', '02_', '03_', '04_', '05_', '06_', '07_', '08_', '09_', '10_', '11_', '12_', '13_', '14_', '15_')
dirL= ('left/01/', 'left/02/', 'left/03/', 'left/04/', 'left/05/', 'left/06/', 'left/07/', 'left/08/', 'left/09/', 'left/10/', 'left/11/', 'left/12/', 'left/13/', 'left/14/', 'left/15/')
for i in fileListL:
for infile in glob.glob( os.path.join(inFrame) ):
print "current file is: " + infile
oL = Image.open(inFrame) # needs dynamic variable for frames
for i, each_quad, each_frame, each_dirL in izip(count(), crops, quads, dirL):
print i, each_quad, each_frame, each_dirL
frame = oL.crop(((each_quad)))
frame.save((each_dirL)+(each_frame)+(outFrame)+'.png')
【问题讨论】:
-
你有什么错误吗?消息打印正常吗?
-
在分配给“inFrame”的单个帧上运行模块时没有错误。每当我在左根目录中有多个图像时,它只会覆盖所有子目录中的相同分割图像. 所以本身没有错误,只需要得到一个正确循环通过 fileListL 的循环。
-
Image.open(inFrame)你是否总是打算打开同一张图片? -
No (inFrame) 当前设置为静态值,以便更容易解释问题。理想情况下,fileListL 需要迭代地输入这个值。想知道我是否需要对所有内容进行一些重组以以不同的方式滑动帧序列?
标签: python list iterator directory