Google Cloud Vision API:“错误代码:3"; ,“消息":“错误的图像数据". [英] Google Cloud Vision API : "error code: 3" , "message": "Bad image data."

查看:181
本文介绍了Google Cloud Vision API:“错误代码:3"; ,“消息":“错误的图像数据".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发布HTTP请求,以检测从Mat图像转换为base64的图像中的文本.运行代码时,我得到

I am trying to POST HTTP request to Detect Text in images converted to base64 from mat image. When I run the code, I get

{
   "responses":[
      {
         "error":{
            "code":3,
            "message":"Bad image data."
         }
      }
   ]
}

我的curl POST字段是这样的JSON字符串:

My curl POST field is a JSON string like this:

{
   "requests":[
      {
         "image":{
            "content":"lZ+elp+elp+elp+elZ+elZ6dlZ6dlZ6dlJ6dlJ2ck52ck52ck52ck52ck52bk5ybkpyakpyakpyakZuZkJqYj5m...........srW0srWzsrWzsrWzsrWz"
         },
         "features":[
            {
               "type":"TEXT_DETECTION"
            }
         ]
      }
   ]
}

我不确定base64编码的图像是否有效.请帮忙!

I am not sure if the base64 encoded image is valid. Please help !

推荐答案

我已经找到了通过将Mat对象转换为向量然后进行编码的解决方案.

I have found a solution by converting the Mat object into vector and then encode.

std::vector<uchar> array;
cv::imencode(".png",mat_img, array);


std::string encoded = Base64::encode(array);

这篇关于Google Cloud Vision API:“错误代码:3"; ,“消息":“错误的图像数据".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆