提交 | 用户 | age
|
4b03ae
|
1 |
#pragma once
|
Q |
2 |
#include "../ImageFunc/ImageFunc.h"
|
|
3 |
enum enumGrabResult
|
|
4 |
{
|
|
5 |
GrabUndenfined=-1,
|
|
6 |
GrabOK=0
|
|
7 |
};
|
|
8 |
enum eCameraResult
|
|
9 |
{
|
|
10 |
CameraError=-1,
|
|
11 |
CameraOk=0,
|
|
12 |
};
|
|
13 |
typedef struct stMyCameraInfo
|
|
14 |
{
|
|
15 |
unsigned char camIp[4]; //!<相机的IP地址
|
|
16 |
unsigned char camMac[6]; //!<相机的MAC地址
|
|
17 |
unsigned char ifIp[4]; //!<计算机和相机连接的网卡IP地址
|
|
18 |
unsigned char ifMac[6]; //!<计算机和相机连接的网卡MAC地址
|
|
19 |
char mMfgName[32]; //!<相机厂商名称
|
|
20 |
char mModelName[32]; //!<相机型号
|
|
21 |
char mSerialNumber[16]; //!<相机序列号
|
|
22 |
char mUserDefinedName[16]; //!<用户设置的相机名称
|
|
23 |
CString sMfgName;
|
|
24 |
CString sModelName;
|
|
25 |
CString sSerialNumber;
|
|
26 |
CString sUserDefinedName;
|
|
27 |
|
|
28 |
stMyCameraInfo()
|
|
29 |
{
|
|
30 |
memset(camIp,0,sizeof(camIp));
|
|
31 |
memset(camMac,0,sizeof(camMac));
|
|
32 |
memset(ifIp,0,sizeof(ifIp));
|
|
33 |
memset(ifMac,0,sizeof(ifMac));
|
|
34 |
memset(mMfgName,0,sizeof(mMfgName));
|
|
35 |
memset(mModelName,0,sizeof(mModelName));
|
|
36 |
memset(mSerialNumber,0,sizeof(mSerialNumber));
|
|
37 |
memset(mUserDefinedName,0,sizeof(mUserDefinedName));
|
|
38 |
sMfgName = _T("");
|
|
39 |
sModelName = _T("");
|
|
40 |
sSerialNumber = _T("");
|
|
41 |
sUserDefinedName = _T("");
|
|
42 |
};
|
|
43 |
}MyCameraInfo;
|
|
44 |
|
|
45 |
|
|
46 |
class MyCamera
|
|
47 |
{
|
|
48 |
public:
|
|
49 |
MyCamera(void);
|
|
50 |
~MyCamera(void);
|
|
51 |
private:
|
|
52 |
|
|
53 |
public:
|
|
54 |
int Idx; //相机在所有相机列表里的下标
|
|
55 |
int m_IsCameraOpened; //相机是否已经打开
|
|
56 |
int m_nWidth; //相机图像宽度
|
|
57 |
int m_nHeight; //相机图像高度
|
|
58 |
int m_XOffset; //
|
|
59 |
int m_YOffset;
|
|
60 |
int m_ROIWidth; //ROI区域宽度
|
|
61 |
int m_ROIHeight; //ROI区域高度
|
|
62 |
int m_PixelFormat;
|
|
63 |
|
|
64 |
int m_nWaitTime; //等待相机超时时间;
|
|
65 |
|
|
66 |
MyImage Image1;
|
|
67 |
CString ResultStr;
|
|
68 |
|
|
69 |
virtual int GetCameraCount(){return 0;};
|
|
70 |
virtual int GetCameraInfo(int index, MyCameraInfo * pMyCameraInfo){return CameraError;};
|
|
71 |
virtual int OpenCamera(int){return CameraError;};
|
|
72 |
virtual int CloseCamera(){return CameraError;};
|
|
73 |
virtual int GetCameraWidthHeight(int* Width, int * Height){return CameraError;};
|
|
74 |
virtual int GetCameraPixelFormat(){return CameraError;};
|
|
75 |
virtual int SetCameraPixelFormat(int *PixelFormat){return CameraError;};
|
|
76 |
virtual int GetExposureTime(double *ExposureTime){return CameraError;};
|
|
77 |
virtual int SetExposureTime(double ExposureTime1){return CameraError;};
|
|
78 |
|
|
79 |
virtual int GetWidth(int *Width){return CameraError;}
|
|
80 |
virtual int GetWidthRange(int *WidthMin,int *WidthMax){return CameraError;};
|
|
81 |
virtual int GetWidthInc(int *WidthInc){return CameraError;};
|
|
82 |
virtual int GetWidthRangeInc(int *WidthMin,int *WidthMax,int *WidthInc)
|
|
83 |
{
|
|
84 |
if (GetWidthRange(WidthMin,WidthMax)==CameraOk&&GetWidthInc(WidthInc)==CameraOk)
|
|
85 |
return CameraOk;
|
|
86 |
else return CameraError;
|
|
87 |
}
|
|
88 |
virtual int SetWidth(int nWidth){return CameraError;}
|
|
89 |
|
|
90 |
virtual int GetHeight(int *Height){return CameraError;}
|
|
91 |
virtual int GetHeightRange(int *HeightMin, int *HeightMax){return CameraError;};
|
|
92 |
virtual int GetHeightInc(int *HeightInc){return CameraError;};
|
|
93 |
virtual int GetHeightRangeInc(int *HeightMin, int *HeightMax, int *HeightInc)
|
|
94 |
{
|
|
95 |
if (GetHeightRange(HeightMin,HeightMax)==CameraOk&&GetHeightInc(HeightInc)==CameraOk)
|
|
96 |
return CameraOk;
|
|
97 |
else return CameraError;
|
|
98 |
}
|
|
99 |
virtual int SetHeight(int nHeight){return CameraError;}
|
|
100 |
|
|
101 |
virtual int GetOffsetXRange(int *OffsetXMin,int *OffsetXMax){return CameraError;};
|
|
102 |
virtual int GetOffsetYRange(int *OffsetYMin,int *OffsetYMax){return CameraError;};
|
|
103 |
virtual int GetOffsetX(int *OffsetX){return CameraError;}
|
|
104 |
virtual int GetOffsetY(int *OffsetY){return CameraError;}
|
|
105 |
virtual int GetOffsetXY(int *OffsetX, int *OffsetY){return CameraError;};
|
|
106 |
|
|
107 |
virtual int SetOffsetX(int nOffsetX){return CameraError;}
|
|
108 |
virtual int SetOffsetY(int nOffsetY){return CameraError;}
|
|
109 |
virtual int SetROI(int nOffsetX,int nOffsetY,int nWidth,int nHeight){return CameraError;};
|
|
110 |
|
|
111 |
virtual int GetGain(double *Gain){return CameraError;};
|
|
112 |
virtual int GetGainRange(double *GainMin,double *GainMax) {return CameraError;};
|
|
113 |
virtual int SetGain(double Gain){return CameraError;};
|
|
114 |
|
|
115 |
virtual int GetGamma(double *gamma){return CameraError;};
|
|
116 |
virtual int GetGammaRange(double *gammaMin,double *gammaMax){return CameraError;};
|
|
117 |
virtual int SetGamma(double gamma){return CameraError;};
|
|
118 |
|
|
119 |
virtual int GetLUTEnable(int *bIsEnable){return CameraError;};
|
|
120 |
virtual int SetLUTEnable(int bIsEnable){return CameraError;};
|
|
121 |
virtual int SetLUT(int *pBuf,int nCount){return CameraError;};
|
|
122 |
|
|
123 |
virtual int SetSim(CString sLangFileName, int pixeltype, int w=0, int h=0){return CameraError;};
|
|
124 |
|
|
125 |
virtual int StartGrab(){return CameraError;};
|
|
126 |
virtual int StopGrab(){return CameraError;};
|
|
127 |
virtual int WaitForGrabFinish(int nTimeWait=500){return CameraError;};
|
|
128 |
virtual int FetchImageData(){return CameraError;};
|
|
129 |
|
|
130 |
int GrabOne(int nWaitTime=1000)
|
|
131 |
{
|
|
132 |
if (m_IsCameraOpened)
|
|
133 |
{
|
|
134 |
int j;
|
|
135 |
ResultStr.Empty();
|
|
136 |
double time1=GetTickCountmS();
|
|
137 |
Image1.Clear();
|
|
138 |
|
|
139 |
j=StartGrab();
|
|
140 |
double time2=GetTickCountmS();
|
|
141 |
if (j!=CameraOk) {ResultStr.AppendFormat(_T("拍照失败 %.1fmS"),time2-time1);return j;}
|
|
142 |
|
|
143 |
j=WaitForGrabFinish(nWaitTime);
|
|
144 |
double time3=GetTickCountmS();
|
|
145 |
if (j!=CameraOk) {ResultStr.AppendFormat(_T("等待超时 %.1fmS 总时 %.1fmS"),time3-time2,time3-time1);return j;}
|
|
146 |
|
|
147 |
j=FetchImageData();
|
|
148 |
double time4=GetTickCountmS();
|
|
149 |
if (j!=CameraOk) {ResultStr.AppendFormat(_T("获取数据失败 %.1fmS 总时 %.1fmS"),time4-time3,time4-time1);return j;}
|
|
150 |
|
|
151 |
ResultStr.AppendFormat(_T("拍照 %.1fmS 等待 %.1fms 取数据 %.1fmS 总时间 %.1fmS"),time2-time1,time3-time2,time4-time3,time4-time1);
|
|
152 |
return CameraOk;
|
|
153 |
}
|
|
154 |
else
|
|
155 |
{
|
|
156 |
ResultStr.Format(_T("拍照失败 相机未打开"));
|
|
157 |
return CameraError;
|
|
158 |
}
|
|
159 |
return CameraError;
|
|
160 |
}
|
|
161 |
};
|
|
162 |
|
|
163 |
class MySimCamera : public MyCamera
|
|
164 |
{
|
|
165 |
public:
|
|
166 |
MySimCamera();
|
|
167 |
~MySimCamera();
|
|
168 |
MySimCamera(CString);
|
|
169 |
|
|
170 |
CString ImageFilePathName; //模拟运行文件路径和通配符
|
|
171 |
CString CurFilePathName;
|
|
172 |
int nTotalImageFileCount;
|
|
173 |
int nCurImageFileIndex;
|
|
174 |
|
|
175 |
int InitLib(){return CameraOk;};
|
|
176 |
int GetCameraCount(){return 1;};
|
|
177 |
int OpenCamera(int);
|
|
178 |
int CloseCamera();
|
|
179 |
int GetCameraWidthHeight(int* nWidth, int * nHeight)
|
|
180 |
{
|
|
181 |
*nWidth=m_nWidth;
|
|
182 |
*nHeight=m_nHeight;
|
|
183 |
return CameraOk;
|
|
184 |
}
|
|
185 |
int GetCameraPixelFormat(){return m_PixelFormat;};
|
|
186 |
int SetExposureTime(double ExposeTime1);
|
|
187 |
int SetGain(double Gain){return CameraOk;};
|
|
188 |
int SetROI(int nOffsetX,int nOffsetY,int nWidth,int nHeight)
|
|
189 |
{
|
|
190 |
return CameraOk;
|
|
191 |
}
|
|
192 |
|
|
193 |
int StartGrab();
|
|
194 |
int StopGrab();
|
|
195 |
int WaitForGrabFinish(int nTimeWait);
|
|
196 |
int FetchImageData();
|
|
197 |
|
|
198 |
int SetSim(CString sFilePathName, int pixeltype, int w=0, int h=0);
|
|
199 |
int GetNextFilePathName();
|
|
200 |
|
|
201 |
}; |