gpt4 book ai didi

python - 从 python 脚本调用 exe

转载 作者:行者123 更新时间:2023-11-28 22:50:57 27 4
gpt4 key购买 nike

我正在尝试从文件夹中读取文件并运行 colorDescriptor.exe,它与 .py 文件位于同一目录中。实际上我想要,每次它读取一个文件来计算 colorDescriptor。

我的代码如下:

import os

from os import listdir
from os.path import isfile, join
mypath1 = "/clothes/"
mypath2 = "/i386-win-vc/"
onlyfiles = [ f for f in listdir(mypath1) if isfile(join(mypath1,f)) ]
image = mypath1+f
os.popen("colorDescriptor image --detector harrislaplace --descriptor sift --output
onlyfiles.txt ")
print image

在终端中,使用 colorDescriptor.exe 的语法例如是:

colorDescriptor image.jpg --detector harrislaplace --descriptor sift --output onlyfiles.txt

我收到错误信息:

Tue04 10:53:30,248 - [Impala.Persistency.FileSystem ] Unable to find image in path 
Tue04 10:53:30,248 - [Impala.Core.Array.ReadFile ] Don't know how to read
Tue04 10:53:30,248 - [Sandbox.koen.mainColorDescriptor ] [ERROR] Could not read input
file: is it really a valid image? image

用建议的代码更改后:

import os

from os import listdir
from os.path import isfile, join
mypath1 = "C:/Documents and Settings/Desktop/clothes/"
mypath2 = "C:/Documents and Settings/My
Documents/colordescriptors40/i386-win-vc/"
onlyfiles = [ f for f in listdir(mypath1) if isfile(join(mypath1,f)) ]
image = mypath1+f
print image
pattern = "colorDescriptor %s --detector harrislaplace --descriptor sift --output
onlyfiles.txt"
os.system(pattern % image)

我现在收到以下信息:

 Tue04 11:06:45,091 ERROR [Impala.Persistency.FileSystem ] Unable to find C:/Documents 
in
path
Tue04 11:06:45,091 INFO [Impala.Persistency.FileSystem ]
Tue04 11:06:45,091 ERROR [Impala.Core.Array.ReadFile ] Don't know how to read
Tue04 11:06:45,091 ERROR [Sandbox.koen.mainColorDescriptor ] [ERROR] Could not read input

文件:它真的是一个有效的图像吗? C:/文档 [0.1s完成]

最佳答案

问题是您没有使用在命令中生成的值。您需要使用 glob.glob 来获取图像列表(可能是“*.jpg”)、目录中的文件,然后为每个文件创建一个新的 outfile.text 名称并执行如下命令:

    cmd = "colorDescriptor %s --detector harrislaplace --descriptor sift --output %s.txt " % (imagepath, imagepath)
os.popen(cmd)

关于python - 从 python 脚本调用 exe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22166769/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com