Eyem_BarcodeAPI.cs
3.9 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
using System;
using Microsoft.Win32.SafeHandles;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
namespace CameraVisionLib.Model
{
internal static unsafe class BarcodeAPI
{
[DllImport(@".\EyemLib\eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemDetectAndDecode(EyemImage tpImage, EyemRect tpRoi, string fileName, string strCodeType, out DataCodeHandle hObject, out EyemBarCode* tpResults, out int ipNum, bool bUseNiBlack, int iBlockSize, int iRangeC, int iSymbolMin, int iSymbolMax, double dScaleUpAndDown = 0.5, double dToleErr = 0.5, double dMinorStep = 1.0);
/// <summary>
/// 读取图像
/// </summary>
/// <param name="filename"></param>
/// <param name="iFalgs"></param>
/// <param name="ucpImage"></param>
/// <returns></returns>
[DllImport(@".\EyemLib\eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern int eyemImageRead(string filename, int iFalgs, out EyemImage ucpImage);
/// <summary>
/// 释放图像资源
/// </summary>
/// <param name="ipImage"></param>
[DllImport(@".\EyemLib\eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern void eyemImageFree(IntPtr ipImage);
/// <summary>
/// 释放工具
/// </summary>
/// <param name="hObject"></param>
/// <returns></returns>
[DllImport(@".\EyemLib\eyemLib.dll", CharSet = CharSet.None, CallingConvention = CallingConvention.Cdecl)]
internal static extern bool eyemDetectAndDecodeFree(IntPtr hObject);
internal class DataCodeHandle : SafeHandleZeroOrMinusOneIsInvalid
{
public DataCodeHandle() : base(true) { }
protected override bool ReleaseHandle()
{
return eyemDetectAndDecodeFree(handle);
}
}
[StructLayout(LayoutKind.Sequential)]
internal struct EyemImage
{
/// <summary>
/// 地址
/// </summary>
public IntPtr ucpImage;
/// <summary>
/// 图像内存 x 方向大小
/// </summary>
public int iWidth;
/// <summary>
/// 图像内存 y 方向大小
/// </summary>
public int iHeight;
/// <summary>
/// 图像通道数
/// </summary>
public int iChannel;
}
[StructLayout(LayoutKind.Sequential)]
internal struct EyemRect
{
/// <summary>
/// 起始点(左上角) x 坐标
/// </summary>
public int iXs;
/// <summary>
/// 起始点(左上角) y 坐标
/// </summary>
public int iYs;
/// <summary>
/// x 方向大小(宽度)
/// </summary>
public int iWidth;
/// <summary>
/// y 方向大小(高度)
/// </summary>
public int iHeight;
}
[StructLayout(LayoutKind.Sequential)]
internal struct EyemBarCode
{
/// <summary>
/// 角度
/// </summary>
public double dAngle;
/// <summary>
/// x坐标
/// </summary>
public int iCenterX;
/// <summary>
/// y坐标
/// </summary>
public int iCenterY;
/// <summary>
/// 码类型
/// </summary>
public IntPtr hType;
/// <summary>
/// 码内容
/// </summary>
public IntPtr hText;
}
}
}