PHP x1,x2,y1,y2坐标的边界框(左侧,顶部,高度,宽度)?

时间:2018-12-12 06:11:25

标签: php laravel amazon-web-services amazon-rekognition

我正在使用AWS Rekognition检测图像中的面部。当检测到人脸时,它将输出装订框信息,以便您可以使用它在图像上绘制一个人脸。但是,它们分别是左,顶部,高度和宽度,数字是十进制浮点数。

以下是输出示例:

while($true){

[void][System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
Function Pick-Date {
  $Cal = New-Object System.Windows.Forms.MonthCalendar
  $Cal.ShowWeekNumbers = $true
  $Cal.MaxSelectionCount = 1
  $Cal.Dock = 'Fill'
  $Form = New-Object Windows.Forms.Form
  $Form.text = "Colocar fecha que desea enviar. Y presiona Enter"
  $Form.Size = New-Object Drawing.Size @(656,620)
  $btnSelect = New-Object System.Windows.Forms.Button
  $btnSelect.Size = "100,100"
  $btnSelect.add_Click({ $Form.close() })
  $btnSelect.Location = New-Object System.Drawing.Point(530,480)
  $btnSelect.Text="ENTER"
  $Form.Controls.Add($btnSelect )
  $Form.AcceptButton = $btnSelect
  $Form.Controls.Add($Cal)
  $Form.Add_Shown({$Form.Activate()})
  [void]$Form.ShowDialog()
  return (Get-Date($Cal.SelectionStart))
}

$fecha = Pick-Date

}

然后在图像上画出框:

{ "BoundingBox": { "Width": 0.06649632751941680908203125, "Height": 0.102198123931884765625, "Left": 0.52286112308502197265625, "Top": 0.2651510536670684814453125 }

但是,盒子永远不会与面部匹配。有没有更简单的方法来转换这些变量或计算它们?我到处都看过了,真的可以使用一些指导。

1 个答案:

答案 0 :(得分:0)

想通了:

list($width, $height) = getimagesize($destinationPath . $im . '.png');
                    $white = imagecolorallocate($im, 255, 255, 255);
                    foreach ($result['FaceDetails'] as $r) {
                        $widtho = $r['BoundingBox']['Width'];
                        $heighto = $r['BoundingBox']['Height'];
                        $left = $r['BoundingBox']['Left'];
                        $top = $r['BoundingBox']['Top'];
                        $w = $width * $widtho;
                        $h = $height * $heighto;
                        $x = $left * $width;
                        $y = $top * $height;
                        imagerectangle($im, $x, $y, $x + $w, $y + $h, $white);
                        imagepng($im, $destinationPath . $im . '.png', 9);
                    }