【发布时间】:2018-11-09 11:16:35
【问题描述】:
所以我使用的是 Google Vision TEXT_DETECTION,它的基础是 - 它读取一个车牌,然后使用 PHPGD 用一个多边形覆盖它。现在这一切都很好,但似乎坐标数组的顺序错误,我把头撞在墙上我希望你能帮忙:)
在上图中,您可以看到车牌和围绕它的多边形。您可以看到它应该是 2 个正方形,但它是一个正方形和一个十字
这是我获取坐标并使用它们放置多边形的代码
$response = json_decode($json_response, true);
//dd($response);
$red =0;
$green =0;
$blue = 0;
$i =0;
foreach($response['responses'][0]['fullTextAnnotation']['pages'] as $box) {
$points = array();
foreach ($box['blocks'] as $block) {
foreach ($block['paragraphs'] as $paragraph) {
foreach ($paragraph['words'] as $word) {
foreach ($word['boundingBox']['vertices'] as $vertex) {
array_push($points, $vertex['x'], $vertex['y']);
}
$count_points = count($points) / 2;
$color = imagecolorallocate($im, round(0), round(0), round(0));
imagefilledpolygon($im, $points, $count_points, $color);
var_dump($points);
}
}
}
}
这是一个 $points(坐标) 的 var_dump
array(8) {
[0]=> int(424)
[1]=> int(224)
[2]=> int(446)
[3]=> int(218)
[4]=> int(451)
[5]=> int(235)
[6]=> int(429)
[7]=> int(241) }
array(16) {
[0]=> int(424)
[1]=> int(224)
[2]=> int(446)
[3]=> int(218)
[4]=> int(451)
[5]=> int(235)
[6]=> int(429)
[7]=> int(241)
[8]=> int(454)
[9]=> int(216)
[10]=> int(472)
[11]=> int(211)
[12]=> int(477)
[13]=> int(228)
[14]=> int(459)
[15]=> int(233)
}
【问题讨论】:
标签: php arrays google-vision