百度行驶证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#调用源码下载

相关推荐
武子康5 分钟前
大数据-212 数据挖掘 机器学习理论 - 无监督学习算法 KMeans 基本原理 簇内误差平方和
大数据·人工智能·学习·算法·机器学习·数据挖掘
deephub6 分钟前
Tokenformer:基于参数标记化的高效可扩展Transformer架构
人工智能·python·深度学习·架构·transformer
Q81375746012 分钟前
数据挖掘在金融交易中的应用:民锋科技的智能化布局
人工智能·科技·数据挖掘
qzhqbb15 分钟前
语言模型的采样方法
人工智能·语言模型·自然语言处理
qzhqbb18 分钟前
基于 Transformer 的语言模型
人工智能·语言模型·自然语言处理·transformer
___Dream19 分钟前
【CTFN】基于耦合翻译融合网络的多模态情感分析的层次学习
人工智能·深度学习·机器学习·transformer·人机交互
极客代码26 分钟前
【Python TensorFlow】入门到精通
开发语言·人工智能·python·深度学习·tensorflow
义小深29 分钟前
TensorFlow|咖啡豆识别
人工智能·python·tensorflow
Tianyanxiao1 小时前
如何利用探商宝精准营销,抓住行业机遇——以AI技术与大数据推动企业信息精准筛选
大数据·人工智能·科技·数据分析·深度优先·零售
羊小猪~~1 小时前
数据结构C语言描述2(图文结合)--有头单链表,无头单链表(两种方法),链表反转、有序链表构建、排序等操作,考研可看
c语言·数据结构·c++·考研·算法·链表·visual studio