#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, "============================================================================== "); SYSTEMTIME st; ::GetLocalTime(&st); fprintf_s(fp, "%04d-%02d-%02d %02d:%02d:%02d ", st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond); fprintf_s(fp, "log_id : %d ", result["log_id"].asInt64()); auto result_num = result["words_result"].size(); if (result_num > 0) std::cout << "识别成功,识别行数:" << result_num << std::endl; else std::cout << "识别失败,未识别数据" << std::endl; for (int i = 0; i < result_num; ++i) fprintf_s(fp, "%s ", result["words_result"][i]["words"].asString().c_str()); fprintf_s(fp, "============================================================================== "); fprintf_s(fp, " "); fclose(fp); } }
以上就是本篇文章【基于百度OCR的图片文字识别】的全部内容了,欢迎阅览 ! 文章地址:http://xiaoguoguo.dbeile.cn/quote/3075.html
行业
资讯
企业新闻
行情
企业黄页
同类资讯
网站地图
返回首页 多贝乐移动站 http://xiaoguoguo.dbeile.cn/mobile/ , 查看更多