LuJiaYi/Define.cs
2024-08-17 18:00:59 +08:00

166 lines
4.7 KiB
C#

using OpenCvSharp;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
public class LuJiaYi
{
// 使用属性而不是字段
public string Product { get; set; }
public int Num { get; set; }
public double Distance { get; set; }
public int Hole { get; set; }
public string Load { get; set; }
// 默认构造函数
public LuJiaYi()
{
}
// 带参数的构造函数
public LuJiaYi(string product, int num, double distance, int hole, string load)
{
Product = product;
Num = num;
Distance = distance;
Hole = hole;
Load = load;
}
}
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 MLRequest()
{
}
}
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 string JsonString { get; set; }
}
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 enum ResultState
{
[Description("检测NG")]
DetectNG = 0,
[Description("OK")]
OK = 1,
}