问题
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