Browse Source

新增代码

niujiuru 2 months atrás
parent
commit
8b1a0ccd55
3 changed files with 27 additions and 4 deletions
  1. 5 0
      dh_takephoto/readme.txt
  2. 20 2
      dh_takephoto/takephoto.c
  3. 2 2
      hk_takephoto/takephoto.c

+ 5 - 0
dh_takephoto/readme.txt

@@ -7,4 +7,9 @@ Todo: 待实现
 - 在具体的项目代码中调用该模块的: “GetDHCameraCount()” 获取当前相机的数量
 - 在具体的项目代码中调用该模块的: “TakePhoto()”        函数拍照并保存文件
 
+备注说明:
+- 该模块初始化时只会初始化U口相机的使用环境,虽然模块本身已支持G口相机使用,
+  但没有在该模块中对G口相机环境进行初始化(耗时、耗电),若需使用,请参考更上
+  层的“camera”模块封装。
+
 2026年1月6日  written by niujiuru

+ 20 - 2
dh_takephoto/takephoto.c

@@ -1,7 +1,7 @@
 #include "takephoto.h"
 
 // 模块名称
-static const char MODULE_NAME[] = "TakePhoto";
+static const char MODULE_NAME[] = "HrTakePhoto";
 
 // 相机类型
 static unsigned int device_type =  interfaceTypeGige | interfaceTypeUsb3;
@@ -25,7 +25,7 @@ typedef struct
   HANDLE      hCam;           // 打开相机的句柄
   uint32_t    camType;        // 相机类型:U、网
   char manuName[MAX_LINE_CHARS]; //制造厂商名称
-  DHImgType    saveImgType;   // 保存图像的类型
+  DHImgType   saveImgType;    // 保存图像的类型
   const char *saveImgPath;    // 保存图像的路径
   bool        isExposureAuto; // 自动曝光:是/否
   struct timespec expTime0;   // 曝光开始的时间
@@ -46,6 +46,24 @@ static bool is_huaray_manu_alias(const char *name)
   return false;
 }
 
+static void OnFrameReceived(IMV_Frame *pFrame, void *pUser)             // 数据帧的回调, 完成一次拍照任务
+{
+  PthotoProcCtx *ctx = (PthotoProcCtx *)pUser;
+  if(NULL == pFrame) return;
+  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);
+}
+
+static int FrameSoftTrigger(unsigned long wParam, unsigned long lParam) // 线程回调函数, 触发一次拍照执行
+{
+  PthotoProcCtx *ctx = (PthotoProcCtx *)wParam;
+  int ret = IMV_ExecuteCommandFeature(ctx->hCam, "TriggerSoftware");
+  if(IMV_OK != ret) ret = 1; // 软触发失败后, 马上再次触发
+  else ret = 1000; // 软触发成功后-延时一秒, 等待下次的触发
+  return ret;
+}
+
 // 单次执行相机拍照, 并保存到文件, 成功返回: 0值, 失败返回:非0值
 // "imgType"     - 获取图像类型
 // "saveImgPath" - 保存的文件名

+ 2 - 2
hk_takephoto/takephoto.c

@@ -65,8 +65,8 @@ static int PhotoProc(unsigned long wParam, unsigned long lParam) // 线程回调
   // 3, 导出图像文件
   if(MV_OK == ret)
   {
-    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, \
+    sw_log_debug("[%s] +++GetOneFrame+++, Width[%u], Height[%u], FrameNum[%u], FrameLen[%u], 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)