PP-OCRv5 C++封装DLL C#调用源码分享

目录

说明

效果

C#调用效果

项目

C#

C++

头文件

源文件

C#调用

下载


说明

C++封装DLL,C#调用源码分享

效果

C#调用效果

项目

C#

C++

头文件

复制代码
#include <windows.h>
#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>

using namespace std;
using namespace cv;

//ocr  初始化
extern "C" _declspec(dllexport) int __cdecl init(void** engine
 , int cpu_threads
 , bool enable_mkldnn

 , char* det_model_dir
 , int limit_side_len
 , double det_db_thresh
 , double det_db_box_thresh
 , double det_db_unclip_ratio
 , bool use_dilation

 , bool cls
 , bool use_angle_cls
 , char* cls_model_dir
 , double cls_thresh
 , double cls_batch_num

 , char* rec_model_dir
 , char* rec_char_dict_path
    , int rec_batch_num
 , int rec_img_h
 , int rec_img_w

 , char* msg);

//识别
extern "C" _declspec(dllexport) int __cdecl ocr(void* engine, Mat * image, char* msg, char** ocr_result, int* ocr_result_len);

//释放
extern "C" _declspec(dllexport) int __cdecl destroy(void* engine, char* msg);

//structure 初始化
extern "C" _declspec(dllexport) int __cdecl structure_init(void** engine

 , int cpu_threads
 , bool enable_mkldnn

 , char* det_model_dir
 , int limit_side_len
 , double det_db_thresh
 , double det_db_box_thresh
 , double det_db_unclip_ratio
 , bool use_dilation

 , bool cls
 , bool use_angle_cls
 , char* cls_model_dir
 , double cls_thresh
 , double cls_batch_num

 , char* rec_model_dir
 , char* rec_char_dict_path
 , int rec_batch_num
 , int rec_img_h
 , int rec_img_w

 , int table_max_len
 , int table_batch_num
 , char* table_model_dir
 , char* table_char_dict_path

 , char* msg);

//structure
extern "C" _declspec(dllexport) int __cdecl structure(void* engine, Mat * image, char* msg, char** ocr_result, int* ocr_result_len);

//释放
extern "C" _declspec(dllexport) int __cdecl structure_destroy(void* engine, char* msg);

源文件

复制代码
#define _CRT_SECURE_NO_WARNINGS

#include "pch.h"
#include <paddleocr.h>
#include "src/json.cpp"
#include <args.h>
#include <chrono>
#include <objbase.h>

using json = nlohmann::json;
using namespace PaddleOCR;

#include<locale>
#include <codecvt>
#include <paddlestructure.h>

//初始化
int __cdecl init(void** engine

 , int cpu_threads
 , bool enable_mkldnn

 , char* det_model_dir
 , int limit_side_len
 , double det_db_thresh
 , double det_db_box_thresh
 , double det_db_unclip_ratio
 , bool use_dilation

 , bool cls
 , bool use_angle_cls
 , char* cls_model_dir
 , double cls_thresh
 , double cls_batch_num

 , char* rec_model_dir
 , char* rec_char_dict_path
 , int rec_batch_num
 , int rec_img_h
 , int rec_img_w

 , char* msg) {

 try {

  FLAGS_cpu_threads = cpu_threads;
  FLAGS_enable_mkldnn = enable_mkldnn;
  FLAGS_visualize = false;

  //det 
  FLAGS_det_model_dir = det_model_dir;
  FLAGS_limit_side_len = limit_side_len;
  FLAGS_det_db_thresh = det_db_thresh;
  FLAGS_det_db_box_thresh = det_db_box_thresh;
  FLAGS_det_db_unclip_ratio = det_db_unclip_ratio;
  FLAGS_use_dilation = use_dilation;

  //cls
  FLAGS_cls = cls;
  FLAGS_use_angle_cls = use_angle_cls;
  FLAGS_cls_model_dir = cls_model_dir;
  FLAGS_cls_thresh = cls_thresh;
  FLAGS_cls_batch_num = cls_batch_num;

  //rec
  FLAGS_rec_model_dir = rec_model_dir;
  FLAGS_rec_char_dict_path = rec_char_dict_path;
  FLAGS_rec_batch_num = rec_batch_num;
  FLAGS_rec_img_h = rec_img_h;
  FLAGS_rec_img_w = rec_img_w;

  PPOCR* _engine = new PPOCR();

  *engine = _engine;

  strcpy_s(msg, 128, "init success");

return 0;
 }
 catch (...) {
  std::cout << "init error" << std::endl;
  strcpy_s(msg, 128, "init error");
return -1;
 }

}

//识别
int __cdecl ocr(void* engine, Mat* image, char* msg, char** ocr_result, int* ocr_result_len) {
if (engine == nullptr)
 {
  strcpy_s(msg, 128, "engine is nullptr");
return -1;
 }

 PPOCR* _engine = (PPOCR*)engine;

 //auto start = std::chrono::steady_clock::now();
 std::vector<OCRPredictResult> OCRPredictResult = _engine->ocr(*image, true, true, FLAGS_cls);
 //auto end = std::chrono::steady_clock::now();
 //std::chrono::duration<double, std::milli> duration = end - start;
 //std::cout << "ocr识别耗时 : " << duration.count() << " ms" << std::endl;

 //返回json格式
 json array = json::array();
for (int i = 0; i < OCRPredictResult.size(); i++) {
  json texts = {};

  texts["text"] = OCRPredictResult[i].text;
  texts["score"] = OCRPredictResult[i].score;

  texts["x1"] = OCRPredictResult[i].box[0][0];
  texts["y1"] = OCRPredictResult[i].box[0][1];

  texts["x2"] = OCRPredictResult[i].box[1][0];
  texts["y2"] = OCRPredictResult[i].box[1][1];

  texts["x3"] = OCRPredictResult[i].box[2][0];
  texts["y3"] = OCRPredictResult[i].box[2][1];

  texts["x4"] = OCRPredictResult[i].box[3][0];
  texts["y4"] = OCRPredictResult[i].box[3][1];

  array.push_back(texts);
 }

 std::string json_str = array.dump();
 *ocr_result_len = (int)json_str.size();
 *ocr_result = (char*)CoTaskMemAlloc(*ocr_result_len + 1);
 strcpy_s(*ocr_result, *ocr_result_len + 1, json_str.c_str());

 strcpy_s(msg, 128, "ocr success");
return 0;
}

//释放
int __cdecl destroy(void* engine, char* msg) {
if (engine != nullptr)
 {
  PPOCR* _engine = (PPOCR*)engine;
  delete _engine;
  _engine = nullptr;
  strcpy_s(msg, 128, "destroy success");
return 0;
 }
else
 {
  strcpy_s(msg, 128, "engine is nullptr");
return -1;
 }
}

//structure
int __cdecl structure_init(void** engine

 , int cpu_threads
 , bool enable_mkldnn

 , char* det_model_dir
 , int limit_side_len
 , double det_db_thresh
 , double det_db_box_thresh
 , double det_db_unclip_ratio
 , bool use_dilation

 , bool cls
 , bool use_angle_cls
 , char* cls_model_dir
 , double cls_thresh
 , double cls_batch_num

 , char* rec_model_dir
 , char* rec_char_dict_path
 , int rec_batch_num
 , int rec_img_h
 , int rec_img_w

 , int table_max_len
 , int table_batch_num
 , char* table_model_dir
 , char* table_char_dict_path


 , char* msg) {

 try {

  FLAGS_cpu_threads = cpu_threads;
  FLAGS_enable_mkldnn = enable_mkldnn;
  FLAGS_visualize = false;

  //det 
  FLAGS_det_model_dir = det_model_dir;
  FLAGS_limit_side_len = limit_side_len;
  FLAGS_det_db_thresh = det_db_thresh;
  FLAGS_det_db_box_thresh = det_db_box_thresh;
  FLAGS_det_db_unclip_ratio = det_db_unclip_ratio;
  FLAGS_use_dilation = use_dilation;

  //cls
  FLAGS_cls = cls;
  FLAGS_use_angle_cls = use_angle_cls;
  FLAGS_cls_model_dir = cls_model_dir;
  FLAGS_cls_thresh = cls_thresh;
  FLAGS_cls_batch_num = cls_batch_num;

  //rec
  FLAGS_rec_model_dir = rec_model_dir;
  FLAGS_rec_char_dict_path = rec_char_dict_path;
  FLAGS_rec_batch_num = rec_batch_num;
  FLAGS_rec_img_h = rec_img_h;
  FLAGS_rec_img_w = rec_img_w;


  FLAGS_table = true;
  FLAGS_table_model_dir = table_model_dir;
  FLAGS_table_char_dict_path = table_char_dict_path;
  FLAGS_table_max_len = table_max_len;
  FLAGS_table_batch_num = table_batch_num;

  PaddleStructure* _engine = new PaddleStructure();

  *engine = _engine;

  strcpy_s(msg, 128, "structure_init success");

return 0;
 }
 catch (...) {
  std::cout << "structure_init error" << std::endl;
  strcpy_s(msg, 128, "structure_init error");
return -1;
 }
}

//structure
int __cdecl structure(void* engine, Mat* image, char* msg, char** ocr_result, int* ocr_result_len) {

if (engine == nullptr)
 {
  strcpy_s(msg, 128, "structure engine is nullptr");
return -1;
 }

 PaddleStructure* _engine = (PaddleStructure*)engine;

 std::vector<StructurePredictResult> structure_results = _engine->structure(
  *image, FLAGS_layout, FLAGS_table, FLAGS_det && FLAGS_rec);

 json array = json::array();
for (size_t j = 0; j < structure_results.size(); ++j) {

  json structure = {};

  structure["type"] = structure_results[j].type;
  structure["x1"] = structure_results[j].box[0];
  structure["y1"] = structure_results[j].box[1];
  structure["x2"] = structure_results[j].box[2];
  structure["y2"] = structure_results[j].box[3];
  structure["confidence"] = structure_results[j].confidence;
  structure["res"] = structure_results[j].html;

  array.push_back(structure);
 }

 std::string json_str = array.dump();
 *ocr_result_len = (int)json_str.size();
 *ocr_result = (char*)CoTaskMemAlloc(*ocr_result_len + 1);
 strcpy_s(*ocr_result, *ocr_result_len + 1, json_str.c_str());

 strcpy_s(msg, 128, "structure success");
return 0;

}

//释放
int __cdecl structure_destroy(void* engine, char* msg) {
if (engine != nullptr)
 {
  PaddleStructure* _engine = (PaddleStructure*)engine;
  delete _engine;
  _engine = nullptr;
  strcpy_s(msg, 128, "structure destroy success");
return 0;
 }
else
 {
  strcpy_s(msg, 128, "structure engine is nullptr");
return -1;
 }
}

C#调用

using Newtonsoft.Json;

using OpenCvSharp;

using System;

using System.Collections.Generic;

using System.Diagnostics;

using System.Drawing;

using System.Runtime.InteropServices;

using System.Text;

using System.Windows.Forms;

namespace OCRV5Test

{

public partial class Form1 : Form

{

public Form1()

{

InitializeComponent();

}

const string DllName = "lw.PPOCRSharp.dll";

//初始化

DllImport(DllName, EntryPoint = "init", CallingConvention = CallingConvention.Cdecl)

public extern static int init(ref IntPtr engine

, int cpu_threads

, bool enable_mkldnn

, string det_model_dir

, int limit_side_len

, double det_db_thresh

, double det_db_box_thresh

, double det_db_unclip_ratio

, bool use_dilation

, bool cls

, bool use_angle_cls

, string cls_model_dir

, double cls_thresh

, double cls_batch_num

, string rec_model_dir

, string rec_char_dict_path

, int rec_batch_num

, int rec_img_h

, int rec_img_w

, StringBuilder msg);

//识别

DllImport(DllName, EntryPoint = "ocr", CallingConvention = CallingConvention.Cdecl)

public extern static int ocr(IntPtr engine, IntPtr image, StringBuilder msg, out IntPtr ocr_result, out int ocr_result_len);

//释放

DllImport(DllName, EntryPoint = "destroy", CallingConvention = CallingConvention.Cdecl)

public extern static int destroy(IntPtr engine, StringBuilder msg);

static IntPtr OCREngine;

private Bitmap bmp;

private String imgPath = null;

private List<OCRResult> ltOCRResult;

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

private StringBuilder OCRResultInfo = new StringBuilder();

private StringBuilder OCRResultAllInfo = new StringBuilder();

Pen pen = new Pen(Brushes.Red, 2f);

private void button1_Click(object sender, EventArgs e)

{

OpenFileDialog ofd = new OpenFileDialog();

ofd.Filter = fileFilter;

if (ofd.ShowDialog() == DialogResult.OK)

{

imgPath = ofd.FileName;

bmp = new Bitmap(imgPath);

pictureBox1.Image = bmp;

richTextBox1.Clear();

button2_Click(null, null);

}

}

private void button2_Click(object sender, EventArgs e)

{

if (imgPath == null)

{

return;

}

button1.Enabled = false;

button2.Enabled = false;

richTextBox1.Clear();

OCRResultInfo.Clear();

OCRResultAllInfo.Clear();

Application.DoEvents();

Mat img = new Mat(imgPath);

StringBuilder msgTemp = new StringBuilder(128);

StringBuilder ocrResultStr = new StringBuilder(1024 * 100);

Stopwatch stopwatch = new Stopwatch();

stopwatch.Start();

IntPtr strPtr;

int ocr_result_len = 0;

int res = ocr(OCREngine, img.CvPtr, msgTemp, out strPtr, out ocr_result_len);

byte[] buffer = new byte[ocr_result_len];

Marshal.Copy(strPtr, buffer, 0, ocr_result_len);

string ocr_result = Encoding.UTF8.GetString(buffer);

Marshal.FreeCoTaskMem(strPtr);

stopwatch.Stop();

double totalTime = stopwatch.Elapsed.TotalSeconds;

OCRResultAllInfo.AppendLine($"耗时: {totalTime:F2}s");

OCRResultAllInfo.AppendLine("---------------------------");

OCRResultInfo.AppendLine($"耗时: {totalTime:F2}s");

OCRResultInfo.AppendLine("---------------------------");

if (res == 0)

{

ltOCRResult = Newtonsoft.Json.JsonConvert.DeserializeObject<List<OCRResult>>(ocr_result);

OCRResultAllInfo.Append(JsonConvert.SerializeObject(ltOCRResult, Newtonsoft.Json.Formatting.Indented));

Graphics graphics = Graphics.FromImage(bmp);

foreach (OCRResult item in ltOCRResult)

{

OCRResultInfo.AppendLine(item.text);

System.Drawing.Point[] pt = new System.Drawing.Point[] {

new System.Drawing.Point(item.x1, item.y1)

, new System.Drawing.Point(item.x2, item.y2)

, new System.Drawing.Point(item.x3, item.y3)

, new System.Drawing.Point(item.x4, item.y4)

};

graphics.DrawPolygon(pen, pt);

}

graphics.Dispose();

if (checkBox1.Checked)

{

richTextBox1.Text = OCRResultAllInfo.ToString();

}

else

{

richTextBox1.Text = OCRResultInfo.ToString();

}

pictureBox1.Image = null;

pictureBox1.Image = bmp;

}

else

{

MessageBox.Show("识别失败," + msgTemp.ToString());

}

img.Release();

button1.Enabled = true;

button2.Enabled = true;

}

/// <summary>

/// 初始化

/// </summary>

/// <param name="sender"></param>

/// <param name="e"></param>

private void Form1_Load(object sender, EventArgs e)

{

radioButton1.Checked = true;

}

void LoadModel()

{

StringBuilder msgTemp = new StringBuilder(128);

string root_dir = Application.StartupPath + @"\inference";

int cpu_threads = 2 ;

bool enable_mkldnn = true;

string det_model_dir = "";

int limit_side_len = 960;

double det_db_thresh = 0.3;

double det_db_box_thresh = 0.6;

double det_db_unclip_ratio = 1.2;

bool use_dilation = false;

bool cls = false;

bool use_angle_cls = true;

string cls_model_dir = root_dir + @"\ch_ppocr_mobile_v2.0_cls_infer\";

double cls_thresh = 0.9;

int cls_batch_num = 1;

string rec_model_dir = "";

string rec_char_dict_path = root_dir + @"\ppocrv5_dict.txt";

int rec_batch_num = 1;

int rec_img_h = 48;

int rec_img_w = 320;

if (radioButton1.Checked)

{

det_model_dir = root_dir + @"\PP-OCRv5_mobile_det_infer\";

rec_model_dir = root_dir + @"\PP-OCRv5_mobile_rec_infer\";

}

else

{

det_model_dir = root_dir + @"\PP-OCRv5_server_det_infer\";

rec_model_dir = root_dir + @"\PP-OCRv5_server_rec_infer\";

}

int res = init(ref OCREngine

, cpu_threads

, enable_mkldnn

, det_model_dir

, limit_side_len

, det_db_thresh

, det_db_box_thresh

, det_db_unclip_ratio

, use_dilation

, cls

, use_angle_cls

, cls_model_dir

, cls_thresh

, cls_batch_num

, rec_model_dir

, rec_char_dict_path

, rec_batch_num

, rec_img_h

, rec_img_w

, msgTemp);

if (res == 0)

{

MessageBox.Show("模型加载成功!");

}

else

{

string msg = msgTemp.ToString();

MessageBox.Show("模型加载失败," + msg);

}

}

private void checkBox1_CheckedChanged(object sender, EventArgs e)

{

richTextBox1.Clear();

if (checkBox1.Checked)

{

richTextBox1.Text = OCRResultAllInfo.ToString();

}

else

{

richTextBox1.Text = OCRResultInfo.ToString();

}

}

private void radioButton1_CheckedChanged(object sender, EventArgs e)

{

RadioButton rb = sender as RadioButton;

if (rb != null && rb.Checked)

{

//MessageBox.Show("选中的是:" + rb.Text);

LoadModel();

}

}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)

{

StringBuilder msgTemp = new StringBuilder(128);

destroy(OCREngine, msgTemp);

}

}

}

复制代码
using Newtonsoft.Json;
using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;

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

        const string DllName = "lw.PPOCRSharp.dll";

        //初始化
        [DllImport(DllName, EntryPoint = "init", CallingConvention = CallingConvention.Cdecl)]
        public extern static int init(ref IntPtr engine
            , int cpu_threads
            , bool enable_mkldnn

            , string det_model_dir
            , int limit_side_len
            , double det_db_thresh
            , double det_db_box_thresh
            , double det_db_unclip_ratio
            , bool use_dilation

            , bool cls
            , bool use_angle_cls
            , string cls_model_dir
            , double cls_thresh
            , double cls_batch_num

            , string rec_model_dir
            , string rec_char_dict_path
            , int rec_batch_num
            , int rec_img_h
            , int rec_img_w

            , StringBuilder msg);

        //识别
        [DllImport(DllName, EntryPoint = "ocr", CallingConvention = CallingConvention.Cdecl)]
        public extern static int ocr(IntPtr engine, IntPtr image, StringBuilder msg, out IntPtr ocr_result, out int ocr_result_len);

        //释放
        [DllImport(DllName, EntryPoint = "destroy", CallingConvention = CallingConvention.Cdecl)]
        public extern static int destroy(IntPtr engine, StringBuilder msg);

        static IntPtr OCREngine;

        private Bitmap bmp;

        private String imgPath = null;

        private List<OCRResult> ltOCRResult;

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

        private StringBuilder OCRResultInfo = new StringBuilder();
        private StringBuilder OCRResultAllInfo = new StringBuilder();

        Pen pen = new Pen(Brushes.Red, 2f);

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                imgPath = ofd.FileName;
                bmp = new Bitmap(imgPath);
                pictureBox1.Image = bmp;
                richTextBox1.Clear();

                button2_Click(null, null);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (imgPath == null)
            {
                return;
            }
            button1.Enabled = false;
            button2.Enabled = false;
            richTextBox1.Clear();
            OCRResultInfo.Clear();
            OCRResultAllInfo.Clear();

            Application.DoEvents();
            Mat img = new Mat(imgPath);
            StringBuilder msgTemp = new StringBuilder(128);
            StringBuilder ocrResultStr = new StringBuilder(1024 * 100);

            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();

            IntPtr strPtr;
            int ocr_result_len = 0;

            int res = ocr(OCREngine, img.CvPtr, msgTemp, out strPtr, out ocr_result_len);
            byte[] buffer = new byte[ocr_result_len];
            Marshal.Copy(strPtr, buffer, 0, ocr_result_len);
            string ocr_result = Encoding.UTF8.GetString(buffer);
            Marshal.FreeCoTaskMem(strPtr);
            stopwatch.Stop();
            double totalTime = stopwatch.Elapsed.TotalSeconds;

            OCRResultAllInfo.AppendLine($"耗时: {totalTime:F2}s");
            OCRResultAllInfo.AppendLine("---------------------------");

            OCRResultInfo.AppendLine($"耗时: {totalTime:F2}s");
            OCRResultInfo.AppendLine("---------------------------");

            if (res == 0)
            {

                ltOCRResult = Newtonsoft.Json.JsonConvert.DeserializeObject<List<OCRResult>>(ocr_result);
                OCRResultAllInfo.Append(JsonConvert.SerializeObject(ltOCRResult, Newtonsoft.Json.Formatting.Indented));
                Graphics graphics = Graphics.FromImage(bmp);

                foreach (OCRResult item in ltOCRResult)
                {
                    OCRResultInfo.AppendLine(item.text);
                    System.Drawing.Point[] pt = new System.Drawing.Point[] {
                              new System.Drawing.Point(item.x1, item.y1)
                            , new System.Drawing.Point(item.x2, item.y2)
                            , new System.Drawing.Point(item.x3, item.y3)
                            , new System.Drawing.Point(item.x4, item.y4)
                        };
                    graphics.DrawPolygon(pen, pt);
                }
                graphics.Dispose();

                if (checkBox1.Checked)
                {
                    richTextBox1.Text = OCRResultAllInfo.ToString();
                }
                else
                {
                    richTextBox1.Text = OCRResultInfo.ToString();
                }

                pictureBox1.Image = null;
                pictureBox1.Image = bmp;
            }
            else
            {
                MessageBox.Show("识别失败," + msgTemp.ToString());
            }

            img.Release();
            button1.Enabled = true;
            button2.Enabled = true;
        }

        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            radioButton1.Checked = true;
        }

        void LoadModel()
        {

            StringBuilder msgTemp = new StringBuilder(128);
            string root_dir = Application.StartupPath + @"\inference";

            int cpu_threads = 2 ;
            bool enable_mkldnn = true;

            string det_model_dir = "";
            int limit_side_len = 960;
            double det_db_thresh = 0.3;
            double det_db_box_thresh = 0.6;
            double det_db_unclip_ratio = 1.2;
            bool use_dilation = false;

            bool cls = false;
            bool use_angle_cls = true;
            string cls_model_dir = root_dir + @"\ch_ppocr_mobile_v2.0_cls_infer\";
            double cls_thresh = 0.9;
            int cls_batch_num = 1;

            string rec_model_dir = "";
            string rec_char_dict_path = root_dir + @"\ppocrv5_dict.txt";
            int rec_batch_num = 1;
            int rec_img_h = 48;
            int rec_img_w = 320;

            if (radioButton1.Checked)
            {
                det_model_dir = root_dir + @"\PP-OCRv5_mobile_det_infer\";
                rec_model_dir = root_dir + @"\PP-OCRv5_mobile_rec_infer\";
            }
            else
            {
                det_model_dir = root_dir + @"\PP-OCRv5_server_det_infer\";
                rec_model_dir = root_dir + @"\PP-OCRv5_server_rec_infer\";
            }
            int res = init(ref OCREngine
                        , cpu_threads
                        , enable_mkldnn

                        , det_model_dir
                        , limit_side_len
                        , det_db_thresh
                        , det_db_box_thresh
                        , det_db_unclip_ratio
                        , use_dilation

                        , cls
                        , use_angle_cls
                        , cls_model_dir
                        , cls_thresh
                        , cls_batch_num

                        , rec_model_dir
                        , rec_char_dict_path
                        , rec_batch_num
                        , rec_img_h
                        , rec_img_w

                        , msgTemp);

            if (res == 0)
            {
                MessageBox.Show("模型加载成功!");
            }
            else
            {
                string msg = msgTemp.ToString();
                MessageBox.Show("模型加载失败," + msg);
            }
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            if (checkBox1.Checked)
            {
                richTextBox1.Text = OCRResultAllInfo.ToString();
            }
            else
            {
                richTextBox1.Text = OCRResultInfo.ToString();
            }
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rb = sender as RadioButton;
            if (rb != null && rb.Checked)
            {
                //MessageBox.Show("选中的是:" + rb.Text);
                LoadModel();
            }
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            StringBuilder msgTemp = new StringBuilder(128);
            destroy(OCREngine, msgTemp);
        }
    }

}

下载

https://download.csdn.net/download/lw112190/90909238

或者

复制代码
PP-OCRv5 Test C#调用完整项目源码.rar
链接: https://pan.baidu.com/s/10wU15EkkxFy7wxxmsi61EQ?pwd=n79z 提取码: n79z
相关推荐
姬公子521几秒前
leetcode hot100刷题日记——29.合并两个有序链表
c++·leetcode·链表
goldfishsky7 分钟前
elasticsearch
开发语言·数据库·python
菜一头包32 分钟前
CPP中CAS std::chrono 信号量与Any类的手动实现
开发语言·c++
new出对象39 分钟前
C++ 中的函数包装:std::bind()、std::function<>、函数指针与 Lambda
开发语言·c++·算法
宁静祥和----------44 分钟前
编码总结如下
c++
zhifanxu44 分钟前
android协程异步编程常用方法
android·开发语言·kotlin
江节胜-胜行全栈AI1 小时前
Java-代码段-http接口调用自身服务中的其他http接口(mock)-并建立socket连接发送和接收报文实例
java·开发语言·http
理论最高的吻1 小时前
面试题 08.08. 有重复字符串的排列组合【 力扣(LeetCode) 】
c++·算法·leetcode·深度优先·回溯法
whoarethenext2 小时前
c/c++的opencv霍夫变换
c语言·c++·opencv
猛犸MAMMOTH2 小时前
Python打卡第40天
开发语言·python·机器学习