error_code" : 216201,
低首看云 发布于2018-05 浏览:2526 回复:5
0
收藏
图片试了.jpeg .jpg 的都出错
error_code" : 216201,
"error_msg" : "image format error",
 
请问大佬这是什么原因
下面贴代码:

/*
* main.cpp
*
*/

#include "src/TableOcr.h"

using namespace check_table;

int main(){
TableOcr ocr;
ocr.LoadImg("gray.bmp");
ocr.Display();
}

 

/*
* TableOrc.h
*
* Created on: 2018年5月14日
*/

#ifndef SRC_TABLEOCR_H_
#define SRC_TABLEOCR_H_

#include
#include

namespace check_table {

class TableOcr {
public:
TableOcr();
virtual ~TableOcr();
public:
void LoadImg(std::string const & image);
void Reset();
void Display();

private:
Json::Value m_result;
void* m_client;
static std::string m_app_id;
static std::string m_api_key;
static std::string m_secret_key;
};

} /* namespace check_table */

#endif /* SRC_TABLEOCR_H_ */

 

 

/*
* TableOrc.cpp
*
* Created on: 2018年5月14日
*/

#include "TableOcr.h"
#include "../header/ocr.h"
namespace check_table {

#define ORC_PTR(x) ((aip::Ocr*)x)

std::string TableOcr::m_app_id = "11233511";
std::string TableOcr::m_api_key = "iaSERAArMqIiRmRgQfXx3Pnc";
std::string TableOcr::m_secret_key = "SpjdUjFNXkIAW5QQnaenySlwcZPG964P";

TableOcr::TableOcr() {
// TODO Auto-generated constructor stub
m_result.clear();
m_client = new aip::Ocr(m_app_id, m_api_key, m_secret_key);
}

void TableOcr::LoadImg(std::string const & image){
std::string img;
if(aip::get_file_content(image.c_str(), &img)){
std::cout << img << std::endl;
return ;
}
// 如果有可选参数
std::map options;
options["language_type"] = "CHN_ENG";
options["detect_direction"] = "true";
options["detect_language"] = "true";
options["probability"] = "true";
// 调用通用文字识别(含位置信息版), 图片参数为本地图片
m_result = ORC_PTR(m_client)->general(image, options);
}
void TableOcr::Display(){
std::cout << m_result << std::endl;
}

void TableOcr::Reset(){
m_result.clear();
}
TableOcr::~TableOcr() {
// TODO Auto-generated destructor stub
m_result.clear();
if(m_client){
ORC_PTR(m_client)->~Ocr();
m_client = NULL;
}
}

} /* namespace check_table */

 

 
收藏
点赞
0
个赞
共5条回复 最后由用户已被禁言回复于2022-04
#6低首看云回复于2018-05
#2 用户已被禁言回复
建议发帖把代码放在代码块里面 有可能是base64导致的

谢谢,问题已解决!

m_result = ORC_PTR(m_client)->general(image, options);

这里调用接口的时候,错把文件名字符串image传进去了。应该文件被传读取并base64编码后的字符串。

0
#5低首看云回复于2018-05

谢谢,问题已解决!

m_result = ORC_PTR(m_client)->general(image, options);

这里调用接口的时候,错把文件名字符串image传进去了。应该文件被传读取并base64编码后的字符串。

0
#4低首看云回复于2018-05

谢谢,问题已解决!

m_result = ORC_PTR(m_client)->general(image, options);

这里调用接口的时候,错把文件名字符串image传进去了。应该文件被传读取并base64编码后的字符串。

 

0
#3低首看云回复于2018-05

谢谢,问题已解决!

m_result = ORC_PTR(m_client)->general(image, options);

这里调用接口的时候,错把文件名字符串image传进去了。应该文件被传读取并base64编码后的字符串。

 

0
#2用户已被禁言回复于2018-05

建议发帖把代码放在代码块里面

有可能是base64导致的

1
TOP
切换版块