2017-03-09 69 views
0

我正在爲android手機做一個深入的食品日誌記錄應用程序,我想用谷歌視覺API添加一些基本的圖像識別。Android中的Google視覺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部分,幫助我順利開始或幫助我開始?

提前感謝。

回答

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

+0

我剛所附 「date_default_timezone_set( 'UTC');」到我的腳本的頂部,這也做了伎倆!謝謝! – user3801533