237 lines
8.0 KiB
C#
237 lines
8.0 KiB
C#
|
|
|||
|
using OpenCvSharp;
|
|||
|
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Drawing;
|
|||
|
using System.Runtime.InteropServices;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public class XKHisence
|
|||
|
{
|
|||
|
public int Number;
|
|||
|
public string ?Type;
|
|||
|
public string ?OcrBar;
|
|||
|
|
|||
|
public int MoveX;
|
|||
|
public int MoveY;
|
|||
|
public int MoveZ;
|
|||
|
public string ?Detect;
|
|||
|
public string ?OcrText;
|
|||
|
public int MoveTwoX;
|
|||
|
public int MoveTwoY;
|
|||
|
public int MoveTwoZ;
|
|||
|
public string ?OcrParm;
|
|||
|
public string ?Language;
|
|||
|
public XKHisence()
|
|||
|
{
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public XKHisence(String type,string ocrBar,int MoveX,int MoveY,int MoveZ,string Detect,string ocrText,int MoveTwoX,int MoveTwoY,int MoveTwoZ,string OcrParm,string Language)
|
|||
|
{
|
|||
|
this.Type = type;
|
|||
|
this.OcrBar = ocrBar;
|
|||
|
this.MoveX = MoveX;
|
|||
|
this.MoveY = MoveY;
|
|||
|
this.MoveZ= MoveZ;
|
|||
|
this.Detect = Detect;
|
|||
|
this.OcrText= ocrText;
|
|||
|
this.MoveTwoX = MoveTwoX;
|
|||
|
this.MoveTwoY = MoveTwoY;
|
|||
|
this.MoveTwoZ = MoveTwoZ;
|
|||
|
this.OcrParm = OcrParm;
|
|||
|
this.Language = Language;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
public class MLRequest
|
|||
|
{
|
|||
|
public int ImageChannels = 3;
|
|||
|
public Mat currentMat;
|
|||
|
public int ResizeWidth;
|
|||
|
public int ResizeHeight;
|
|||
|
|
|||
|
public float confThreshold;
|
|||
|
|
|||
|
public float iouThreshold;
|
|||
|
|
|||
|
//public int ImageResizeCount;
|
|||
|
|
|||
|
public string in_node_name;
|
|||
|
|
|||
|
public string out_node_name;
|
|||
|
|
|||
|
public string in_lable_path;
|
|||
|
|
|||
|
public int ResizeImageSize;
|
|||
|
public int segmentWidth;
|
|||
|
public int ImageWidth;
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
public float Score;
|
|||
|
|
|||
|
}
|
|||
|
public class DetectionResultDetail
|
|||
|
{
|
|||
|
public string LabelBGR { get; set; }//识别到对象的标签BGR
|
|||
|
|
|||
|
|
|||
|
public int LabelNo { get; set; } // 识别到对象的标签索引
|
|||
|
|
|||
|
public string LabelName { get; set; }//识别到对象的标签名称
|
|||
|
|
|||
|
public double Score { get; set; }//识别目标结果的可能性、得分
|
|||
|
|
|||
|
public string LabelDisplay { get; set; }//识别到对象的 显示信息
|
|||
|
|
|||
|
public double Area { get; set; }//识别目标的区域面积
|
|||
|
|
|||
|
public Rectangle Rect { get; set; }//识别目标的外接矩形
|
|||
|
|
|||
|
public RotatedRect MinRect { get; set; }//识别目标的最小外接矩形(带角度)
|
|||
|
|
|||
|
//public ResultState InferenceResult { get; set; }//只是模型推理 label的结果
|
|||
|
|
|||
|
public double DistanceToImageCenter { get; set; } //计算矩形框到图像中心的距离
|
|||
|
|
|||
|
|
|||
|
|
|||
|
// public ResultState FinalResult { get; set; }//模型推理+其他视觉、逻辑判断后 label结果
|
|||
|
}
|
|||
|
public class MLResult
|
|||
|
{
|
|||
|
public bool IsSuccess = false;
|
|||
|
public string ResultMessage;
|
|||
|
public Bitmap ResultMap;
|
|||
|
public List<DetectionResultDetail> ResultDetails = new List<DetectionResultDetail>();
|
|||
|
|
|||
|
}
|
|||
|
public class MLResultModel
|
|||
|
{
|
|||
|
public bool IsSuccess = false;
|
|||
|
public string ResultMessage;
|
|||
|
public Bitmap ResultMap;
|
|||
|
public List<DetectionResultDetail> ResultDetails = new List<DetectionResultDetail>();
|
|||
|
public string WashMachineBar;
|
|||
|
public string WashMachineBatch;
|
|||
|
public string WashMachineSN;
|
|||
|
public string WashMachineLanguage;
|
|||
|
}
|
|||
|
public static class MLEngine
|
|||
|
{
|
|||
|
|
|||
|
//private const string sPath = @"D:\\C#\磁环项目\\OpenVinoYolo\\openvino_Yolov5_v7_v2.0\\openvino_Yolov5_v7\\Program\ConsoleProject\\x64\\Release\\QuickSegmentDynamic.dll";
|
|||
|
|
|||
|
|
|||
|
[DllImport("QuickSegmentDynamic.dll", EntryPoint = "InitModel")]
|
|||
|
public static extern IntPtr InitModel(string model_filename, string inferenceDevice, string input_node_name, int bacth, int inferenceChannels, int InferenceWidth, int InferenceHeight);
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 分割
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <param name="img"></param>
|
|||
|
/// <param name="W"></param>
|
|||
|
/// <param name="H"></param>
|
|||
|
/// <param name="C"></param>
|
|||
|
/// <param name="labelText"></param>
|
|||
|
/// <param name="conf_threshold"></param>
|
|||
|
/// <param name="IOU_THRESHOLD"></param>
|
|||
|
/// <param name="fScoreThre"></param>
|
|||
|
/// <param name="segmentWidth"></param>
|
|||
|
/// <param name="Mask_output"></param>
|
|||
|
/// <param name="label"></param>
|
|||
|
/// <returns></returns>
|
|||
|
[DllImport("QuickSegmentDynamic.dll", EntryPoint = "seg_ModelPredict")]
|
|||
|
|
|||
|
public static extern bool seg_ModelPredict(IntPtr model, byte[] img, int W, int H, int C,
|
|||
|
string labelText, float conf_threshold, float IOU_THRESHOLD, float fScoreThre, int segmentWidth,
|
|||
|
ref byte Mask_output, ref byte label);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 目标检测
|
|||
|
/// </summary>
|
|||
|
/// <param name="model"></param>
|
|||
|
/// <param name="img"></param>
|
|||
|
/// <param name="W"></param>
|
|||
|
/// <param name="H"></param>
|
|||
|
/// <param name="C"></param>
|
|||
|
/// <param name="nodes"></param>
|
|||
|
/// <param name="labelText"></param>
|
|||
|
/// <param name="conf_threshold"></param>
|
|||
|
/// <param name="IOU_THRESHOLD"></param>
|
|||
|
/// <param name="Mask_output"></param>
|
|||
|
/// <param name="label"></param>
|
|||
|
[DllImport("QuickSegmentDynamic.dll", EntryPoint = "det_ModelPredict")]
|
|||
|
public static extern bool det_ModelPredict(IntPtr model, byte[] img, int W, int H, int C,
|
|||
|
string nodes,// ++++++++++++++++++++++++++++++++++++
|
|||
|
string labelText, float conf_threshold, float IOU_THRESHOLD,
|
|||
|
ref byte Mask_output, ref byte label);
|
|||
|
|
|||
|
|
|||
|
[DllImport("QuickSegmentDynamic.dll", EntryPoint = "FreePredictor")]
|
|||
|
public static extern void FreePredictor(IntPtr model);
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
public static class OcrEngine
|
|||
|
{
|
|||
|
|
|||
|
// private const string sPath = @"F:\OOOCR\PaddleOCRsourcecodeGPU\PROJECTS\OcrDetForm\bin\Release\net7.0-windows\ocrInference.dll";
|
|||
|
|
|||
|
|
|||
|
|
|||
|
[DllImport("ocrInference.dll", EntryPoint = "InitModel")]
|
|||
|
public static extern IntPtr InitModel(string model_ParaPath, string device_id);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
[DllImport("ocrInference.dll", EntryPoint = "Inference")]
|
|||
|
public static extern bool Inference(IntPtr model, byte[] img, int W, int H, int C,
|
|||
|
|
|||
|
ref byte Mask_output, ref byte label);
|
|||
|
|
|||
|
|
|||
|
[DllImport("ocrInference.dll", EntryPoint = "FreePredictor")]
|
|||
|
public static extern void FreePredictor(IntPtr model);
|
|||
|
}
|
|||
|
public static class MLEngine1
|
|||
|
{
|
|||
|
/**********************************************************************/
|
|||
|
/***************** 1.推理DLL导入实现 ****************/
|
|||
|
/**********************************************************************/
|
|||
|
//private const string sPath = @"D:\M018_NET7.0\src\Debug\model_infer.dll";
|
|||
|
// 加载推理相关方法
|
|||
|
[DllImport("model_infer.dll", EntryPoint = "InitModel")] // 模型统一初始化方法: 需要yml、pdmodel、pdiparams
|
|||
|
//[DllImport(sPath, EntryPoint = "InitModel")] // 模型统一初始化方法: 需要yml、pdmodel、pdiparams
|
|||
|
public static extern IntPtr InitModel(string model_type, string model_filename, string params_filename, string cfg_file, bool use_gpu, int gpu_id, ref byte paddlex_model_type);
|
|||
|
|
|||
|
[DllImport("model_infer.dll", EntryPoint = "Det_ModelPredict")] // PaddleDetection模型推理方法
|
|||
|
public static extern bool Det_ModelPredict(IntPtr model, byte[] img, int W, int H, int C, IntPtr output, int[] BoxesNum, ref byte label);
|
|||
|
|
|||
|
[DllImport("model_infer.dll", EntryPoint = "Seg_ModelPredict")] // PaddleSeg模型推理方法
|
|||
|
public static extern bool Seg_ModelPredict(IntPtr model, byte[] img, int W, int H, int C, ref byte output);
|
|||
|
|
|||
|
[DllImport("model_infer.dll", EntryPoint = "Cls_ModelPredict")] // PaddleClas模型推理方法
|
|||
|
public static extern bool Cls_ModelPredict(IntPtr model, byte[] img, int W, int H, int C, ref float score, ref byte category, ref int category_id);
|
|||
|
|
|||
|
[DllImport("model_infer.dll", EntryPoint = "Mask_ModelPredict")] // Paddlex的MaskRCNN模型推理方法
|
|||
|
public static extern bool Mask_ModelPredict(IntPtr model, byte[] img, int W, int H, int C, IntPtr output, ref byte Mask_output, int[] BoxesNum, ref byte label);
|
|||
|
//public static extern bool Mask_ModelPredict(IntPtr model, IntPtr img, int W, int H, int C, IntPtr output, ref byte Mask_output, int[] BoxesNum, ref byte label);
|
|||
|
[DllImport("model_infer.dll", EntryPoint = "DestructModel")] // 分割、检测、识别模型销毁方法
|
|||
|
public static extern void DestructModel(IntPtr model);
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|