如何在图像PHP中检测形状的位置 [英] How to detect position of shape in image PHP

查看:140
本文介绍了如何在图像PHP中检测形状的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的图像带有白色背景,在该图像中,我有某种形状-布的一部分。我需要找到最左,上,右和下像素。最有效的方法是什么?

I have image with white background and in that image i have some kind of shape - part of cloth. I need to find most left, up, right and bottom pixel. What is the most efficient way to do that?

推荐答案

您可以使用trimImage函数修剪图像,然后查看几何和页面信息以查找修剪后剩余的图像边界框。

You can use the trimImage function to trim the image, and then look at the geometry and page info to find how the bounding box of the image that was left after trimming.

$base = new Imagick(realpath('./trim.png'));

$base->trimImage(0);

$geometry = $base->getImageGeometry();
$pageInfo = $base->getImagePage();

printf (
    "Width %d Height %d\n",
    $geometry['width'],
    $geometry['height']
);

printf(
    "OffsetX: %d OffsetY %d\n",
    $pageInfo['x'],
    $pageInfo['y']
);

这篇关于如何在图像PHP中检测形状的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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