先上图,有图有真相

  首先在百度开通ORC服务,目前是免费的,普通识别每天50000次免费,非常棒!

百度文档:http://ai.baidu.com/docs#/OCR-API/top

  下载百度SDK神马的就不多说了,需要包含CURL和JSON库,注意版本要求

  windows下的openssl 32位和64位一键安装包顺便分享下,自己安装太麻烦

  链接:https://pan.baidu.com/s/1HAuplB3deQGFk2eO8zC13A
  提取码:mh34

  CURL和JSON库就不贴出来了,网上随便都能找到,需要的朋友可以找我,我私发给你。

  接下来进入正题,贴代码:

ImageRecogition.h

 #pragma once

 #include "json/json.h"

 class CImageRecogition
{
public:
CImageRecogition();
~CImageRecogition(); public:
/*accurate_basic*/
Json::Value static accurate_basic(std::string szFile);
/*general_basic*/
Json::Value static general_basic(std::string szFile);
/*general_enhanced*/
Json::Value static general_enhanced(std::string szFile);
/*receipt*/
Json::Value static receipt(std::string szFile);
/*custom*/
Json::Value static custom(std::string szFile); /*save result to file*/
void static SaveResultToFile(Json::Value & result, std::string szFile);
private:
};

ImageRecogition.cpp

#include "stdafx.h"
#include "ImageRecogition.h" #include "baiduapi/ocr.h" #define APP_ID "xxxxxxx"
#define API_KEY "xxxxxxx"
#define SECRET_KEY "xxxxx" CImageRecogition::CImageRecogition()
{ } CImageRecogition::~CImageRecogition()
{ } Json::Value CImageRecogition::accurate_basic(std::string szFile)
{
aip::Ocr client(APP_ID, API_KEY, SECRET_KEY); std::string image;
aip::get_file_content(szFile.c_str(), &image);
std::map<std::string, std::string> options;
options["detect_direction"] = "true";
options["probability"] = "true"; std::cout << "高精识别开始:";
return client.accurate_basic(image, options);
} Json::Value CImageRecogition::general_basic(std::string szFile)
{
aip::Ocr client(APP_ID, API_KEY, SECRET_KEY); std::string image;
aip::get_file_content(szFile.c_str(), &image);
std::map<std::string, std::string> options;
//options["language_type"] = "KOR";
options["detect_direction"] = "true";
options["detect_language"] = "true";
options["probability"] = "true"; std::cout << "普通识别开始:";
return client.general_basic(image, options);
} Json::Value CImageRecogition::general_enhanced(std::string szFile)
{
aip::Ocr client(APP_ID, API_KEY, SECRET_KEY); std::string image;
aip::get_file_content(szFile.c_str(), &image);
std::map<std::string, std::string> options;
//options["language_type"] = "KOR";
options["detect_direction"] = "true";
options["detect_language"] = "true";
options["probability"] = "true"; std::cout << "生僻字识别开始:";
return client.general_enhanced(image, options);
} Json::Value CImageRecogition::receipt(std::string szFile)
{
aip::Ocr client(APP_ID, API_KEY, SECRET_KEY); std::string image;
aip::get_file_content(szFile.c_str(), &image);
std::map<std::string, std::string> options;
//options["recognize_granularity"] = "small";
options["probability"] = "true";
//options["accuracy"] = "normal";
options["detect_direction"] = "true"; std::cout << "通用票据识别开始:";
return client.receipt(image, options);
} Json::Value CImageRecogition::custom(std::string szFile)
{
aip::Ocr client(APP_ID, API_KEY, SECRET_KEY); std::string image;
aip::get_file_content(szFile.c_str(), &image);
std::map<std::string, std::string> options;
std::string templateSign = "354b9b4fd9b0e4b38aedb8096260c6de"; std::cout << "自定义模板识别开始:";
return client.custom(image, templateSign, options);
} void CImageRecogition::SaveResultToFile(Json::Value & result, std::string szFile)
{
FILE* fp = nullptr;
auto error_no = fopen_s(&fp, szFile.c_str(), "a+");
if (fp != nullptr)
{
fprintf_s(fp, "==============================================================================\n");
SYSTEMTIME st;
::GetLocalTime(&st);
fprintf_s(fp, "%04d-%02d-%02d %02d:%02d:%02d\n", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
fprintf_s(fp, "log_id : %d\n", result["log_id"].asInt64()); auto result_num = result["words_result"].size(); if (result_num > )
std::cout << "识别成功,识别行数:" << result_num << std::endl;
else
std::cout << "识别失败,未识别数据" << std::endl; for (int i = ; i < result_num; ++i)
fprintf_s(fp, "%s\n", result["words_result"][i]["words"].asString().c_str()); fprintf_s(fp, "==============================================================================\n");
fprintf_s(fp, "\n");
fclose(fp);
}
}
 

然后就是main函数的调用了

#include "stdafx.h"
#include <iostream> #include "ServiceLogic/ImageRecogition.h"
#include "curl/curl.h"
#include "DirFile/DirFile.h" int _tmain(int argc, char* argv[])
{
std::vector<std::string> vecFiles;
DirFile::ListFiles(".", vecFiles, FILETYPE_JPG | FILETYPE_PNG | FILETYPE_JPEG);
for (auto it : vecFiles)
{
std::cout << it << std::endl;
std::string szFileName = it.substr(, it.rfind("."));
std::string szPath = "./Log_" + szFileName + "/";
DirFile::CreatePath(szPath); //CImageRecogition::SaveResultToFile(CImageRecogition::accurate_basic(it), szPath + "accurate_basic.log");
CImageRecogition::SaveResultToFile(CImageRecogition::general_basic(it), szPath + "general_basic.log");
//CImageRecogition::SaveResultToFile(CImageRecogition::general_enhanced(it), szPath + "general_enhanced.log");
//CImageRecogition::SaveResultToFile(CImageRecogition::receipt(it), szPath + "receipt.log");
//CImageRecogition::SaveResultToFile(CImageRecogition::custom(it), szPath + "custom.log");
} system("pause");
return ;
}

 DirFile.h是遍历当前目录下对应格式的文件,以及Log目录的创建的,这里就不贴出来了,毕竟不是这次的主题。

 百度ORC的识别率,对图片要求还是比较高的,本人给朝鲜族的朋友测试韩文的发票,效果还是挺差强人意的。看大家的需求吧。

基于百度OCR的图片文字识别的更多相关文章

  1. 【图片识别】java 图片文字识别 ocr (转)

    http://www.cnblogs.com/inkflower/p/6642264.html 最近在开发的时候需要识别图片中的一些文字,网上找了相关资料之后,发现google有一个离线的工具,以下为 ...

  2. java 图片文字识别 ocr

    最近在开发的时候需要识别图片中的一些文字,网上找了相关资料之后,发现google有一个离线的工具,以下为java使用的demo 在此之前,使用这个工具需要在本地安装OCR工具: 下面一个是一定要安装的 ...

  3. 一篇文章搞定百度OCR图片文字识别API

    一篇文章搞定百度OCR图片文字识别API https://www.jianshu.com/p/7905d3b12104

  4. 小试Office OneNote 2010的图片文字识别功能(OCR)

    原文:小试Office OneNote 2010的图片文字识别功能(OCR) 自Office 2003以来,OneNote就成为了我电脑中必不可少的软件,它集各种创新功能于一身,可方便的记录下各种类型 ...

  5. 【原】Coursera—Andrew Ng机器学习—课程笔记 Lecture 18—Photo OCR 应用实例:图片文字识别

    Lecture 18—Photo OCR 应用实例:图片文字识别 18.1 问题描述和流程图 Problem Description and Pipeline 图像文字识别需要如下步骤: 1.文字侦测 ...

  6. [C13] 应用实例:图片文字识别(Application Example: Photo OCR)

    应用实例:图片文字识别(Application Example: Photo OCR) 问题描述和流程图(Problem Description and Pipeline) 图像文字识别应用所作的事是 ...

  7. python3 图片文字识别

    最近用到了图片文字识别这个功能,从网上搜查了一下,决定利用百度的文字识别接口.通过测试发现文字识别率还可以.下面就测试过程简要说明一下 1.注册用户 链接:https://login.bce.baid ...

  8. 刚破了潘金莲的身份信息(图片文字识别),win7、win10实测可用(免费下载)

    刚破了潘金莲的身份信息(图片文字识别),win7.win10实测可用 效果如下: 证照,车牌.身份证.名片.营业执照 等图片文字均可识别 电脑版 本人出品 大小1.3MB 下载地址:https://p ...

  9. Python人工智能之图片识别,Python3一行代码实现图片文字识别

    1.Python人工智能之图片识别,Python3一行代码实现图片文字识别 2.tesseract-ocr安装包和中文语言包 注意:

随机推荐

  1. 一起来学Spring Cloud | 第四章:服务消费者 ( Feign )

    上一章节,讲解了SpringCloud如何通过RestTemplate+Ribbon去负载均衡消费服务,本章主要讲述如何通过Feign去消费服务. 一.Feign 简介: Feign是一个便利的res ...

  2. 【转】monkey实战--测试步骤、常用参数、常规monkey命令

    monkey实战--测试步骤.常用参数.常规monkey命令   简要步骤:adb devices---了解包名--adb shell monkey -p 包名 -v 运行次数(多个参数的组合形成不同 ...

  3. 常用API(正则表达式、Date、DateFormat、Calendar)

    常用API 今日内容介绍 u 正则表达式 u Date u DateFormat u Calendar 第1章 正则表达式 1.1 正则表达式的概念 正则表达式(英语:Regular Expressi ...

  4. spring Cloud中,解决Feign/Ribbon整合Hystrix第一次请求失败的问题?

    Spring Cloud中,Feign和Ribbon在整合了Hystrix后,可能会出现首次调用失败的问题,要如何解决该问题呢? 造成该问题的原因 Hystrix默认的超时时间是1秒,如果超过这个时间 ...

  5. JavaScript中三种字符串连接方式及其性能比较

    参考地址: https://www.cnblogs.com/programs/p/5554742.html 工作中经常会碰到要把2个或多个字符串连接成一个字符串的问题,在JS中处理这类问题一般有三种方 ...

  6. iOS开发 - Protocol协议及委托代理(Delegate)

    因为Object-C是不支持多继承的,所以很多时候都是用Protocol(协议)来代替.Protocol(协议)只能定义公用的一套接口,但不能提供具体的实现方法.也就是说,它只告诉你要做什么,但具体怎 ...

  7. Android 开发干货,键盘状态

    地址:http://www.imooc.com/article/4711 [A]stateUnspecified:软键盘的状态并没有指定,系统将选择一个合适的状态或依赖于主题的设置 [B]stateU ...

  8. Jquery 事件 DOM操作

    常规事件: 把JS的事件  on去掉即可 例如:js    document.getElementById("id").onclinck=function(){} Jquery   ...

  9. 简单案列完美搞定Mvc设计模式

    一个小列子搞定Mvc模式,包括数据库以及如何提高用户体验度 1.首先来web.xml配置servlet的访问路径: <?xml version="1.0" encoding= ...

  10. miniLCD12864 16引脚

    显示图片 main.c #include<reg51.h>#include"st7565.h"//---存一个图片--//unsigned char code pic[ ...