如何将命令imagemagick转换为php代码?

问题描述 投票:-2回答:1

我想用OCR。但图像无法完美读取,因此我将图像转换为删除噪声背景,Original Images

然后,我运行这个命令:

convert -colorspace gray -modulate 120 -contrast-stretch 10%x80% -modulate 140 -gaussian-blur 1 -contrast-stretch 5%x50% +repage -negate -gaussian-blur 4 -negate -modulate 130 original.jpeg clean.jpeg

Images Result

问题是,如何将上述命令转换为php?好吧,我在php中使用imagick非常困惑。

mycode(这就是我所知道的):

$image = new Imagick('captcha.png'); 
$image->modulateImage(450, 0, 500);
$image->writeImage("output.jpg"); 

来自PHP Imagick的结果:HERE

我知道,这是不同的配置号,但结果不是很远。

有什么建议吗?

====回答(谢谢你qazxsw poi)

fmw42
php imagemagick ocr imagemagick-convert
1个回答
1
投票

要删除黑色边框并在ImageMagick中为图像设置阈值,请执行此操作

输入:

$image = new Imagick('captcha.png'); $image->thresholdimage(0.1 * \Imagick::getQuantum(), 134217727); $image->shaveImage(2, 1); $image->writeImage("output.jpg");

enter image description here

convert img.png -shave 1x1 -threshold 0 result.png

因为8和7触摸,如果OCR工作,我会感到惊讶。

对于Imagick,请参阅

enter image description here https://www.php.net/manual/en/imagick.thresholdimage.php

© www.soinside.com 2019 - 2024. All rights reserved.