【问题标题】:Google vision API food label detection in androidandroid中的谷歌视觉API食品标签检测
【发布时间】:2017-03-09 18:05:12
【问题描述】:

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

我一直在尝试使用 API 并使用 PHP,但没有成功。 我一直在浏览所有教程,但总是卡在某个点上。

这是迄今为止我在 php 中最接近的一次

<?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";
}
?>

但是我得到了这个错误。

Fatal error: Uncaught exception 'Google\Cloud\Exception\ServiceException' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone.' in /Library/WebServer/Documents/foodLogging/vendor/google/cloud/src/RequestWrapper.php:223 Stack trace: #0 /Library/WebServer/Documents/foodLogging/vendor/google/cloud/src/RequestWrapper.php(136): Google\Cloud\RequestWrapper->convertToGoogleException(Object(Google\Cloud\Exception\ServiceException)) #1 /Library/WebServer/Documents/foodLogging/vendor/google/cloud/src/RestTrait.php(83): Google\Cloud\RequestWrapper->send(Object(GuzzleHttp\Psr7\Request), Array) #2 /Library/WebServer/Documents/foodLogging/vendor/google/cloud/src/Vision/Connecti in /Library/WebServer/Documents/foodLogging/vendor/google/cloud/src/RequestWrapper.php on line 223

我已经阅读了整个文档,但我不知道为什么它对日期时间有问题,因为我什至从未使用过它。

有没有人有任何可以帮助我的谷歌视觉 API 的经验?最好是android部分,帮我上路还是帮我入门?

先谢谢了。

【问题讨论】:

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


    【解决方案1】:

    在 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

    【讨论】:

    • 我刚刚附加了“date_default_timezone_set('UTC');”到我脚本的顶部,这也起到了作用!谢谢!
    猜你喜欢
    • 2017-09-09
    • 2019-12-18
    • 1970-01-01
    • 2017-02-04
    • 1970-01-01
    • 2017-06-14
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多