|
|
@@ -12,16 +12,19 @@ typedef struct
|
|
|
HANDLE hCam;
|
|
|
EImgType saveImgType;
|
|
|
const char *saveImgFilename;
|
|
|
- HANDLE hESig; // 任务结束的通知
|
|
|
- int rCode; // 任务结束返回值
|
|
|
+ bool isExposureAuto; // 自动曝光:是/否
|
|
|
+ struct timespec expTime0; // 曝光开始的时间
|
|
|
+ HANDLE hESig; // 任务结束的通知
|
|
|
+ int rCode; // 任务结束返回值
|
|
|
} PthotoProcCtx;
|
|
|
|
|
|
static int PhotoProc(unsigned long wParam, unsigned long lParam) // 线程回调函数,执行一次拍照任务
|
|
|
{
|
|
|
- PthotoProcCtx *ctx = (PthotoProcCtx *)wParam; MV_FRAME_OUT frame = { 0 };
|
|
|
+ PthotoProcCtx *ctx = (PthotoProcCtx *)wParam; MV_FRAME_OUT frame = { 0 }; int ret;
|
|
|
|
|
|
// 1, 触发一次拍照
|
|
|
- int ret = MV_CC_SetCommandValue(ctx->hCam, "TriggerSoftware");
|
|
|
+getp:
|
|
|
+ ret = MV_CC_SetCommandValue(ctx->hCam, "TriggerSoftware");
|
|
|
|
|
|
// 2, 等待获取图像
|
|
|
if(MV_OK == ret)
|
|
|
@@ -36,6 +39,13 @@ static int PhotoProc(unsigned long wParam, unsigned long lParam) // 线程回调
|
|
|
sw_log_debug("[%s] +++GetOneFrame+++, Width[%d], Height[%d], FrameNum[%d], FrameLen[%d], PixelType[0x%08X]", MODULE_NAME, \
|
|
|
frame.stFrameInfo.nWidth, frame.stFrameInfo.nHeight, frame.stFrameInfo.nFrameNum, frame.stFrameInfo.nFrameLen, \
|
|
|
(unsigned int)frame.stFrameInfo.enPixelType);
|
|
|
+ if(ctx->isExposureAuto)
|
|
|
+ { // 自动曝光模式下, 等待15秒后的图像清晰度才可用
|
|
|
+ struct timespec now; clock_gettime(CLOCK_MONOTONIC, &now);
|
|
|
+ long elapsed = (now.tv_sec - ctx->expTime0.tv_sec)*1000 + (now.tv_nsec-ctx->expTime0.tv_nsec)/(1000*1000);
|
|
|
+ sw_log_debug("[%s] +++GetOneFrame+++, 等待曝光完成, elapsed=%ldms", MODULE_NAME, elapsed);
|
|
|
+ if(elapsed < 15*1000) { MV_CC_FreeImageBuffer(ctx->hCam, &frame); goto getp/*继续取图像*/; }
|
|
|
+ }
|
|
|
ret = SavePhoto(ctx->hCam, &frame, ctx->saveImgType, ctx->saveImgFilename);
|
|
|
MV_CC_FreeImageBuffer(ctx->hCam, &frame);
|
|
|
}
|
|
|
@@ -135,6 +145,16 @@ int TakePhoto(EImgType imgType, const char *saveImgFilename, int timeout, SImgMa
|
|
|
goto end_p;
|
|
|
}
|
|
|
|
|
|
+ MVCC_ENUMVALUE ExposureMode = { 0 };
|
|
|
+ ret = MV_CC_GetExposureAutoMode(hCam, &ExposureMode);
|
|
|
+ if(MV_OK != ret)
|
|
|
+ {
|
|
|
+ sw_log_error("[%s] 获取-曝光模式失败, errCode=0x%x!!", MODULE_NAME, ret);
|
|
|
+ goto end_p;
|
|
|
+ }
|
|
|
+ if(ExposureMode.nCurValue != MV_EXPOSURE_AUTO_MODE_OFF) { ctx.isExposureAuto = true; clock_gettime(CLOCK_MONOTONIC, &ctx.expTime0); }
|
|
|
+ else ctx.isExposureAuto = false;
|
|
|
+
|
|
|
ctx.hCam = hCam;
|
|
|
ctx.saveImgType = imgType;
|
|
|
ctx.saveImgFilename = saveImgFilename;
|