# dbocr **Repository Path**: ywlydd/dbocr ## Basic Information - **Project Name**: dbocr - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2022-03-08 - **Last Updated**: 2022-12-12 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # ocr模块 ```c++ #ifndef __DBOCR_H__ #define __DBOCR_H__ #ifdef __cplusplus extern "C" { #endif struct DBOCRAlgo; // 初始化算法 // config_dir - 配置文件目录 // cam_id - 摄像头id = 0或1.... struct DBOCRAlgo* dbocr_initAlgo(const char* config_dir); //int dbocr_openCam(const DBOCRAlgo* handle, int cam_id); //struct XinuoImage* dbocr_readImage(const char* imgname); // 释放算法对象 int dbocr_freeAlgo(struct DBOCRAlgo* handle); // 释放算法对象 int dbocr_setParamInt(struct DBOCRAlgo* handle, int flag, int value); // 检测一帧图片 // imgname 图片路径,如果为NULL 则从摄像头读取 // roi - 感兴趣框的左上点和右下点坐标 [x1, y1, x2, y2] // 返回 结果字符串 const char* dbocr_detectOneFrame(struct DBOCRAlgo* handle, const char* imgname, const int* roi); //int test_ocr(int argc, const char* argv[]); #ifdef __cplusplus } #endif #endif // !__XINUO_XINUO_H__ ``` ### C++ 调用例子 ```C++ #include "libdbocr.h" #include #include #include #ifndef test_libdbocr #define test_libdbocr main #endif // test_libxinuo int test_libdbocr(int argc, char** argv) { char config_dir[256] = "./models"; //if (argc > 1) { snprintf(config_dir, 256, "%s", argv[1]); } struct DBOCRAlgo* handle = dbocr_initAlgo(config_dir); if (!handle) { printf("没插加密狗\n"); system("pause"); return 0; } const char* imgs[] = { //NULL, "test_imgs/1.jpg", "test_imgs/2.jpg", "test_imgs/3.jpg", "test_imgs/4.jpg", "test_imgs/5.jpg", }; const int nimgs = sizeof(imgs) / sizeof(imgs[0]); const char* out = ""; for (int i = 0; i < nimgs; ++i) { //out = xinuo_detectOneFrame(imgs[i] ? picpath : NULL); out = dbocr_detectImageFile(handle, imgs[i], NULL); printf("%d %s\n", strlen(out), out ? out : "file not exist"); } dbocr_freeAlgo(handle); return 0; } ``` ### C#调用例子 ```C# using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Linq; using System.Runtime.InteropServices; namespace winform { public partial class VisionForm : Form { // public string config_dir = Application.StartupPath + @"\xinuo\200"; public string config_dir = @"D:\code\git\ywlydd\dbocr\models"; //public string logfile = @"D:\bin\xinuoTest\test.log"; //public string outpath = @"D:\bin\xinuoTest\out"; public char[] picpath = new char[256]; IntPtr handle; public VisionForm() { InitializeComponent(); } /// /// 初始化 /// /// /// private void button1_Click(object sender, EventArgs e) { try { char[] temp = config_dir.ToArray(); handle = VisionClass.dbocr_initAlgo(temp);//返回非0,初始化成功 MessageBox.Show(handle.ToString()); } catch(Exception ex) { MessageBox.Show("初始化失败:" + ex.ToString()); } } private void button2_Click(object sender, EventArgs e) { try { OpenFileDialog openfile = new OpenFileDialog(); openfile.Filter = "*.jpg | *.jpg";//设置文件后缀 string imgname = @"D:\bin\dbocrTest\test.jpg"; if (openfile.ShowDialog() == DialogResult.OK) { imgname = openfile.FileName; } else { return; } char[] temp = imgname.ToArray(); IntPtr result = VisionClass.dbocr_detectImageFile(handle, temp, null);//检测 string strRet = Marshal.PtrToStringAnsi(result); strRet += "123"; MessageBox.Show(strRet); } catch (Exception ex) { MessageBox.Show("检测失败:" + ex.ToString()); } } } } ``` ### 返回 ```json [ { "text":"香港深圳抽血,", //识别结果 "points":[[433,272],[230,56],[266,22],[469,238]]// 矩形框四个角点 }, { "text":"专业查性别", "points":[[581,304],[340,63],[387,16],[628,257]] }, { "text":"专业鉴定B超单", "points":[[451,456],[164,136],[214,91],[501,411]] }, { "text":"b超仪器查性别", "points":[[365,531],[84,195],[137,151],[418,487]] }, { "text":"加微信", "points":[[130,399],[4,235],[59,193],[185,356]] }, { "text":"可邮寄", "points":[[575,422],[458,305],[497,266],[614,383]] }, { "text":"eee", "points":[[208,488],[131,392],[169,362],[246,458]] } ] ```