如何检测图像内部纸张的边框并使用ImageMagick进行裁剪? [英] How can I detect borders of a piece of paper inside of an image and crop it using ImageMagick?

查看:202
本文介绍了如何检测图像内部纸张的边框并使用ImageMagick进行裁剪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从照片中裁剪纸质文档。例如,有人拍摄文档的照片并将其发送到服务器,它将被编辑为看起来像扫描文档。如何检测文档的边框并使用ImageMagick裁剪它?

I'm trying to crop paper documents from photographs. For example, someone takes a picture of a document and sends it to the server and it will get edited to look like a scanned document. How can I detect the border of the document and crop it using ImageMagick?

谢谢

推荐答案

你想使用convert命令和 -trim option 裁剪纯色边框,自此扫描图像, -fuzz选项以确保修剪即使颜色不完全坚固,也完全裁剪边框。

You want to use the convert command with the -trim option to crop out the solid color borders, and since the images are scanned, the -fuzz option to make sure trim completely crops the border even if the color isn't perfectly solid.

所以这样的事情:

convert input.jpg -fuzz 2% -trim output.jpg

将其翻译成PHP代码,你最终得到这个:

Translating that into PHP code, you'd end up with this:

$image = new Imagick('input.jpg');
$image->trimImage(2); // Trim the image with a 2% fuzz
$image->writeImage('output.jpg');

这篇关于如何检测图像内部纸张的边框并使用ImageMagick进行裁剪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆