具有宽高比的裁剪图像未考虑上下文

Crop image with aspect ratio doesn't take into account the context

我正在尝试在 php 中使用 Google 视觉 API 裁剪图像。 API returns 最好的剪裁, 不考虑纵横比 我发送。

这是我目前的情况:

    $imageAnnotator = new ImageAnnotatorClient();

    $image = file_get_contents(storage_path('test.jpg'));
    $context = new \Google\Cloud\Vision\V1\ImageContext();
    $cropHintsParams = new \Google\Cloud\Vision\V1\CropHintsParams();
    $cropHintsParams->setAspectRatios([floatval(1)]);
    $context->setCropHintsParams($cropHintsParams);

    $response = $imageAnnotator->cropHintsDetection($image, [$context]);
    $annotations = $response->getCropHintsAnnotation();

知道这有什么问题吗?

php 文档示例未提供任何纵横比...https://cloud.google.com/vision/docs/detecting-crop-hints

提前致谢

好的,在 Google libs 深入研究了 2 小时后,发现需要在关联数组中提供 imageContext,如下所示:

$response = $imageAnnotator->cropHintsDetection($im, ['imageContext' => $context]);

希望这会为未来的人节省一些时间:)