首页 > 编程语言 >百度驾驶证C++离线SDK V1.1 C#接入

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

时间:2024-04-10 10:31:17浏览次数:33  
标签:C# res image 离线 C++ ToDouble path new pts

百度驾驶证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;
        }
    }
}

下载 

C++封装源码下载

C#调用源码下载

SDK下载

标签:C#,res,image,离线,C++,ToDouble,path,new,pts
From: https://blog.csdn.net/weixin_46771779/article/details/137586674

相关文章

  • 1688商品详情跨境属性数据接口(1688.item_get_specifications)
    1688商品详情跨境属性数据接口(1688.item_get_specifications)是一个专为跨境电商商家设计的API,它允许商家获取商品的国际贸易相关属性。这些属性对于跨境电商至关重要,因为它们帮助商家遵守不同国家和地区的法律法规,确保商品的顺利报关和交易。具体来说,这个接口的应用主要体现在......
  • 【leetcode面试经典150题】26.判断子序列(C++)
    【leetcode面试经典150题】专栏系列将为准备暑期实习生以及秋招的同学们提高在面试时的经典面试算法题的思路和想法。本专栏将以一题多解和精简算法思路为主,题解使用C++语言。(若有使用其他语言的同学也可了解题解思路,本质上语法内容一致)【题目描述】给定字符串 s 和 t ......
  • 使用ultralytics导入YOLO报错:libcublas.so.11: symbol cublasLtGetStatusString versi
    1.问题:使用yolo的时候,fromultralyticsimportYOLO.然后报错:libcublas.so.11:symbolcublasLtGetStatusStringversionlibcublasLt.so.11notdefinedinfilelibcublasLt.so.11withlinktimereference2.解决方案:pipuninstallnvidia_cublas_cu11然后就会运行......
  • Python基于Excel数据加以反距离加权空间插值并掩膜图层
      本文介绍基于Python中ArcPy模块,实现Excel数据读取并生成矢量图层,同时进行IDW插值与批量掩膜的方法。1任务需求  首先,我们来明确一下本文所需实现的需求。  现有一个记录有北京市部分PM2.5浓度监测站点在2019年05月18日00时至23时(其中不含19时)等23个逐小时PM2.5浓度数......
  • Taurus.MVC 性能压力测试(ap 压测 和 linux 下wrk 压测):.NET Core 版本
    前言:最近的Taurus.MVC版本,对性能这一块有了不少优化,因此准备进行一下压测,来测试并记录一下Taurus.MVC 框架的性能,以便后续持续优化改进。今天先压测.NETCore 版本,后续有时间再压测一下.NET 版本。下面来看不同场景下的压测结果,以下测试结果会由两台电脑进行分别测试。......
  • 界面控件DevExtreme JS & ASP.NET Core 2024年度产品规划预览(二)
    在本文中我们将介绍今年即将发布的v24.1附带的主要特性,这些特性既适用于DevExtreme JavaScript(Angular、React、Vue、jQuery),也适用于基于DevExtreme的ASP.NETMVC/Core控件。注意:本文中列出的功能和特性说明官方当前/预计的发展计划,此信息仅供参考之用,其中列出的功能/产品可......
  • java synchronized 还是用redis 锁 java的synchronized的实现原理
    synchronized是同步的意思,在java多线程中,我们一般会考虑共享数据的处理,共享数据的处理包含两块,第一是共享数据,第二是在多线程访问共享数据的时候,如果处理共享数据,保证数据的有效正确性。我们要保证线程A访问共享数据,对数据进行处理的时候,其他线程能够等待线程A访问完毕后,和线程A看......
  • 解决keil单片编程ERROR L107: ADDRESS SPACE OVERFLOW问题及根源分析
    1、将部分声明的不需要修改的变量声明为程序存储器变量,即在变量名前增加code关键字,如:unsignedcharcodeled_mod[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};当然,我们也可以使用关键字xdata将数据存储到片......
  • sql是不是可以写在service层?虽然service是业务层
    我记得我曾经学javaweb的时候,也是被这个问题困惑过大半年,service层到底要不要出现sql或者Hibernate的hql语句?我曾经有和你一样的困惑,比如有一个UserDao的接口,假如我想查询User,根据Id查询可能UserDao就需要设置一个findUserById(Integerid)这样的方法,根据用户名查询就是findUserBy......
  • 独立站点发布VectorTileServer的方法
    独立站点部署模式下,发布矢量切片服务的方式说明二维切片类型栅格地图瓦片(MapServer|WMTS)切片图层可绘制服务器上一组可通过Web访问的切片。在绘制栅格地图瓦片图层时,对在当前地图范围和地图比例中绘制图层时所需的切片执行请求。切片图层可用于绘制一组托管在已知U......