python - 从 python 脚本调用 exe

标签 python exe

我正在尝试从文件夹中读取文件并运行与 .py 文件位于同一目录中的 colorDescriptor.exe 。实际上我想要,每次读取文件来计算 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.1秒完成】

最佳答案

问题是您没有使用在命令中生成的值。您需要使用 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/

相关文章:

php - 如何使用 urllib 对 url 进行编码

python - ajax post 上的 django-csrf 保护

python - 'unlink()' does not work in Python' s shared_memory on Windows

c# - 是否正在做任何工作来创建 C# 编译器来生成 native exe?

python - 使用 cx_freeze 将 .py 转换为可执行文件时出错

java - 在 Java 中调用 Python 3.x 函数

python - Pandas 无法读取使用 h5py 创建的 hdf5 文件

java - 如何为java程序制作带有图标的exe

python - 异常 : Python. 在 pyinstaller 中找不到运行时

winforms - EXE 和 MSI 之间的最佳方法