提交 | 用户 | age
|
4b03ae
|
1 |
#pragma once
|
Q |
2 |
#include "MyCameraBase.h"
|
|
3 |
#include "./MVS_SDK/MvCameraControl.h"
|
|
4 |
#include <gdiplus.h>
|
|
5 |
|
|
6 |
class MVSCamera : public MyCamera
|
|
7 |
{
|
|
8 |
public:
|
|
9 |
MVSCamera(void);
|
|
10 |
~MVSCamera(void);
|
|
11 |
|
|
12 |
private:
|
|
13 |
volatile static int TotalCameraCount;
|
|
14 |
|
|
15 |
public:
|
|
16 |
HANDLE m_hCam; //打开的相机句柄
|
|
17 |
|
|
18 |
UINT m_nFPS; //! 帧率
|
|
19 |
BOOL m_bTrigCont; //! 连续触发模式
|
|
20 |
int m_nTimeCostMax; //! 从发出触发指令到得到图像所花费时间的最大值
|
|
21 |
float m_fExpo; //! 曝光时间,uS
|
|
22 |
|
|
23 |
volatile int Grabok;
|
|
24 |
volatile int TrigeredCount;
|
|
25 |
volatile int BackCallCount;
|
|
26 |
volatile int SnapCount;
|
|
27 |
|
|
28 |
unsigned char* pImageBuf;
|
|
29 |
int pImageBufSize;
|
|
30 |
|
|
31 |
static int InitLib();
|
|
32 |
int GetCameraCount(){return TotalCameraCount;}
|
|
33 |
int GetCameraInfo(int index, MyCameraInfo * pMyCameraInfo);
|
|
34 |
|
|
35 |
int OpenCamera(int Index);
|
|
36 |
int CloseCamera();
|
|
37 |
int GetCameraWidthHeight(int * nWidth, int * nHeight)
|
|
38 |
{
|
|
39 |
*nWidth=m_nWidth;
|
|
40 |
*nHeight=m_nHeight;
|
|
41 |
return CameraOk;
|
|
42 |
};
|
|
43 |
int GetCameraPixelFormat()
|
|
44 |
{
|
|
45 |
return m_PixelFormat;
|
|
46 |
};
|
|
47 |
int GetExposureTime(double *ExposureTime);
|
|
48 |
int SetExposureTime(double ExposeTime);
|
|
49 |
|
|
50 |
int GetWidth(int *nWidth)
|
|
51 |
{
|
|
52 |
MVCC_INTVALUE iValue;
|
|
53 |
int nRet = MV_CC_GetIntValue(m_hCam,"Width", &iValue);
|
|
54 |
if (nRet!=MV_OK)
|
|
55 |
return CameraError;
|
|
56 |
|
|
57 |
*nWidth = iValue.nCurValue;
|
|
58 |
return CameraOk;
|
|
59 |
};
|
|
60 |
int GetWidthRange(int *WidthMin,int *WidthMax)
|
|
61 |
{
|
|
62 |
MVCC_INTVALUE iValue;
|
|
63 |
int nRet = MV_CC_GetIntValue(m_hCam,"Width", &iValue);
|
|
64 |
if (nRet!=MV_OK)
|
|
65 |
return CameraError;
|
|
66 |
|
|
67 |
*WidthMin = iValue.nMin;
|
|
68 |
*WidthMax = iValue.nMax;
|
|
69 |
return CameraOk;
|
|
70 |
};
|
|
71 |
int GetWidthInc(int *WidthInc)
|
|
72 |
{
|
|
73 |
MVCC_INTVALUE iValue;
|
|
74 |
int nRet = MV_CC_GetIntValue(m_hCam,"Width", &iValue);
|
|
75 |
if (nRet!=MV_OK)
|
|
76 |
return CameraError;
|
|
77 |
|
|
78 |
*WidthInc = iValue.nInc;
|
|
79 |
return CameraOk;
|
|
80 |
};
|
|
81 |
int SetWidth(int nWidth)
|
|
82 |
{
|
|
83 |
int nRet = MV_CC_SetIntValue(m_hCam,"Width", nWidth);
|
|
84 |
if (nRet!=MV_OK)
|
|
85 |
return CameraError;
|
|
86 |
|
|
87 |
return CameraOk;
|
|
88 |
};
|
|
89 |
|
|
90 |
|
|
91 |
int GetHeight(int *nHeight)
|
|
92 |
{
|
|
93 |
MVCC_INTVALUE iValue;
|
|
94 |
int nRet = MV_CC_GetIntValue(m_hCam,"Height", &iValue);
|
|
95 |
if (nRet!=MV_OK)
|
|
96 |
return CameraError;
|
|
97 |
|
|
98 |
*nHeight = iValue.nCurValue;
|
|
99 |
return CameraOk;
|
|
100 |
};
|
|
101 |
int GetHeightRange(int *HeightMin,int *HeightMax)
|
|
102 |
{
|
|
103 |
MVCC_INTVALUE iValue;
|
|
104 |
int nRet = MV_CC_GetIntValue(m_hCam,"Height", &iValue);
|
|
105 |
if (nRet!=MV_OK)
|
|
106 |
return CameraError;
|
|
107 |
|
|
108 |
*HeightMin = iValue.nMin;
|
|
109 |
*HeightMax = iValue.nMax;
|
|
110 |
return CameraOk;
|
|
111 |
};
|
|
112 |
int GetHeightInc(int *HeightInc)
|
|
113 |
{
|
|
114 |
MVCC_INTVALUE iValue;
|
|
115 |
int nRet = MV_CC_GetIntValue(m_hCam,"Height", &iValue);
|
|
116 |
if (nRet!=MV_OK)
|
|
117 |
return CameraError;
|
|
118 |
|
|
119 |
*HeightInc = iValue.nInc;
|
|
120 |
return CameraOk;
|
|
121 |
};
|
|
122 |
int SetHeight(int nHeight)
|
|
123 |
{
|
|
124 |
int nRet = MV_CC_SetIntValue(m_hCam,"Height", nHeight);
|
|
125 |
if (nRet!=MV_OK)
|
|
126 |
return CameraError;
|
|
127 |
|
|
128 |
return CameraOk;
|
|
129 |
};
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
int GetOffsetX(int *nOffsetX)
|
|
134 |
{
|
|
135 |
MVCC_INTVALUE iValue;
|
|
136 |
int nRet = MV_CC_GetIntValue(m_hCam,"OffsetX", &iValue);
|
|
137 |
if (nRet!=MV_OK)
|
|
138 |
return CameraError;
|
|
139 |
|
|
140 |
*nOffsetX = iValue.nCurValue;
|
|
141 |
return CameraOk;
|
|
142 |
};
|
|
143 |
int GetOffsetXRange(int *OffsetXMin,int *OffsetXMax)
|
|
144 |
{
|
|
145 |
MVCC_INTVALUE iValue;
|
|
146 |
int nRet = MV_CC_GetIntValue(m_hCam,"OffsetX", &iValue);
|
|
147 |
if (nRet!=MV_OK)
|
|
148 |
return CameraError;
|
|
149 |
|
|
150 |
*OffsetXMin = iValue.nMin;
|
|
151 |
*OffsetXMax = iValue.nMax;
|
|
152 |
return CameraOk;
|
|
153 |
};
|
|
154 |
int SetOffsetX(int nOffsetX)
|
|
155 |
{
|
|
156 |
int nRet = MV_CC_SetIntValue(m_hCam,"OffsetX", nOffsetX);
|
|
157 |
if (nRet!=MV_OK)
|
|
158 |
return CameraError;
|
|
159 |
|
|
160 |
return CameraOk;
|
|
161 |
};
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
int GetOffsetY(int *nOffsetY)
|
|
166 |
{
|
|
167 |
MVCC_INTVALUE iValue;
|
|
168 |
int nRet = MV_CC_GetIntValue(m_hCam,"OffsetY", &iValue);
|
|
169 |
if (nRet!=MV_OK)
|
|
170 |
return CameraError;
|
|
171 |
|
|
172 |
*nOffsetY = iValue.nCurValue;
|
|
173 |
return CameraOk;
|
|
174 |
};
|
|
175 |
int GetOffsetYRange(int *OffsetYMin,int *OffsetYMax)
|
|
176 |
{
|
|
177 |
MVCC_INTVALUE iValue;
|
|
178 |
int nRet = MV_CC_GetIntValue(m_hCam,"OffsetY", &iValue);
|
|
179 |
if (nRet!=MV_OK)
|
|
180 |
return CameraError;
|
|
181 |
|
|
182 |
*OffsetYMin = iValue.nMin;
|
|
183 |
*OffsetYMax = iValue.nMax;
|
|
184 |
return CameraOk;
|
|
185 |
};
|
|
186 |
int SetOffsetY(int nOffsetY)
|
|
187 |
{
|
|
188 |
int nRet = MV_CC_SetIntValue(m_hCam,"OffsetY", nOffsetY);
|
|
189 |
if (nRet!=MV_OK)
|
|
190 |
return CameraError;
|
|
191 |
|
|
192 |
return CameraOk;
|
|
193 |
};
|
|
194 |
|
|
195 |
int SetROI(int nOffsetX, int nOffsetY, int nWidth, int nHeight)
|
|
196 |
{
|
|
197 |
int WidthMax,WidthMin,WidthInc,HeightMax,HeigtMin,OffsetXMin,OffsetXMax,OffsetYMin,OffsetYMax;
|
|
198 |
if (GetWidthRange(&WidthMin,&WidthMax)!=CameraOk) return CameraError;
|
|
199 |
if (GetWidthInc(&WidthInc)!=CameraOk) return CameraError;
|
|
200 |
if (WidthInc==0) return CameraError;
|
|
201 |
if (GetHeightRange(&HeigtMin,&HeightMax)!=CameraOk) return CameraError;
|
|
202 |
if (GetOffsetXRange(&OffsetXMin,&OffsetXMax)!=CameraOk) return CameraError;
|
|
203 |
if (GetOffsetYRange(&OffsetYMin,&OffsetYMax)!=CameraOk) return CameraError;
|
|
204 |
if (nWidth<WidthMin||nWidth>WidthMax) return CameraError;
|
|
205 |
if ((nWidth%WidthInc)!=0) return CameraError;
|
|
206 |
if (nHeight<HeigtMin||nHeight>HeightMax) return CameraError;
|
|
207 |
if (nOffsetX<OffsetXMin||nOffsetX>OffsetXMax) return CameraError;
|
|
208 |
if (nOffsetY<OffsetYMin||nOffsetY>OffsetYMax) return CameraError;
|
|
209 |
|
|
210 |
if (nOffsetX+nWidth>WidthMax) return CameraError;
|
|
211 |
if (nOffsetY+nHeight>HeightMax) return CameraError;
|
|
212 |
if (SetOffsetX(0)!=CameraOk) return CameraError;
|
|
213 |
if (SetOffsetY(0)!=CameraOk) return CameraError;
|
|
214 |
if (SetWidth(nWidth)!=CameraOk) return CameraError;
|
|
215 |
if (SetHeight(nHeight)!=CameraOk) return CameraError;
|
|
216 |
if (SetOffsetX(nOffsetX)!=CameraOk) return CameraError;
|
|
217 |
if (SetOffsetY(nOffsetY)!=CameraOk) return CameraError;
|
|
218 |
return CameraOk;
|
|
219 |
};
|
|
220 |
|
|
221 |
|
|
222 |
int GetGain(double *nGain)
|
|
223 |
{
|
|
224 |
MVCC_FLOATVALUE fValue;
|
|
225 |
int nRet = MV_CC_GetFloatValue(m_hCam,"Gain", &fValue);
|
|
226 |
if (nRet!=MV_OK)
|
|
227 |
return CameraError;
|
|
228 |
|
|
229 |
*nGain = fValue.fCurValue;
|
|
230 |
return CameraOk;
|
|
231 |
};
|
|
232 |
int GetGainRange(double *GainMin,double *GainMax)
|
|
233 |
{
|
|
234 |
MVCC_FLOATVALUE fValue;
|
|
235 |
int nRet = MV_CC_GetFloatValue(m_hCam,"Gain", &fValue);
|
|
236 |
if (nRet!=MV_OK)
|
|
237 |
return CameraError;
|
|
238 |
|
|
239 |
*GainMin = fValue.fMin;
|
|
240 |
*GainMax = fValue.fMax;
|
|
241 |
return CameraOk;
|
|
242 |
};
|
|
243 |
int SetGain(float Gain)
|
|
244 |
{
|
|
245 |
int nRet = MV_CC_SetFloatValue(m_hCam,"Gain", Gain);
|
|
246 |
if (nRet!=MV_OK)
|
|
247 |
return CameraError;
|
|
248 |
|
|
249 |
return CameraOk;
|
|
250 |
};
|
|
251 |
|
|
252 |
int GetGamma(double *nGamma)
|
|
253 |
{
|
|
254 |
MVCC_FLOATVALUE fValue;
|
|
255 |
int nRet = MV_CC_GetFloatValue(m_hCam,"Gamma", &fValue);
|
|
256 |
if (nRet!=MV_OK)
|
|
257 |
return CameraError;
|
|
258 |
|
|
259 |
*nGamma = fValue.fCurValue;
|
|
260 |
return CameraOk;
|
|
261 |
};
|
|
262 |
int GetGammaRange(double *GammaMin,double *GammaMax)
|
|
263 |
{
|
|
264 |
MVCC_FLOATVALUE fValue;
|
|
265 |
int nRet = MV_CC_GetFloatValue(m_hCam,"Gamma", &fValue);
|
|
266 |
if (nRet!=MV_OK)
|
|
267 |
return CameraError;
|
|
268 |
|
|
269 |
*GammaMin = fValue.fMin;
|
|
270 |
*GammaMax = fValue.fMax;
|
|
271 |
return CameraOk;
|
|
272 |
};
|
|
273 |
int SetGamma(float Gamma)
|
|
274 |
{
|
|
275 |
int nRet = MV_CC_SetFloatValue(m_hCam,"Gamma", Gamma);
|
|
276 |
if (nRet!=MV_OK)
|
|
277 |
return CameraError;
|
|
278 |
|
|
279 |
return CameraOk;
|
|
280 |
};
|
|
281 |
|
|
282 |
|
|
283 |
int GetLUTEnable(int *bIsEnable)
|
|
284 |
{
|
|
285 |
bool v;
|
|
286 |
int nRet = MV_CC_GetBoolValue(m_hCam,"LUTEnable", &v);
|
|
287 |
if (nRet!=MV_OK)
|
|
288 |
return CameraError;
|
|
289 |
|
|
290 |
*bIsEnable = v;
|
|
291 |
return CameraOk;
|
|
292 |
};
|
|
293 |
int SetLUTEnable(int bIsEnable)
|
|
294 |
{
|
|
295 |
bool v = (bIsEnable != 0);
|
|
296 |
int nRet = MV_CC_SetBoolValue(m_hCam,"LUTEnable", v);
|
|
297 |
if (nRet!=MV_OK)
|
|
298 |
return CameraError;
|
|
299 |
|
|
300 |
return CameraOk;
|
|
301 |
};
|
|
302 |
int SetLUT(int *pBuf,int nCount)
|
|
303 |
{
|
|
304 |
int nRet;
|
|
305 |
for (int i=0;i<nCount&&i<1024;i++)
|
|
306 |
{
|
|
307 |
nRet = MV_CC_SetIntValue(m_hCam,"LUTIndex", i);
|
|
308 |
if (nRet!=MV_OK)
|
|
309 |
return CameraError;
|
|
310 |
|
|
311 |
nRet = MV_CC_SetIntValue(m_hCam,"LUTValue", pBuf[i]);
|
|
312 |
if (nRet!=MV_OK)
|
|
313 |
return CameraError;
|
|
314 |
}
|
|
315 |
|
|
316 |
return CameraOk;
|
|
317 |
};
|
|
318 |
|
|
319 |
int StartGrab();
|
|
320 |
int StopGrab(){return CameraOk;};
|
|
321 |
int WaitForGrabFinish(int mSecound);
|
|
322 |
int FetchImageData();
|
|
323 |
|
|
324 |
int UpdateFps();
|
|
325 |
|
|
326 |
static void __stdcall ImageCallBackEx(unsigned char* pData, MV_FRAME_OUT_INFO_EX* pFrameInfo, void* pUser);
|
|
327 |
|
|
328 |
int OnImageCallBackEx(unsigned char* pData, MV_FRAME_OUT_INFO_EX* pFrameInfo);
|
|
329 |
};
|
|
330 |
|