银行卡的数字检測
发布日期:2021-06-24 18:20:41 浏览次数:2 分类:技术文章

本文共 1487 字,大约阅读时间需要 4 分钟。

业余瞎搞。废话少说。上代码:

#pragma comment(lib, "libtesseract302.lib")#pragma comment(lib, "liblept.lib")#include 
#include
#include
#include
#include
#include
using namespace std;cv::Mat image;string windowsname = "image";void OnTracker(int thres, void *user){ cv::threshold(image, image, thres, 2.5*thres,CV_THRESH_BINARY); cv::imshow(windowsname, image); tesseract::TessBaseAPI api; api.Init(NULL, "eng", tesseract::OEM_DEFAULT); //识别英文 api.SetVariable( "tessedit_char_whitelist", "0123456789");//限制识别字符范围 api.SetImage(image.data,image.cols, image.rows, image.channels(), image.step); if (0==api.Recognize(NULL)) { STRING str = api.GetUTF8Text(); printf(str.string()); string strtemp = str.string(); while (1) { int k = strtemp.find_first_of(' '); if (k<0||k>=strtemp.length()) { break; } strtemp.erase(k,1); } cout << strtemp << endl; while(1) { int k = strtemp.find_first_of('\n'); if (k<0||k>=strtemp.length()) { break; } string temp = strtemp.substr(0,k); cout << temp << endl; if (temp.length() > 14) { cout << "the card numbers is :" << temp << endl;; break; } strtemp.erase(0,k+1); } }}int main(){ cv::namedWindow("image", 1); image = cv::imread("test.jpg"); cv::cvtColor(image, image, CV_RGB2GRAY); int thres = 100; cv::createTrackbar("thres:", "image", &thres, 255, OnTracker); cv::imshow(windowsname, image); cv::waitKey(0); return 0;}

检測结果例如以下:

对数字3和8偶尔会出现检測不准确的现象

转载地址:https://blog.csdn.net/weixin_34248258/article/details/86464238 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:企业 SOA 设计(2)–组件化产品开发平台
下一篇:性能测试晋级教程

发表评论

最新留言

表示我来过!
[***.240.166.169]2024年04月13日 19时12分09秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章