具有宽高比的图像不考虑上下文

问题描述 投票:0回答:1

我正在尝试使用php中的Google Vision API裁剪图像。该API返回可能的最佳裁剪,不考虑宽高比我正在发送。

这是我到目前为止的内容:

    $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

提前谢谢您

php google-vision
1个回答
0
投票

确定,经过2个小时的深入研究Google libs,结果证明imageContext需要以如下所示的关联数组提供:

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

希望这可以节省将来的时间:)

© www.soinside.com 2019 - 2024. All rights reserved.