先上图,有图有真相

  首先在百度开通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. 在IDEA中编辑struts国际化properties文件

    在IDEA中编辑struts国际化properties文件 如果手工创建的web工程,struts的i18n属性文件,可以使用native2ascii工具转换(记得命令行的第二个文件名是要保存的文件名 ...

  2. countUp 动画展示数字变化

    html <p id="countUp" style="font-size:25px;height:25px;background-color:#0aa;" ...

  3. LR脚本示例之常用函数

    1.变量和参数的设置 //将IP地址和端口放入到参数中lr_save_string("127.0.0.1:1080","ip"); //退出脚本建议使用lr_e ...

  4. HDU 1847 Good Luck in CET-4 Everybody! 四级好运!(博弈)

    思路:先用P/N状态来找规律. N状态:1 2 4 6 8 16 P状态:3 5 因为3=1+2, 无论拿1或者2皆输.看看5,只要抽掉2就变成了3,所以是N状态.看看6,可以抽掉1 2 4,若抽1, ...

  5. (转)在SQL Server 2016,Visual Studio 2017环境下,连接数据库屡屡失败,在connectionString上出的问题

    适用情景: 1,ServerVersion出了问题,“SqlCnt.ServerVersion”引发了类型“System.InvalidOperationException”的异常 2,在String ...

  6. 【UML】对象图Object diagram(转)

    http://blog.csdn.net/sds15732622190/article/details/48894751 前言 今天要说的是UML中的对象图.他与类图,合作图都有关系,是类图的实例化. ...

  7. [dp uestc oj] G - 邱老师玩游戏

    G - 邱老师玩游戏 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  8. ctrl+shift+f

    ctrl+f是在当前文件寻找某个参数 ctrl+shift+f是在整个工程目录下寻找某个参数

  9. 安装JDK1.8以及配置环境变量的步骤

    一. 首先到官网下载jdk1.8,下载的版本分为windows和linux,这里需要安装操作系统进行下载.我的是64位就下载x64,32位系统则下载x86 二. 然后就是安装,双击进行安装,这里不用更 ...

  10. 01_1JAVA简介

    01_1JAVA简介 1. Java基础 语法基础.OO.Exception.Array.基础类.I/O Stream.Collection /Generic.Thread.TCP/UDP.GUI.M ...