float类型的子进程参数不可迭代

时间:2013-01-04 22:40:50

标签: python python-2.7

在运行下面的代码时,我在子进程模块中收到错误。参数horizo​​ntaldeviation和vertical deviation是浮点数,我正在运行一个带有命令行浮点参数的二进制.exe文件carddetector。

 **Traceback (most recent call last):
  File "C:\Python27\card_detection_test\run_card_detection_test.py", line 174, in <module>
    process_dataset(dataset, args)
  File "C:\Python27\card_detection_test\run_card_detection_test.py", line 102, i
n process_dataset
    output_file)
  File "C:\Python27\card_detection_test\run_card_detection_test.py", line 38, in
 run_recognition
    subprocess.check_call(args, stdout=fout, stderr=dmp)
  File "C:\python27\lib\subprocess.py", line 506, in check_call
    retcode = call(*popenargs, **kwargs)
  File "C:\python27\lib\subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "C:\python27\lib\subprocess.py", line 679, in __init__
    errread, errwrite)
  File "C:\python27\lib\subprocess.py", line 855, in _execute_child
    args = list2cmdline(args)
  File "C:\python27\lib\subprocess.py", line 587, in list2cmdline
    needquote = (" " in arg) or ("\t" in arg) or not arg
TypeError: argument of type 'float' is not iterable**


def run_recognition(carddetector,
                 init_path,
                 horizontaldeviation,
                 verticaldeviation,
                 imgwidth,
                 imgheight,
                 input_path,
                 output_file):
carddetector = os.path.abspath(carddetector)
init_path = os.path.abspath(init_path)
input_path = os.path.abspath(input_path)
output_file = os.path.abspath(output_file)
args =[carddetector,
                 init_path,
                 horizontaldeviation,
                 verticaldeviation,
                 imgwidth,
                 imgheight,
                 input_path,
                 output_file]
res = True
dmp = open(output_file + '.dmp', 'w')
out_dir = output_file + '.dir'
curr_dir = os.getcwd()
try:
    fout = open(output_file, 'w')
    try:
        subprocess.check_call(args, stdout=fout, stderr=dmp)
    except subprocess.CalledProcessError:
        print 'runner failed at: ' +  input_path
        res = False
    finally:
        fout.close()
except IOError:
    print 'cannot open', output_file
    res = False
finally:
    dmp.close()
os.chdir(curr_dir)
return res
def process_dataset(dataset, cfg):
print 'processing: ', dataset
item_path = os.path.join(cfg.datasets,dataset)

if not os.path.isdir(item_path):
    print "not a directory:", item_path
    return
run_args = []
files_in_dir = os.listdir(item_path)
for input_file in files_in_dir:
    print 'input file', input_file
    if fnmatch.fnmatch(input_file,'*.png'):
        input_path = os.path.join(item_path, input_file)
        output_file = os.path.join(cfg.output, input_file + '.yaml')
        run_args.append((cfg.carddetector,
                    cfg.init_path,
                    cfg.horizontaldeviation,
                    cfg.verticaldeviation,
                    cfg.imgwidth,
                    cfg.imgheight,
                    input_path,
                    output_file))
        print 'run_args', run_args

        run_recognition(cfg.carddetector,
                    cfg.init_path,
                    cfg.horizontaldeviation,
                    cfg.verticaldeviation,
                    cfg.imgwidth,
                    cfg.imgheight,
                    input_path,
                    output_file)

0 个答案:

没有答案