【发布时间】:2019-02-21 15:48:22
【问题描述】:
我想在 python 中获取文件的平均亮度。阅读了上一个问题 [Problem getting terminal output from ImageMagick's compare.exe ( Either by pipe or Python ) 我想出了:
cmd='/usr/bin/convert {} -format "%[fx:100*image.mean]\n" info: > bright.txt'.format(full)
subprocess.call(cmd,shell=True)
with open('bright.txt', 'r') as myfile:
x=myfile.read().replace('\n', '')
return x
上一个问题推荐使用“pythonmagick”,我可以找到它,但没有当前文档,最近的活动也很少。我想不出使用它的语法。
我知道我的代码不能令人满意,但它确实有效。 有没有更好的方法不需要 'shell=true' 或额外的文件处理?
【问题讨论】:
-
我不是 Python Wand 专家,但您可以在 Python Wand 中执行 fx 命令。见docs.wand-py.org/en/0.4.1/wand/image.html
-
您还可以使用 Python Pillow 来获取图像的均值。见pillow.readthedocs.io/en/5.2.x/reference/ImageStat.html
标签: python subprocess imagemagick