百度文字识别

    OCR.getInstance(this).initAccessTokenWithAkSk(new OnResultListener<AccessToken>() {
        @Override
        public void onResult(AccessToken result) {
            // 调用成功,返回AccessToken对象
            String token = result.getAccessToken();
        }
        @Override
        public void onError(OCRError error) {
            // 调用失败,返回OCRError子类SDKError对象
        }
    }, getApplicationContext(), "Sg1BqTHgMjKyj7xgHMR7GncL", "fgILC2g9RHYuh7Sbf9BrXpgQMUzEeup3");
    OCR.getInstance(this).initAccessToken(new OnResultListener<AccessToken>() {
        @Override
        public void onResult(AccessToken result) {
            // 调用成功,返回AccessToken对象
            String token = result.getAccessToken();
        }
        @Override
        public void onError(OCRError error) {
            // 调用失败,返回OCRError子类SDKError对象
        }
    }, getApplicationContext());




@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
            case PictureConfig.CHOOSE_REQUEST:
                List<LocalMedia> selectList = PictureSelector.obtainMultipleResult(data);
                LocalMedia media = selectList.get(0);
                String path = media.getCompressPath();
                //5. 显示到界面
                RequestOptions options = new RequestOptions()
                        .transform(new GlideRoundTransform())
                        .error(R.mipmap.head_doctor)
                        .dontAnimate()
                        .priority(Priority.HIGH);
                // 生成intent对象
                // 通用文字识别参数设置
                GeneralBasicParams param = new GeneralBasicParams();
                param.setDetectDirection(true);
                param.setImageFile(new File(path));

// 调用通用文字识别服务
OCR.getInstance(this).recognizeGeneralBasic(param, new OnResultListener() {
@Override
public void onResult(GeneralResult result) {
// 调用成功,返回GeneralResult对象
for (WordSimple wordSimple : result.getWordList()) {
// wordSimple不包含位置信息
MyToastUtil.show(wordSimple.getWords().toString());
}
// json格式返回字符串
MyToastUtil.show(result.getJsonRes().toString());
}
@Override
public void onError(OCRError error) {
// 调用失败,返回OCRError对象
}
});
break;
}
}
}

©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页