我正在尝试使用 Google Vision API 检测文本,但 JSON 响应为空
我用 RADSutdio 10.3 构建了一个 Windows VCL C++ Builder 应用程序,它选择一个现有图像,将其转换为 BASE64 字符串并将其作为图像内容发送,如下所示:
{
"requests": [
{
"image": {
"content": "BASE64_ENCODED_IMAGE"
},
"features": [
{
"type": "TEXT_DETECTION"
}
]
}
]
}
我正在使用 RESTClient、RESTRequest 和 RESTResponse 组件来实现这一点。它工作得很好,我得到了响应并根据需要对其进行操作。
当我尝试使用带有 RADStudio 10.4 的 Android 32 位多设备表单复制此问题时,我得到了 200 状态代码,但我的响应是:
{}
这是我的代码:
String json1="{\"requests\":[{\"image\":{\"content\":\""+BASE64_ENCODED_IMAGE+"\"},\"features\":[{\"type\":\"TEXT_DETECTION\"}]}]}";
RESTClient1->ResetToDefaults();
RESTClient1->Accept = "application/json, text/plain; q=0.9, text/html;q=0.8,";
RESTClient1->AcceptCharset = "UTF-8, *;q=0.8";
RESTClient1->BaseURL = "https://vision.googleapis.com";
RESTClient1->HandleRedirects = true;
RESTClient1->RaiseExceptionOn500 = false;
String APIkey = "MY_APIKEY";
RESTRequest2->Resource = "v1/images:annotate?key=" + APIkey;
RESTRequest2->Client = RESTClient1;
RESTRequest2->Response = RESTResponse1;
RESTRequest2->SynchronizedEvents = false;
RESTResponse1->ContentType = "application/json";
RESTRequest2->Params->AddItem();
RESTRequest2->Params->Items[0]->Value = json1;
RESTResponse1->RootElement = "responses[0].textAnnotations[0]";
RESTRequest2->Execute();