百度ocr文字识别编码时遇到的错误
来源:互联网 发布:通江集团 知乎 编辑:程序博客网 时间:2024/06/05 10:13
最近在做项目是遇到百度ocr文字识别编码时的错误,搜索好久,不见有效解决方案,故在解决后记了下来。。。。
首先一定是去看文档了http://apistore.baidu.com/apiworks/servicedetail/969.html。
可是当你去设置imageType这个参数时,你发现文档是这么写的 图片资源类型, 1.表示经过BASE64编码后的字串,然后需要经过urlencode处理(特别重要);2.图片原文件 3. 图片URl类型,此时image中填写图片所在位置。而我需要用type为1时,那么image这个参数需要传什么。经过反复多次试验,根部不需要urlencode处理,只需要对bitmap做base64编码就可以了。而且只支持jpg格式的图片。这是一个很大的坑。。。
最后附上部分代码:
//对bitmap做base64处理
public static String convertIconToString(Bitmap bitmap){
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.PNG, 100, baos);
byte[] appicon = baos.toByteArray();// 转为byte数组
return Base64.encodeToString(appicon, Base64.NO_WRAP);//注意这Base64.NO_WRAP参数很重要,一定是它。去除空格
}
//请求百度ocr接口
@SuppressWarnings("unchecked")
private void request() {
Bitmap bm = ((BitmapDrawable)mImageView.getDrawable()).getBitmap();
String image = convertIconToString(bm);
Parameters para = new Parameters();
para.put("fromdevice", "pc");
para.put("clientip", "10.10.10.0");
para.put("detecttype", "LocateRecognize");
para.put("languagetype", "CHN_ENG");
para.put("imagetype", "1");
para.put("image", image);
para.put("version", "v1");
para.put("sizetype", "small");
ApiStoreSDK.execute(httpUrl,ApiStoreSDK.POST,para,
new ApiCallBack(){
@Override
public void onSuccess(int status, String responseString) {
tv.setText(responseString);
Log.d("sdkdemo", responseString);
Intent intent = new Intent(getApplicationContext(),ResearchActivity.class);
intent.putExtra("result", responseString);
startActivity(intent);
}
@Override
public void onComplete() {
}
@Override
public void onError(int arg0, String arg1, Exception e) {
Log.i("sdkdemo", "errMsg: " + (e == null ? "" : e.getMessage()));
//@pokerWU
// TODO: 17-1-8 for test <code></code>
Intent intent = new Intent(getApplicationContext(),ResearchActivity.class);
intent.putExtra("result", "");
startActivity(intent);
}
});
}
- 百度ocr文字识别编码时遇到的错误
- 百度OCR文字识别的小例子
- 百度OCR文字识别PHP的Demo
- 百度OCR文字识别-身份证识别
- 用百度AI的OCR文字识别结合PHP实现了图片的文字识别功能
- JAVA实现百度OCR文字识别功能
- JAVA实现百度OCR文字识别功能
- android的文字识别OCR
- 利用百度OCR的node.js的接口实现文字识别的功能
- PHP:基于百度大脑api实现OCR文字识别
- 阿里 旷视 百度 OCR图片文字识别功能对比
- 最简单的屏幕OCR文字识别
- 最简单的屏幕OCR文字识别
- 最简单的屏幕OCR文字识别
- 最简单的屏幕OCR文字识别
- OCR文字识别软件的最佳选择
- OCR文字识别软件的最佳选择
- OCR文字识别
- angularjs ngdocs 使用grunt生成api文档说明
- 17 - 02 - 28 图解HTTP(02)
- Text Kit进阶
- vtkDelaunay2D - 三角剖分面
- nodeJs+express+mongoDB开发个人博客
- 百度ocr文字识别编码时遇到的错误
- Unity 编辑器开发 知识点 持续更新
- 系统学习机器学习之神经网络(十) --BAM网络
- ipynb文件打开方式
- MyBatis入门实例
- servlet教程
- windows socket 客户端
- tableView为UITableViewStyleGrouped时,组与组之间会有一点间隙
- POI使用:用poi接口不区分xls/xlsx格式解析Excel文档(41种日期格式解析方法,5种公式结果类型解析方法,3种常用数值类型精度控制办法)