先上图,有图有真相

  首先在百度开通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. 洛谷-P3927 SAC E#1 - 一道中档题 Factorial

    原址 题目背景 数据已修改 SOL君(炉石主播)和SOL菌(完美信息教室讲师)是好朋友. 题目描述 SOL君很喜欢阶乘.而SOL菌很喜欢研究进制. 这一天,SOL君跟SOL菌炫技,随口算出了n的阶乘. ...

  2. c#基础2-out-ref

    //out参数要求在方法的内部 ; JiangJin(ref salary1); Console.WriteLine(salary1); Console.ReadKey(); 必须为其赋值 out.r ...

  3. @PropertySource

    功能 加载指定的属性文件(*.properties)到 Spring 的 Environment 中.可以配合 @Value 和 @ConfigurationProperties 使用. @Prope ...

  4. AJPFX辨析GBK和UTF8的区别

    GBK编码:是指中国的中文字符,其它它包含了简体中文与繁体中文字符,另外还有一种字符“gb2312”,这种字符仅能存储简体中文字符. UTF-8编码:它是一种全国家通过的一种编码,如果你的网站涉及到多 ...

  5. 装饰者模式及php实现

    装饰模式(Decorator Pattern) : 动态地给一个对象增加一些额外的职责(Responsibility),就增加对象功能来说,装饰模式比生成子类实现更为灵活.其别名也可以称为包装器(Wr ...

  6. JavaScirpt 的垃圾(garbage collection)回收机制

    一.垃圾回收机制—GC Javascript具有自动垃圾回收机制(GC:Garbage Collecation),也就是说,执行环境会负责管理代码执行过程中使用的内存. 原理:垃圾收集器会定期(周期性 ...

  7. 草根程序员如何进入BAT

        首页 最新文章 IT 职场 前端 后端 移动端 数据库 运维 其他技术 - 导航条 - 首页 最新文章 IT 职场 前端 - JavaScript - HTML5 - CSS 后端 - Pyt ...

  8. 变更gcc版本

    当前的GCC版本为GCC-4.2,需要切换到GCC-3.4.首先,你需要去你的usr/bin/下去看看有没有gcc-3.4这样文件,如果没有的话,就安装一下吧: apt-get install gcc ...

  9. python+selenium之验证码的处理

    对于web应用来说,大部分的系统在用户登录时都要求用户输入验证码.验证码的类型很多,有字母数字的,有汉字的.甚至还有需要用户输入一道算术题的答案的.对于系统来说,使用验证码可以有效地防止采用机器猜测方 ...

  10. 这些O2O比你们更靠谱儿

    本文纯属虚构,如有雷同,全是 C2C(Copy to China). 一 「什么社区 O2O,不就是跑腿儿的?那叮*小区不好好跑腿儿,非要搞什么狗屁社交,不是死了?」 三十四岁的老刘咽了口唾沫,接着跟 ...