2017-06-05 69 views
0

我正在嘗試使用Google Cloud Vision API檢測遠程圖像中的文本,但似乎無法獲得vision.detectText()語法。谷歌雲視覺API:node.js和圖像的URI,如何調用vision.detectText()?

當沒有云存儲存儲桶時,如何使用vision.detectText()?

我想我可以/應該忽略參考storage.bucket()上https://cloud.google.com/vision/docs/detecting-text

表示我:

vision.detectText('https://drive.google.com/file 
    /d/0Bw4DMtLCtPMkWVlIVXE5a2ZpQlU/view?usp=drivesdk') 
      .then((results) => { 
      const detections = results[0]; 
      console.log('Text:'); 
      detections.forEach((text) => console.log(text)); 
      }) 
      .catch((err) => { 
      console.error('ERROR:', err); 
      }); 

控制檯報告:

ERROR: { PartialFailureError: A failure occurred during this request. 
at /Users/node_modules/@google-cloud/vision/src/index.js:434:15 
at /Users/node_modules/@google-cloud/vision/src/index.js:126:5 
at _combinedTickCallback (internal/process/next_tick.js:80:11) 
at process._tickCallback (internal/process/next_tick.js:104:9) 
errors: 
[ { image: 'https://drive.google.com/file/d 
/0Bw4DMtLCtPMkNFFselFhU0RMV2c/view?usp=drivesdk', 
    errors: [Object] } ], 
response: { responses: [ [Object] ] }, 
message: 'A failure occurred during this request.' } 

我已嘗試使用:

vision.detectText(storage.bucket().file('https://...... 

但錯誤是:

Error: A bucket name is needed to use Cloud Storage. 

回答

0

看起來你不是要設置你的GOOGLE_APPLICATION_CREDENTIALS環境變量。下面的代碼工作的測試:

const Vision = require('@google-cloud/vision'); 
const vision = Vision(); 
const fileName = 'http://example.com/eg.jpg'; 

vision.detectText(fileName) 
    .then((results) => { 
    const detections = results[0]; 

    console.log('Text:'); 
    detections.forEach((text) => console.log(text)); 
    }) 
    .catch((err) => { 
     console.error('ERROR:', err); 
    }); 

要嘗試一下我們的樣品,通過一個URI(例如HTTP URI)的​​3210樣品:

node detect.js fulltext http://www.identifont.com/samples/houseindustries/NeutraText.gif 
+0

vision.detectFaces()不表示一個桶參數像vision.detectText() – user1405141

+0

已更新,以演示文本檢測 – class

+0

罷工。讓我看看,謝謝。 – user1405141