推广 热搜:   企业  系统  中国  行业  公司  教师  设备    服务 

基于百度OCR的图片文字识别

   日期:2024-12-06     浏览:95    移动:http://xiaoguoguo.dbeile.cn/mobile/quote/3075.html
#include "stdafx.h"

基于百度OCR的图片文字识别

#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); } }
 
本文地址:http://xiaoguoguo.dbeile.cn/quote/3075.html    多贝乐 http://xiaoguoguo.dbeile.cn/ , 查看更多

特别提示:本信息由相关企业自行提供,真实性未证实,仅供参考。请谨慎采用,风险自负。


相关行业动态
推荐行业动态
点击排行
网站首页  |  关于我们  |  联系方式  |  使用协议  |  版权隐私  |  网站地图  |  排名推广  |  广告服务  |  积分换礼  |  网站留言  |  RSS订阅  |  违规举报  |  鄂ICP备2023001713号