Android中的Google vision API食品标签检测

时间:2017-03-09 18:05:12

标签: php android google-play-services google-cloud-vision

我正在为Android手机制作一个深入的食物记录应用程序,我想使用google vision API添加一些基本的图像识别。

我一直在试验API并使用PHP但没有成功。 我一直在浏览所有的教程,总是陷入困境。

这是我到目前为止最接近的PHP

data2
data3

但后来我收到了这个错误。

<?php
# Includes the autoloader for libraries installed with composer
require __DIR__ . '/vendor/autoload.php';

# Imports the Google Cloud client library
use Google\Cloud\Vision\VisionClient;

# Your Google Cloud Platform project ID
$projectId = 'foodlogging-160914';

putenv('GOOGLE_APPLICATION_CREDENTIALS=./FoodLogging-ae7e284eb66e.json');

# Instantiates a client
$vision = new VisionClient([
    'projectId' => $projectId
]);

# The name of the image file to annotate
$fileName = __DIR__ . '/hamburger.jpg';

# Prepare the image to be annotated
$image = $vision->image(fopen($fileName, 'r'), [
    'LABEL_DETECTION'
]);

# Performs label detection on the image file
$labels = $vision->annotate($image)->labels();

echo "Labels:\n";
foreach ($labels as $label) {
    echo $label->description() . "\n";
}
?>

我已经关注了整个文档,我不知道为什么它在日期时间方面有问题,因为我从来没有使用它。

有没有人有使用google vision API的经验可以帮到我?最好是安装android部分,帮我上路还是帮我上手?

非常感谢。

1 个答案:

答案 0 :(得分:0)

在php.ini中设置时区。

➜ ~ cat /etc/php.ini | grep timezone ; Defines the default timezone used by the date functions ; http://php.net/date.timezone date.timezone = America/Sao_Paulo

相关问题