首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >我如何在Python中使用imagemagick?

我如何在Python中使用imagemagick?
EN

Stack Overflow用户
提问于 2020-06-15 23:59:15
回答 1查看 1.9K关注 0票数 1

下面有两个我想用Python实现的命令。我完全是Imagemagick的新手,所以有人能告诉我如何在Python中使用以下命令吗?我想我得用魔杖了?

代码语言:javascript
运行
复制
convert input.png -crop 762x41+32+100 -units pixelsperinch -density 300 image.png

convert image.png -auto-level -negate -threshold 70% crop_processed.png

tesseract crop-processed.png stdout

输入图像:

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-06-16 01:52:52

这里是如何在Python .中实现这一点的。

输入:

代码语言:javascript
运行
复制
from wand.image import Image
from wand.display import display

with Image(filename='stockholm.jpg') as img:
    img.crop(left=34, top=99, width=755, height=37)
    img.auto_level()
    img.negate()
    img.threshold(threshold=0.70)
    img.save(filename='stockhold_processed.png')
    display(img)

结果:

或使用Python/OpenCV

代码语言:javascript
运行
复制
import cv2
import numpy as np

# read image as grayscale
img = cv2.imread('stockholm.jpg', cv2.IMREAD_GRAYSCALE)

# crop image
img = img[99:99+37, 34:34+755]

# threshold image
img_thresh = cv2.threshold(img, 128, 255, cv2.THRESH_BINARY)[1]

# view result
cv2.imshow("threshold", img_thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()

# save result
cv2.imwrite("stockholm_crop_threshold.png", img_thresh)

结果:

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62398868

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档