python-3.x - ImageMagick和Wand之间连接组件的输出不同?
问题描述
我正在尝试使用 Windows10 下的连接组件功能获取颜色坐标
- 蟒蛇 3.8.5
- ImageMagick 7.0.10-29 Q8 x64 2020-09-05
将 ImageMagick 与以下命令一起使用,我可以正确获取坐标。
>convert input.png -define connected-components:verbose=true -define connected-components:area-threshold=100 -connected-components 8
-auto-level out:null
Objects (id: bounding-box centroid area mean-color):
0: 284x172+0+0 133.5,60.0 26161 srgb(0,0,0)
2: 259x59+14+84 143.0,113.0 15281 srgb(255,255,255)
3: 259x17+14+144 143.0,152.0 4403 srgb(255,255,255)
1: 143x21+130+60 201.0,70.0 3003 srgb(255,255,255)
当我将连接组件与 Python3/Wand 一起使用时,我得到不同的输出。
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:57:54) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from wand.image import Image
>>> with Image(filename='input.png') as img:
... objects = img.connected_components()
...
>>> for cc_obj in objects:
... print("{0._id}: {0.size} {0.offset}".format(cc_obj))
...
0: (284, 172) (0, 0)
0: (0, 0) (0, 0)
14: (84, 98784247810) (0, 0)
0: (0, 0) (0, 0)
>>>
为什么 python/Wand 的输出不同?如何解决?提前致谢。
下面是输入图像。
下面是输入图像。
解决方案
下面是使用 Python 子进程调用 ImageMagick 命令行的示例(修剪图像的多余背景):
import subprocess
cmd = 'convert 0.png -fuzz 30% -trim +repage 0_trim.png'
subprocess.check_output(cmd, shell=True, universal_newlines=True)
一个替代方案是:
import subprocess
cmd = 'convert 0.png -fuzz 30% -trim +repage 0_trim.png'
subprocess.call(cmd, shell=True)
推荐阅读
- python - 无法弄清楚如何在张量中使用值
- vue.js - Quasar Framework (Vue) Uploader 使用 apollo-upload (GraphQL)
- python-3.x - 在自己的图像上测试网络
- php - 在 Laravel 5.7 中合并具有多个键的集合
- typescript - 如何为客户端转译打字稿
- c# - 第一次调用异步等待仍然有错误 IEnumerable
不包含 GetAwaiter 的定义 - algorithm - 如何为多人游戏随机创建一个公平的迷宫?
- php - 如何使用多个标签快速搜索帖子/列表?
- c# - 将网络开始位置添加到游戏对象后如何修复触发器
- indexing - Dspace 作者索引不敏感的口音