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

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

目录

说明

效果

项目

代码

下载


说明

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

SDK包结构

效果

项目

代码

using Newtonsoft.Json;

using System;

using System.Drawing;

using System.Runtime.InteropServices;

using System.Text;

using System.Windows.Forms;

namespace CSharpWinformTest

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

const string DllName = "DLSharp.dll";

//行驶证正页

[DllImport(DllName, EntryPoint = "dl_front_init_license", CallingConvention = CallingConvention.Cdecl)]

internal extern static int dl_front_init_license(string key, string licenseFile, bool is_remote);

[DllImport(DllName, EntryPoint = "dl_front_create", CallingConvention = CallingConvention.Cdecl)]

internal extern static IntPtr dl_front_create();

[DllImport(DllName, EntryPoint = "dl_front_init", CallingConvention = CallingConvention.Cdecl)]

internal extern static int dl_front_init(IntPtr engine, string ini_path);

[DllImport(DllName, EntryPoint = "dl_front_ocr", CallingConvention = CallingConvention.Cdecl)]

internal extern static int dl_front_ocr(IntPtr engine, string image_path, StringBuilder ocr_result1, StringBuilder ocr_result2);

[DllImport(DllName, EntryPoint = "dl_front_destroy", CallingConvention = CallingConvention.Cdecl)]

internal extern static void dl_front_destroy(IntPtr engine);

//行驶证副页

[DllImport(DllName, EntryPoint = "dl_back_init_license", CallingConvention = CallingConvention.Cdecl)]

internal extern static int dl_back_init_license(string key, string licenseFile, bool is_remote);

[DllImport(DllName, EntryPoint = "dl_back_create", CallingConvention = CallingConvention.Cdecl)]

internal extern static IntPtr dl_back_create();

[DllImport(DllName, EntryPoint = "dl_back_init", CallingConvention = CallingConvention.Cdecl)]

internal extern static int dl_back_init(IntPtr engine, string ini_path);

[DllImport(DllName, EntryPoint = "dl_back_ocr", CallingConvention = CallingConvention.Cdecl)]

internal extern static int dl_back_ocr(IntPtr engine, string image_path, StringBuilder ocr_result1, StringBuilder ocr_result2);

[DllImport(DllName, EntryPoint = "dl_back_destroy", CallingConvention = CallingConvention.Cdecl)]

internal extern static void dl_back_destroy(IntPtr engine);

IntPtr front_engine;

IntPtr back_engine;

private void button1_Click(object sender, EventArgs e)

{

if (image_path == "")

{

return;

}

StringBuilder ocr_result1 = new StringBuilder(1024);

StringBuilder ocr_result2 = new StringBuilder(1024);

int res = dl_front_ocr(front_engine, image_path, ocr_result1, ocr_result2);

if (res == 0)

{

Object jsonObject = JsonConvert.DeserializeObject(ocr_result1.ToString());

textBox1.Text = JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);

}

else

{

textBox1.Text = "识别失败";

}

}

private void Form1_Load(object sender, EventArgs e)

{

string key = "AISEE_xingshizheng_win_0530_3_3";

string licenseFile = Application.StartupPath + "\\license\\license.ini";

int res = -1;

string ini_path = "";

res = dl_front_init_license(key, licenseFile, false);

Console.WriteLine(res.ToString());

front_engine = dl_front_create();

ini_path = Application.StartupPath + "\\resource\\vehiclecard_front_resource";

res = dl_front_init(front_engine, ini_path);

Console.WriteLine(res.ToString());

res = dl_back_init_license(key, licenseFile, false);

Console.WriteLine(res.ToString());

back_engine = dl_back_create();

ini_path = Application.StartupPath + "\\resource\\vehiclecard_back_resource";

res = dl_back_init(back_engine, ini_path);

Console.WriteLine(res.ToString());

image_path = Application.StartupPath + "\\front_images\\2.jpg";

//image_path = Application.StartupPath + "\\back_images\\1.png";

pictureBox1.Image = new Bitmap(image_path);

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

dl_front_destroy(front_engine);

dl_back_destroy(back_engine);

}

string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";

string 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 button3_Click(object sender, EventArgs e)

{

if (image_path == "")

{

return;

}

StringBuilder ocr_result1 = new StringBuilder(1024);

StringBuilder ocr_result2 = new StringBuilder(1024);

int res = dl_back_ocr(back_engine, image_path, ocr_result1, ocr_result2);

if (res == 0)

{

Object jsonObject = JsonConvert.DeserializeObject(ocr_result1.ToString());

textBox1.Text = JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);

}

else

{

textBox1.Text = "识别失败";

}

}

private void button4_Click(object sender, EventArgs e)

{

image_path = Application.StartupPath + "\\front_images\\2.jpg";

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);

}

}

}

using Newtonsoft.Json;
using System;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

namespace CSharpWinformTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        const string DllName = "DLSharp.dll";

        //行驶证正页

        [DllImport(DllName, EntryPoint = "dl_front_init_license", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int dl_front_init_license(string key, string licenseFile, bool is_remote);

        [DllImport(DllName, EntryPoint = "dl_front_create", CallingConvention = CallingConvention.Cdecl)]
        internal extern static IntPtr dl_front_create();

        [DllImport(DllName, EntryPoint = "dl_front_init", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int dl_front_init(IntPtr engine, string ini_path);

        [DllImport(DllName, EntryPoint = "dl_front_ocr", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int dl_front_ocr(IntPtr engine, string image_path, StringBuilder ocr_result1, StringBuilder ocr_result2);

        [DllImport(DllName, EntryPoint = "dl_front_destroy", CallingConvention = CallingConvention.Cdecl)]
        internal extern static void dl_front_destroy(IntPtr engine);


        //行驶证副页

        [DllImport(DllName, EntryPoint = "dl_back_init_license", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int dl_back_init_license(string key, string licenseFile, bool is_remote);

        [DllImport(DllName, EntryPoint = "dl_back_create", CallingConvention = CallingConvention.Cdecl)]
        internal extern static IntPtr dl_back_create();

        [DllImport(DllName, EntryPoint = "dl_back_init", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int dl_back_init(IntPtr engine, string ini_path);

        [DllImport(DllName, EntryPoint = "dl_back_ocr", CallingConvention = CallingConvention.Cdecl)]
        internal extern static int dl_back_ocr(IntPtr engine, string image_path, StringBuilder ocr_result1, StringBuilder ocr_result2);

        [DllImport(DllName, EntryPoint = "dl_back_destroy", CallingConvention = CallingConvention.Cdecl)]
        internal extern static void dl_back_destroy(IntPtr engine);


        IntPtr front_engine;
        IntPtr back_engine;

        private void button1_Click(object sender, EventArgs e)
        {

            if (image_path == "")
            {
                return;
            }

            StringBuilder ocr_result1 = new StringBuilder(1024);
            StringBuilder ocr_result2 = new StringBuilder(1024);
            int res = dl_front_ocr(front_engine, image_path, ocr_result1, ocr_result2);
            if (res == 0)
            {

                Object jsonObject = JsonConvert.DeserializeObject(ocr_result1.ToString());
                textBox1.Text = JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);
            }
            else
            {
                textBox1.Text = "识别失败";
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string key = "AISEE_xingshizheng_win_0530_3_3";
            string licenseFile = Application.StartupPath + "\\license\\license.ini";
            int res = -1;
            string ini_path = "";

            res = dl_front_init_license(key, licenseFile, false);
            Console.WriteLine(res.ToString());

            front_engine = dl_front_create();

            ini_path = Application.StartupPath + "\\resource\\vehiclecard_front_resource";
            res = dl_front_init(front_engine, ini_path);
            Console.WriteLine(res.ToString());

            res = dl_back_init_license(key, licenseFile, false);
            Console.WriteLine(res.ToString());

            back_engine = dl_back_create();

            ini_path = Application.StartupPath + "\\resource\\vehiclecard_back_resource";
            res = dl_back_init(back_engine, ini_path);
            Console.WriteLine(res.ToString());

            image_path = Application.StartupPath + "\\front_images\\2.jpg";
            //image_path = Application.StartupPath + "\\back_images\\1.png";

            pictureBox1.Image = new Bitmap(image_path);
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            dl_front_destroy(front_engine);
            dl_back_destroy(back_engine);
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string 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 button3_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }

            StringBuilder ocr_result1 = new StringBuilder(1024);
            StringBuilder ocr_result2 = new StringBuilder(1024);
            int res = dl_back_ocr(back_engine, image_path, ocr_result1, ocr_result2);
            if (res == 0)
            {
                Object jsonObject = JsonConvert.DeserializeObject(ocr_result1.ToString());
                textBox1.Text = JsonConvert.SerializeObject(jsonObject, Newtonsoft.Json.Formatting.Indented);
            }
            else
            {
                textBox1.Text = "识别失败";
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            image_path = Application.StartupPath + "\\front_images\\2.jpg";
            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);
        }
    }
}

下载

C++封装源码下载

C#调用源码下载

相关推荐
AL.千灯学长1 小时前
DeepSeek接入Siri(已升级支持苹果手表)完整版硅基流动DeepSeek-R1部署
人工智能·gpt·ios·ai·苹果vision pro
cookies_s_s1 小时前
Linux--进程(进程虚拟地址空间、页表、进程控制、实现简易shell)
linux·运维·服务器·数据结构·c++·算法·哈希算法
LCG元1 小时前
大模型驱动的围术期质控系统全面解析与应用探索
人工智能
lihuayong2 小时前
计算机视觉:主流数据集整理
人工智能·计算机视觉·mnist数据集·coco数据集·图像数据集·cifar-10数据集·imagenet数据集
不想编程小谭2 小时前
力扣LeetCode: 2506 统计相似字符串对的数目
c++·算法·leetcode
政安晨2 小时前
政安晨【零基础玩转各类开源AI项目】DeepSeek 多模态大模型Janus-Pro-7B,本地部署!支持图像识别和图像生成
人工智能·大模型·多模态·deepseek·janus-pro-7b
一ge科研小菜鸡2 小时前
DeepSeek 与后端开发:AI 赋能云端架构与智能化服务
人工智能·云原生
冰 河2 小时前
‌最新版DeepSeek保姆级安装教程:本地部署+避坑指南
人工智能·程序员·openai·deepseek·冰河大模型
维维180-3121-14552 小时前
AI赋能生态学暨“ChatGPT+”多技术融合在生态系统服务中的实践技术应用与论文撰写
人工智能·chatgpt
終不似少年遊*2 小时前
词向量与词嵌入
人工智能·深度学习·nlp·机器翻译·词嵌入