先上图,有图有真相

  首先在百度开通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. 疯狂使用 leancloud (投稿文章)

    疯狂使用 leancloud 本文章是投稿文章,已在 leancloud 微信公众号发表. 这里是原文,内容有调整. 3年,从工程师到创始人 觉得不错可以点这里进行 leancloud 注册 项目背景 ...

  2. AJPFX关于Java中的集合

    ava API中所用的集合类,都是实现了Collection接口,他的一个类继承结构如下: Collection<--List<--Vector Collection<--List& ...

  3. Redis list(列表)

    Redis列表是简单的字符串列表,列表是有序的,列表中的元素可以重复. 可以添加一个元素到列表的头部(左边)或者尾部(右边) 一个列表最多可以包含 232 - 1 个元素 (40多亿). 1.lpus ...

  4. centos 离线安装 mysql 5.7

    1 . 安装新版mysql前,需将系统自带的mariadb-lib卸载. rpm -qa|grep mariadb mariadb-libs--.el7.centos.x86_64 rpm -e -- ...

  5. 判断JS数据类型的几种方法

    原文转自http://www.cnblogs.com/onepixel/p/5126046.html! 说到数据类型,我们先说一下JavaScript 中常见的几种数据类型: 基本类型:string, ...

  6. robotframework介绍

    1.测试用例使用文本文件(TXT或者TSV文件)保存,使用制表符分隔数据.可以方便的使用任何文本编辑器,或者EXCEL编辑测试用例.也可以使用HTML格式创建用例.2.测试用例中支持变量使用,可以使用 ...

  7. 51nod 1101 换零钱

    基准时间限制:1 秒 空间限制:131072 KB 分值: 20 难度:3级算法题 N元钱换为零钱,有多少不同的换法?币值包括1 2 5分,1 2 5角,1 2 5 10 20 50 100元.   ...

  8. C#链接mysql 新手容易出错的问题

    1.Access denied for user 'root'@'DESKTOP-AN72KEI' (using password: YES) 出现这个问题的原因是因为mysql的自带用户root理论 ...

  9. HDU 5489 Removed Interval 2015 ACM/ICPC Asia Regional Hefei Online (LIS变形)

    定义f[i]表示以i为开头往后的最长上升子序列,d[i]表示以i为结尾的最长上升子序列. 先nlogn算出f[i], 从i-L开始枚举f[i],表示假设i在最终的LIS中,往[0,i-L)里找到满足a ...

  10. 3. Netbackup 7.6客户端的安装(windows/linux)

    1 客户端的安装 1.1 Windows客户端安装 1.1.1 客户端hosts修改 windows xp/2003/vista/2008/7/8用户HOSTS文件是在“c:\windows\syst ...