Google Cloud Vision API : “error code: 3” , “message”: “Bad image data.”

不问归期 提交于 2019-12-11 15:19:59

问题


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."
         }
      }
   ]
}

My curl POST field is a JSON string like this:

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

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


回答1:


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);


来源:https://stackoverflow.com/questions/51735897/google-cloud-vision-api-error-code-3-message-bad-image-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!