百度驾驶证C++离线SDK V1.1 C#接入

百度驾驶证C++离线SDK V1.1 C#接入

目录

说明 

效果 

项目

代码

下载 


说明 

自己根据SDK封装了动态库,然后C#调用。

SDK包结构

效果 

项目

代码

using Newtonsoft.Json;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using 驾驶证测试.Commom;

namespace 驾驶证测试
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        bool isDraw = false;

        private void Form1_Load(object sender, EventArgs e)
        {
            image_path = Application.StartupPath + "\\front_images\\1.png";
            pictureBox1.Image = new Bitmap(image_path);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            image_path = Application.StartupPath + "\\front_images\\1.png";

            Mat image = new Mat(image_path);

            pictureBox1.Image = new Bitmap(image_path);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            image_path = Application.StartupPath + "\\back_images\\1.png";
            pictureBox1.Image = new Bitmap(image_path);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
            pictureBox1.Image = null;
            image_path = ofd.FileName;
            pictureBox1.Image = new Bitmap(image_path);
            textBox1.Text = "";
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }

            textBox1.Text = "";
            Application.DoEvents();

            string ocr_result1 = "";
            string ocr_result2 = "";
            Mat image = new Mat(image_path);
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            int res = DL_OCR_Helper.dl_front_ocr2(image, out ocr_result1, out ocr_result2);
            stopwatch.Stop();
            double totalTime = stopwatch.Elapsed.TotalSeconds;
            textBox1.Text += $"耗时: {totalTime:F2}s";
            textBox1.Text += "\r\n-------------------\r\n";

            if (res == 0)
            {
                Object jsonObject = JsonConvert.DeserializeObject(ocr_result1.ToString());
                textBox1.Text += JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);

                textBox1.Text += "\r\n-------------------\r\n";

                Object jsonObject2 = JsonConvert.DeserializeObject(ocr_result2.ToString());
                textBox1.Text += JsonConvert.SerializeObject(jsonObject2, Newtonsoft.Json.Formatting.Indented);

                List<OcrRes2> lt = JsonConvert.DeserializeObject<List<OcrRes2>>(ocr_result2.ToString());

                foreach (OcrRes2 item in lt)
                {
                    string[] pts = item.coordinator.Split(' ');

                    //多边形的顶点
                    OpenCvSharp.Point[] points = new OpenCvSharp.Point[]
                    {
                        new OpenCvSharp.Point(Convert.ToDouble( pts[0]), Convert.ToDouble( pts[1])),
                        new OpenCvSharp.Point(Convert.ToDouble( pts[2]), Convert.ToDouble( pts[3])),
                        new OpenCvSharp.Point(Convert.ToDouble( pts[4]), Convert.ToDouble( pts[5])),
                        new OpenCvSharp.Point(Convert.ToDouble( pts[6]), Convert.ToDouble( pts[7])),
                    };

                    // 绘制多边形
                    if (isDraw)
                    {
                        Cv2.Polylines(image, new OpenCvSharp.Point[][] { points }, isClosed: true, color: new Scalar(0, 255, 0), thickness: 3);

                    }
                }
                if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                    pictureBox1.Image = null;
                }

                pictureBox1.Image = new Bitmap(image.ToMemoryStream());
                image.Dispose();
            }
            else
            {
                textBox1.Text = "识别失败";
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }

            textBox1.Text = "";
            Mat image = new Mat(image_path);
            Application.DoEvents();
            string ocr_result1 = "";
            string ocr_result2 = "";
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            int res = DL_OCR_Helper.dl_back_ocr2(image, out ocr_result1, out ocr_result2);
            stopwatch.Stop();
            double totalTime = stopwatch.Elapsed.TotalSeconds;
            textBox1.Text += $"耗时: {totalTime:F2}s";
            textBox1.Text += "\r\n-------------------\r\n";
            if (res == 0)
            {
                Object jsonObject = JsonConvert.DeserializeObject(ocr_result1.ToString());
                textBox1.Text += JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);

                textBox1.Text += "\r\n-------------------\r\n";

                Object jsonObject2 = JsonConvert.DeserializeObject(ocr_result2.ToString());
                textBox1.Text += JsonConvert.SerializeObject(jsonObject2, Newtonsoft.Json.Formatting.Indented);

                List<OcrRes2> lt = JsonConvert.DeserializeObject<List<OcrRes2>>(ocr_result2.ToString());

                foreach (OcrRes2 item in lt)
                {

                    string[] pts = item.coordinator.Split(' ');

                    //多边形的顶点
                    OpenCvSharp.Point[] points = new OpenCvSharp.Point[]
                    {
                        new OpenCvSharp.Point(Convert.ToDouble( pts[0]), Convert.ToDouble( pts[1])),
                        new OpenCvSharp.Point(Convert.ToDouble( pts[2]), Convert.ToDouble( pts[3])),
                        new OpenCvSharp.Point(Convert.ToDouble( pts[4]), Convert.ToDouble( pts[5])),
                        new OpenCvSharp.Point(Convert.ToDouble( pts[6]), Convert.ToDouble( pts[7])),
                    };

                    // 绘制多边形
                    if (isDraw)
                    {
                        Cv2.Polylines(image, new OpenCvSharp.Point[][] { points }, isClosed: true, color: new Scalar(0, 255, 0), thickness: 3);
                    }
                }
                if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                    pictureBox1.Image = null;
                }
                pictureBox1.Image = new Bitmap(image.ToMemoryStream());
                image.Dispose();
            }
            else
            {
                textBox1.Text = "识别失败";
            }
        }

        private void button6_Click(object sender, EventArgs e)
        {
            DL_OCR_Helper.InitStatus();

            //授权校验 初始化引擎
            string key = "";
            string licenseKeyPath = Application.StartupPath + "\\license\\license.key";
            string licenseFile = Application.StartupPath + "\\license\\license.ini";
            int res = -1;
            string ini_path = "";

            key = File.ReadAllText(licenseKeyPath);

            res = DL_OCR_Helper.dl_front_init_license(key, licenseFile, false);
            if (res != 0)
            {
                MessageBox.Show(DL_OCR_Helper.GetMsg(res));
                return;
            }

            res = DL_OCR_Helper.dl_front_create();
            if (res != 0)
            {
                MessageBox.Show("驾驶证正页创建引擎失败!");
                return;
            }

            ini_path = Application.StartupPath + "\\front_resource";
            res = DL_OCR_Helper.dl_front_init(ini_path);
            if (res != 0)
            {
                MessageBox.Show(DL_OCR_Helper.GetMsg(res));
                return;
            }

            res = DL_OCR_Helper.dl_back_init_license(key, licenseFile, false);
            if (res != 0)
            {
                MessageBox.Show(DL_OCR_Helper.GetMsg(res));
                return;
            }

            res = DL_OCR_Helper.dl_back_create();
            if (res != 0)
            {
                MessageBox.Show("驾驶证副页创建引擎失败!");
                return;
            }

            ini_path = Application.StartupPath + "\\back_resource";
            res = DL_OCR_Helper.dl_back_init(ini_path);
            if (res != 0)
            {
                MessageBox.Show(DL_OCR_Helper.GetMsg(res));
                return;
            }
            MessageBox.Show("初始化成功!");
            button1.Enabled = true;
            button3.Enabled = true;
        }
    }
}

using Newtonsoft.Json;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using 驾驶证测试.Commom;namespace 驾驶证测试
{public partial class Form1 : Form{public Form1(){InitializeComponent();}string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";string image_path = "";bool isDraw = false;private void Form1_Load(object sender, EventArgs e){image_path = Application.StartupPath + "\\front_images\\1.png";pictureBox1.Image = new Bitmap(image_path);}private void button4_Click(object sender, EventArgs e){image_path = Application.StartupPath + "\\front_images\\1.png";Mat image = new Mat(image_path);pictureBox1.Image = new Bitmap(image_path);}private void button5_Click(object sender, EventArgs e){image_path = Application.StartupPath + "\\back_images\\1.png";pictureBox1.Image = new Bitmap(image_path);}private void button2_Click(object sender, EventArgs e){OpenFileDialog ofd = new OpenFileDialog();ofd.Filter = fileFilter;if (ofd.ShowDialog() != DialogResult.OK) return;pictureBox1.Image = null;image_path = ofd.FileName;pictureBox1.Image = new Bitmap(image_path);textBox1.Text = "";}private void button1_Click(object sender, EventArgs e){if (image_path == ""){return;}textBox1.Text = "";Application.DoEvents();string ocr_result1 = "";string ocr_result2 = "";Mat image = new Mat(image_path);Stopwatch stopwatch = new Stopwatch();stopwatch.Start();int res = DL_OCR_Helper.dl_front_ocr2(image, out ocr_result1, out ocr_result2);stopwatch.Stop();double totalTime = stopwatch.Elapsed.TotalSeconds;textBox1.Text += $"耗时: {totalTime:F2}s";textBox1.Text += "\r\n-------------------\r\n";if (res == 0){Object jsonObject = JsonConvert.DeserializeObject(ocr_result1.ToString());textBox1.Text += JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);textBox1.Text += "\r\n-------------------\r\n";Object jsonObject2 = JsonConvert.DeserializeObject(ocr_result2.ToString());textBox1.Text += JsonConvert.SerializeObject(jsonObject2, Newtonsoft.Json.Formatting.Indented);List<OcrRes2> lt = JsonConvert.DeserializeObject<List<OcrRes2>>(ocr_result2.ToString());foreach (OcrRes2 item in lt){string[] pts = item.coordinator.Split(' ');//多边形的顶点OpenCvSharp.Point[] points = new OpenCvSharp.Point[]{new OpenCvSharp.Point(Convert.ToDouble( pts[0]), Convert.ToDouble( pts[1])),new OpenCvSharp.Point(Convert.ToDouble( pts[2]), Convert.ToDouble( pts[3])),new OpenCvSharp.Point(Convert.ToDouble( pts[4]), Convert.ToDouble( pts[5])),new OpenCvSharp.Point(Convert.ToDouble( pts[6]), Convert.ToDouble( pts[7])),};// 绘制多边形if (isDraw){Cv2.Polylines(image, new OpenCvSharp.Point[][] { points }, isClosed: true, color: new Scalar(0, 255, 0), thickness: 3);}}if (pictureBox1.Image != null){pictureBox1.Image.Dispose();pictureBox1.Image = null;}pictureBox1.Image = new Bitmap(image.ToMemoryStream());image.Dispose();}else{textBox1.Text = "识别失败";}}private void button3_Click(object sender, EventArgs e){if (image_path == ""){return;}textBox1.Text = "";Mat image = new Mat(image_path);Application.DoEvents();string ocr_result1 = "";string ocr_result2 = "";Stopwatch stopwatch = new Stopwatch();stopwatch.Start();int res = DL_OCR_Helper.dl_back_ocr2(image, out ocr_result1, out ocr_result2);stopwatch.Stop();double totalTime = stopwatch.Elapsed.TotalSeconds;textBox1.Text += $"耗时: {totalTime:F2}s";textBox1.Text += "\r\n-------------------\r\n";if (res == 0){Object jsonObject = JsonConvert.DeserializeObject(ocr_result1.ToString());textBox1.Text += JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);textBox1.Text += "\r\n-------------------\r\n";Object jsonObject2 = JsonConvert.DeserializeObject(ocr_result2.ToString());textBox1.Text += JsonConvert.SerializeObject(jsonObject2, Newtonsoft.Json.Formatting.Indented);List<OcrRes2> lt = JsonConvert.DeserializeObject<List<OcrRes2>>(ocr_result2.ToString());foreach (OcrRes2 item in lt){string[] pts = item.coordinator.Split(' ');//多边形的顶点OpenCvSharp.Point[] points = new OpenCvSharp.Point[]{new OpenCvSharp.Point(Convert.ToDouble( pts[0]), Convert.ToDouble( pts[1])),new OpenCvSharp.Point(Convert.ToDouble( pts[2]), Convert.ToDouble( pts[3])),new OpenCvSharp.Point(Convert.ToDouble( pts[4]), Convert.ToDouble( pts[5])),new OpenCvSharp.Point(Convert.ToDouble( pts[6]), Convert.ToDouble( pts[7])),};// 绘制多边形if (isDraw){Cv2.Polylines(image, new OpenCvSharp.Point[][] { points }, isClosed: true, color: new Scalar(0, 255, 0), thickness: 3);}}if (pictureBox1.Image != null){pictureBox1.Image.Dispose();pictureBox1.Image = null;}pictureBox1.Image = new Bitmap(image.ToMemoryStream());image.Dispose();}else{textBox1.Text = "识别失败";}}private void button6_Click(object sender, EventArgs e){DL_OCR_Helper.InitStatus();//授权校验 初始化引擎string key = "";string licenseKeyPath = Application.StartupPath + "\\license\\license.key";string licenseFile = Application.StartupPath + "\\license\\license.ini";int res = -1;string ini_path = "";key = File.ReadAllText(licenseKeyPath);res = DL_OCR_Helper.dl_front_init_license(key, licenseFile, false);if (res != 0){MessageBox.Show(DL_OCR_Helper.GetMsg(res));return;}res = DL_OCR_Helper.dl_front_create();if (res != 0){MessageBox.Show("驾驶证正页创建引擎失败!");return;}ini_path = Application.StartupPath + "\\front_resource";res = DL_OCR_Helper.dl_front_init(ini_path);if (res != 0){MessageBox.Show(DL_OCR_Helper.GetMsg(res));return;}res = DL_OCR_Helper.dl_back_init_license(key, licenseFile, false);if (res != 0){MessageBox.Show(DL_OCR_Helper.GetMsg(res));return;}res = DL_OCR_Helper.dl_back_create();if (res != 0){MessageBox.Show("驾驶证副页创建引擎失败!");return;}ini_path = Application.StartupPath + "\\back_resource";res = DL_OCR_Helper.dl_back_init(ini_path);if (res != 0){MessageBox.Show(DL_OCR_Helper.GetMsg(res));return;}MessageBox.Show("初始化成功!");button1.Enabled = true;button3.Enabled = true;}}
}

下载 

C++封装源码下载

C#调用源码下载

SDK下载

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/804373.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++矩阵库Armadillo出现warning solve() system is singular错误的解决

本文介绍使用C 语言的矩阵库Armadillo时&#xff0c;出现报错system is singular; attempting approx solution的解决方法。 在之前的文章中&#xff0c;我们介绍过Armadillo矩阵库在Visual Studio软件C环境中的配置方法&#xff08;https://blog.csdn.net/zhebushibiaoshifu/a…

使用midjourney搞出一套三国人物画像!

当下已进入如火如荼的全民AI时代&#xff0c;最近体验了下midjourney&#xff0c;使用它的以图生图功能生成出来一套三国人物画像&#xff0c;和大家分享下使用心得。 使用midjourney的准备工作 下载工具 使用midjourney生产图片依赖的工具和流程&#xff0c;大致如下&#…

ssh远程压测断网,导致程序中断,解决方案

解决方案是用tmux功能&#xff0c;很好用&#xff0c;亲测有效 tmux是一种终端复用工具&#xff0c;它允许用户在单个终端窗口中同时运行多个终端会话。tmux提供了多个窗口和面板的功能&#xff0c;使用户可以轻松地切换和管理多个终端会话。 使用tmux可以实现以下功能&#x…

vue3移动端H5 瀑布流显示列表

以上效果 是之前发送的改进版 waterList <template><view class"pro-cons" v-if"data.length"><view class"cons-left"><template v-for"(item, index) in data"><template v-if"(index 1) % 2 1…

NLP在搜索召回领域中的应用场景

自然语言处理&#xff08;NLP&#xff09;在搜索召回领域中的应用场景非常广泛&#xff0c;它通过理解和分析人类语言&#xff0c;提高了信息检索的准确性和效率。以下是一些具体的应用场景&#xff1a; 1. 搜索引擎优化 NLP技术可以用于优化搜索引擎的查询处理&#xff0c;通…

【DM8】外部表

外部表是指不存在于数据库中的表。 通过向达梦数据库定义描述外部表的元数据&#xff0c;可以把一个操作系统文件当成一个只读的数据库表&#xff0c;对外部表将像普通定义的表一样访问。 外部表的数据存储在操作系统文件中&#xff0c;建立外部表的时候&#xff0c;不会产生…

下载安装JDK17(windows)

官网地址 Oracle | Cloud Applications and Cloud Platform 点击Products拉倒最下面点击java 点击右下角Download Java 选择JDK17 点击Windows&#xff0c;下载第二个 下载完成点击一下步安装就好了 认真看这段话 ​ JDK 17 binaries are free to use in production and free…

记录线上问题定位实践 org.springframework.dao.QueryTimeoutException(解决思路)

现象 线上环境 偶发性出现如下异常&#xff0c;当出现此异常的&#xff0c;可重复复现 org.springframework.dao.QueryTimeoutException: ### Error querying database. Cause: com.mysql.cj.jdbc.exceptions.MySQLTimeoutException: Statement cancelled due to timeout or…

代码整洁之道【2】--函数

关于函数部分的总结 一、函数只做一件事 函数应该只做一件事、做好这件事、只做这件事。 判断函数是否不止做了一件事&#xff0c;还有一个方法&#xff0c;就是看是否能再拆出一个函数&#xff0c;该函数不仅只是单纯地重新 二、函数尽量不要太长 按照作者的理论&#xff…

【算法】双指针算法

个人主页 &#xff1a; zxctscl 如有转载请先通知 题目 1. 283. 移动零1.1 分析1.2 代码 2. 1089. 复写零2.1 分析2.2 代码 3. 202. 快乐数3.1 分析3.2 代码 4. 11. 盛最多水的容器4.1 分析4.2 代码 5. LCR 179. 查找总价格为目标值的两个商品5.1 分析5.2 代码 6. 15. 三数之和…

大语言模型开源数据集

本文目标&#xff1a;汇聚目前大语言模型预训练、微调、RM/RL、评测等全流程所需的常见数据集&#xff0c;方便大家使用&#xff0c;本文持续更新。文章篇幅较长&#xff0c;建议收藏后使用。 一、按语料类型分类 1、维基百科类 No.1 Identifying Machine-Paraphrased Plagia…

企业微信认证后可以修改主体吗?

企业微信变更主体有什么作用&#xff1f;如果原有的公司注销了&#xff0c;或者要更换一家公司主体来运营企业微信&#xff0c;那么就可以进行变更主体&#xff0c;变更主体后才可以保留原来企业微信上的所有用户&#xff0c;否则就只能重新申请重新积累用户了。企业微信变更主…

新媒体运营到底是什么?

引流&#xff0c;留存&#xff0c;激活&#xff0c;变现&#xff0c;新媒体运营的道路很简单&#xff0c;但真的要做好&#xff0c;还得加亿点细节。首先&#xff0c;你得搞懂什么是新媒体运营。新媒体运营新媒体运营&#xff0c;也就是要懂新媒体&#xff0c;懂运营。 一、认识…

【资源分享】MAC上最好用的截图软件-Snipaste

::: block-1 “时问桫椤“是一个关注本科生到研究生教育阶段的不严肃的公众号&#xff0c;希望能在大家迷茫、难受、困难之时帮助到大家。用广大研究生的经验总结&#xff0c;让大家能尽早的适应研究生生活&#xff0c;尽快的看透科研本质。祝好&#xff01;&#xff01;&#…

vue通过echarts实现数据可视化

1、安装echarts cnpm install echarts -Sechart官方图表示例大全&#xff1a;https://echarts.apache.org/examples/zh/index.html#chart-type-line 2、代码实现 <template><div><div class"box" ref"zhu"></div><div class&…

注解式 WebSocket - 构建 群聊、单聊 系统

目录 前言 注解式 WebSocket 构建聊天系统 群聊系统&#xff08;基本框架&#xff09; 群聊系统&#xff08;添加昵称&#xff09; 单聊系统 WebSocket 作用域下无法注入 Spring Bean 对象&#xff1f; 考虑离线消息 前言 很久之前&#xff0c;咱们聊过 WebSocket 编程式…

掌握网络抓取技术:利用RobotRules库的Perl下载器一览小红书的世界

引言 在信息时代的浪潮下&#xff0c;人们对于获取和分析海量网络数据的需求与日俱增。网络抓取技术作为满足这一需求的关键工具&#xff0c;正在成为越来越多开发者的首选。而Perl语言&#xff0c;以其卓越的文本处理能力和灵活的特性&#xff0c;脱颖而出&#xff0c;成为了…

【web3技术】如何利用这些免费资源学习Web3,快速入门到工作?

Web3 文章和课程列表。了解如何为以太坊区块链开发智能合约。 以下是免费学习资源列表,可以帮助您学习如何为以太坊区块链开发智能合约。 0. 白皮书 比特币白皮书以太坊白皮书1.开始使用 Cloudflare 构建 Web3 应用程序 了解如何使用 Cloudflare 的新开源模板构建 Web3 应用…

Android 属性动画及自定义3D旋转动画

Android 动画框架 其中包括&#xff0c;帧动画、视图动画&#xff08;补间动画&#xff09;、属性动画。 在Android3.0之前&#xff0c;视图动画一家独大&#xff0c;之后属性动画框架被推出。属性动画框架&#xff0c;基本可以实现所有的视图动画效果。 视图动画的效率较高…

【第七篇】使用BurpSuite进行主动、被动扫描和主动、被动爬虫

文章目录 前言主动扫描被动扫描主动爬虫被动爬虫前言 Burp Scanner 既可以用作全自动扫描仪,也可以用作增强手动测试工作流程的强大手段。 扫描网站涉及两个阶段: 抓取内容和功能: Burp Scanner 首先在目标站点周围导航,密切反映真实用户的行为。它对站点的结构和内容以及…