|
|
@@ -18,6 +18,7 @@ static const char * const setTriggerMode = "On"; /// 默认: 打开, 可关闭:
|
|
|
#define AE_EXP_STABLE_FRAMES 4 // 相机处于自动曝光模式时, 累计曝光值稳定的帧数
|
|
|
|
|
|
// 保存照片
|
|
|
+static int SavePhoto(HANDLE hCam, IMV_Frame *pFrame, DHImgType imgType, const char *imgFile);
|
|
|
|
|
|
// 拍照回调
|
|
|
typedef struct
|
|
|
@@ -48,11 +49,41 @@ static bool is_huaray_manu_alias(const char *name)
|
|
|
|
|
|
static void OnFrameReceived(IMV_Frame *pFrame, void *pUser) // 数据帧的回调, 完成一次拍照任务
|
|
|
{
|
|
|
- PthotoProcCtx *ctx = (PthotoProcCtx *)pUser;
|
|
|
+ PthotoProcCtx *ctx = (PthotoProcCtx *)pUser; int ret = IMV_OK;
|
|
|
if(NULL == pFrame) return;
|
|
|
+
|
|
|
+ // 1, 打印该帧信息
|
|
|
sw_log_debug("[%s] +++GetOneFrame+++, Width[%u], Height[%u], FrameNum[%llu], FrameLen[%u], PixelType[0x%08X]", MODULE_NAME,
|
|
|
pFrame->frameInfo.width, pFrame->frameInfo.height, pFrame->frameInfo.blockId, pFrame->frameInfo.size,
|
|
|
(unsigned int)pFrame->frameInfo.pixelFormat);
|
|
|
+
|
|
|
+ // 2, 自动曝光模式
|
|
|
+ if(ctx->isExposureAuto)
|
|
|
+ {
|
|
|
+ double curExpTime = 0.0;
|
|
|
+ ret = IMV_GetDoubleFeatureValue(ctx->hCam, "ExposureTime", &curExpTime);
|
|
|
+ if(IMV_OK != ret) goto endp;
|
|
|
+
|
|
|
+ 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); // 计算时间差, 单位: ms
|
|
|
+ sw_log_debug("[%s] +++GetOneFrame+++, 等待曝光完成, ExposureTime = %.2fus, ElapsedTime = %ldms", MODULE_NAME, curExpTime, elapsed);
|
|
|
+
|
|
|
+ if(fabsf(curExpTime - ctx->lastExpTime) <= AE_EXP_TIME_EPS_US) ctx->expStableCnt++;
|
|
|
+ else ctx->expStableCnt = 0;
|
|
|
+
|
|
|
+ if(ctx->expStableCnt < AE_EXP_STABLE_FRAMES && elapsed < AE_WAIT_MAX_MS)
|
|
|
+ { // 曝光未稳定, 也未超时, 则继续等下一帧
|
|
|
+ ctx->lastExpTime = curExpTime; if(0 == ctx->expStableCnt) ctx->expStableCnt = 1;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3, 导出图像文件
|
|
|
+ ret = SavePhoto(ctx->hCam, pFrame, ctx->saveImgType, ctx->saveImgPath);
|
|
|
+
|
|
|
+ // 4, 设置拍照完成
|
|
|
+endp:
|
|
|
+ ctx->rCode = ret; sw_signal_give(ctx->hESig);
|
|
|
}
|
|
|
|
|
|
static int FrameSoftTrigger(unsigned long wParam, unsigned long lParam) // 线程回调函数, 触发一次拍照执行
|