PaddleHelper.cs 2.1 KB
using log4net;
using log4net.Core;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace paddleOCR
{
    public class PaddleHelper
    {
        public static void Init()
        {
            int code = VisionAPI.eyemInitNNDetector("", ".//yolact_base_169_14550_interrupt.onnx", 550, 550);
            VisionAPI.log.Info($"初始化检测器 rtnCode={code}");
            VisionAPI.eyemNNDetectorParams(0.15f, 0.45f);
            VisionAPI.log.Info($"设置检测参数,{0.15f},{0.45f}");
            PaddleSharpAPI.Init();
        }

        [HandleProcessCorruptedStateExceptions]
        public static string StartCPlusOcr(string imgPath)
        {
            string result = "";
            try
            {
                PaddleSharpAPI.OCRHandle(imgPath, out result);
            }
            catch (Exception ex)
            {
                VisionAPI.log.Error("StartCPlusOcr err",ex);
            }
            finally
            {

            }
            return result;
        }

        [HandleProcessCorruptedStateExceptions]
        public static string StartCPlusOcrRewrite(string imgPath)
        {
            string result = "";
            try
            {
                PaddleSharpAPI.OCRHandleRewrite(imgPath, out result);
            }
            catch (Exception ex)
            {
                VisionAPI.log.Error("StartCPlusOcr err", ex);
            }
            finally
            {

            }
            return result;
        }
        static List<T> DeserializeJsonToList<T>(string json) where T : class
        {
            JsonSerializer serializer = new JsonSerializer();
            StringReader sr = new StringReader(json);
            object o = serializer.Deserialize(new JsonTextReader(sr), typeof(List<T>));
            List<T> list = o as List<T>;
            return list;
        }
    }
}