Closed ghost closed 6 years ago
I tried your example but with
const uriBase = 'https://westcentralus.api.cognitive.microsoft.com/vision/v2.0/ocr';
instead of
const uriBase = 'https://westcentralus.api.cognitive.microsoft.com/vision/v1.0';
and got a different result -
message: "Access denied due to invalid subscription key. Make sure to provide a valid key for an active subscription."
as expected, as I don't have a subscription key. Can you try with this uriBase?
it worked, I have last two questions before you close this issue. Do you have a Sample, which can provide the text in images with bot-builder? and the other question: with which function can I get the Text of Json like a string in this example: I want to get the texts like this: "NOTHING EXISTS"
' "textAngle": 0, "regions": [ { "boundingBox": "21,16,304,451", "lines": [ { "boundingBox": "28,16,288,41", "words": [ { "boundingBox": "28,16,288,41", "text": "NOTHING" } ] }, { "boundingBox": "27,66,283,52", "words": [ { "boundingBox": "27,66,283,52", "text": "EXISTS" } ] },'
Do you have a Sample, which can provide the text in images with bot-builder?
No, I am not familiar with this product, just happened to peep into it in an attempt to support you. Please ask this to their support forum.
with which function can I get the Text of Json like a string in this example: I want to get the texts like this: "NOTHING EXISTS"
Here is how you could do it:
const obj = {
textAngle: 0,
regions: [
{
boundingBox: "21,16,304,451",
lines: [
{
boundingBox: "28,16,288,41",
words: [
{
boundingBox: "28,16,288,41",
text: "NOTHING"
}
]
},
{
boundingBox: "27,66,283,52",
words: [
{
boundingBox: "27,66,283,52",
text: "EXISTS"
}
]
}
]
}
]
}
let buf = ''
obj.regions.forEach((a, b, c) => {
a.lines.forEach((p, q, r) => {
p.words.forEach((x, y, z) => {
buf += ` ${x.text}`
})
})
})
console.log(buf)
NOTHING EXISTS #
Hope this helps!
thanks for your response, i tried it with my code but why i am getting this error in your opinion ? the error is cannot read property 'forEach ' of undefined app.js 41:13 obj.regions.forEach(a,b,c) => { this is my code looks like: ''use strict';
const request = require('request');
// Replace
const imageUrl = 'https://i.pinimg.com/originals/c3/cc/b2/c3ccb2dee31874b2ba8c9e0a35d4f1b6.jpg';
// Request parameters. const params = { 'language': 'unk', 'detectOrientation': 'true', };
const options = { uri: uriBase, qs: params, body: '{"url": ' + '"' + imageUrl + '"}', headers: { 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key' : subscriptionKey } };
request.post(options, (error, response, body) => { if (error) { console.log('Error: ', error); return; }
const obj = JSON.stringify(JSON.parse(body), null, ' ');
//------------ get the texts from json as string
let buf = ''
obj.regions.forEach((a, b, c) => {
a.lines.forEach((p, q, r) => {
p.words.forEach((x, y, z) => {
buf += ${x.text}
})
})
})
console.log(buf) //------------- console.log('JSON Response\n');
});'
you will need to perform nullchecks. That is, for each object, make sure it is not null before accessing its members. So the snippet will change to:
if(obj && obj.regions) {
obj.regions.forEach((a, b, c) => {
if(a && a.lines) {
a.lines.forEach((p, q, r) => {
if(p && p.words) {
p.words.forEach((x, y, z) => {
buf += ` ${x.text}`
})
}
})
}
})
}
thank you very much. i am going to close this issue. you helped me too much. I will open another issue for another code. i hope you have time to answer on it. thanks again.
Hello,
i am trying to Demonstration a sample but i am get always this error { "statusCode : 404" "messeges : resource not found"}
can anybody help me please, the code looks like this: ''use strict';
const request = require('request');
// Replace with your valid subscription key.
'use strict';
const subscriptionKey = '7***';
// You must use the same location in your REST call as you used to get your // subscription keys. For example, if you got your subscription keys from // westus, replace "westcentralus" in the URL below with "westus".
const uriBase = 'https://westcentralus.api.cognitive.microsoft.com/vision/v1.0';
const imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/thumb/a/af/Atomist_quote_from_Democritus.png/338px-Atomist_quote_from_Democritus.png';
// Request parameters. const params = { 'language': 'unk', 'detectOrientation': 'true', };
const options = { uri: uriBase, qs: params, body: '{"url": ' + '"' + imageUrl + '"}', headers: { 'Content-Type': 'application/json', 'Ocp-Apim-Subscription-Key' : subscriptionKey } };
request.post(options, (error, response, body) => { if (error) { console.log('Error: ', error); return; } let jsonResponse = JSON.stringify(JSON.parse(body), null, ' '); console.log('JSON Response\n'); console.log(jsonResponse); });'