Eyem_RegionAPI.cs
3.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
namespace CameraVisionLib.Model
{
internal static class RegionAPI
{
[DllImport(@".\EyemLib\eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemTrackFeature(EyemImage tpRefImg, EyemImage tpNextImg, IntPtr tpArray, int iArraySize, IntPtr ipResults, out EyemImage tpDstImg);
[DllImport(@".\EyemLib\eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemInitNNDetector(string detectorConfigPath, string detectorModelPath);
[DllImport(@".\EyemLib\eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemNNDetector(EyemImage tpImage, out int ipNum, ref BboxContainer container);
internal static IntPtr StructArray2IntPtr<T>(T[] tpArray)
{
IntPtr ptr = Marshal.AllocHGlobal(checked(Marshal.SizeOf(typeof(T)) * tpArray.Length));
for (int index = 0; index < tpArray.Length; index++)
Marshal.StructureToPtr(tpArray[index], (IntPtr)(checked((long)ptr + index * Marshal.SizeOf(typeof(T)))), false);
return ptr;
}
[StructLayout(LayoutKind.Sequential)]
internal struct EyemImage
{
public IntPtr Handle;
public int Width;
public int Height;
public int Depth;
public int Channel;
/*
iDepth:
uint8_t 取值范围[0, 255], iDepth = 0(常用,解码图像一般为此种格式)
int8_t 取值范围[-128, 127], iDepth = 1
uint16_t 取值范围[0, 56635], iDepth = 2(常用,点料机图像一般为此种格式)
int16_t 取值范围[-32768, 32767], iDepth = 3
int32_t 取值范围[-2147483648, 2147483647], iDepth = 4
float_t 取值范围[-3.4028235E38, 3.4028235E38], iDepth = 5
double_t 取值范围[-1.7E-308, 1.7E+308], iDepth = 6
iChannels:
彩色 rgb iChannels=3 argb iChannels=4
灰度 iChannels=1
*/
}
[StructLayout(LayoutKind.Sequential)]
internal struct EyemRegion
{
public int X;
public int Y;
public int Width;
public int Height;
public double Ratio; //变化比例
}
[StructLayout(LayoutKind.Sequential)]
internal struct EyemRect
{
public int iXs; // 起始点(左上角) x 坐标
public int iYs; // 起始点(左上角) y 坐标
public int iWidth; // x 方向大小(宽度)
public int iHeight; // y 方向大小(高度)
}
[StructLayout(LayoutKind.Sequential)]
internal struct BboxContainer
{
//最多支持100个目标
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 100)]
public EyemRect[] bboxes;
}
}
}