google Cloud Vision API: node.js 和图像 URI,如何调用 vision.detectText()?
google Cloud Vision API: node.js and an image URI, how to invoke vision.detectText()?
我正在尝试使用 google Cloud Vision API 检测远程图像中的文本,但似乎无法正确使用 vision.detectText() 语法。
没有云存储桶时如何使用vision.detectText()?
我想我 can/should 忽略了 https://cloud.google.com/vision/docs/detecting-text
上对 storage.bucket() 的引用
我有:
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.
您似乎没有设置 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)传递给 detect.js 示例,如下所示:
node detect.js fulltext http://www.identifont.com/samples/houseindustries/NeutraText.gif
我正在尝试使用 google Cloud Vision API 检测远程图像中的文本,但似乎无法正确使用 vision.detectText() 语法。
没有云存储桶时如何使用vision.detectText()?
我想我 can/should 忽略了 https://cloud.google.com/vision/docs/detecting-text
上对 storage.bucket() 的引用我有:
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.
您似乎没有设置 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)传递给 detect.js 示例,如下所示:
node detect.js fulltext http://www.identifont.com/samples/houseindustries/NeutraText.gif