Quellcode durchsuchen

优化修改代码

niujiuru vor 3 Wochen
Ursprung
Commit
babcb030dc
2 geänderte Dateien mit 54 neuen und 14 gelöschten Zeilen
  1. 44 4
      dh_takephoto/takephoto.c
  2. 10 10
      hk_takephoto/takephoto.c

+ 44 - 4
dh_takephoto/takephoto.c

@@ -18,7 +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);
+static int SavePhoto(HANDLE hCam, IMV_Frame *pFrame, DHImgType imgType, const char *imgPath);
 
 // 拍照回调
 typedef struct
@@ -277,10 +277,50 @@ end_p:
   return ret;
 }
 
-// 保存照片
-static int SavePhoto(HANDLE hCam, IMV_Frame *pFrame, DHImgType imgType, const char *imgFile)
+// 保存给定的数据帧到BMP图像文件, 成功返回:true, 失败返回:false
+static bool SaveFrameToBmp(IMV_HANDLE hCam, IMV_Frame *pFrame, const char *path)
+{
+}
+
+// 保存给定的数据帧到JPG图像文件, 成功返回:true, 失败返回:false
+static bool SaveFrameToJpg(IMV_HANDLE hCam, IMV_Frame *pFrame, const char *path)
+{
+}
+
+// 保存给定的数据帧到指定格式("BMP"/"JPG")的图像文件,成功返回0值
+static int SavePhoto(HANDLE hCam, IMV_Frame *pFrame, DHImgType imgType, const char *imgPath)
 {
-  return IMV_OK; // todo: 实现保存照片功能
+  char *path1 = (char *)imgPath, *path2 = NULL; int ret = IMV_OK; char ext[5];
+
+  if(!hCam || !pFrame || !path1 || strlen(path1) <= 0) return -15;
+
+  switch(imgType)
+  {
+   case IMG_TYPE_BMP: // 保存为.bmp格式
+    strcpy(ext, ".bmp");
+    break;
+   case IMG_TYPE_JPG: // 保存为.jpg格式
+    strcpy(ext, ".jpg");
+    break;
+   default: return -16;
+  }
+
+  if(!xstrcasestr(path1, "right", ext))
+  {
+    path2 = (char *)sw_heap_malloc(strlen(path1) + sizeof(ext));
+    if(path2) sprintf(path2, "%s%s", path1, ext);
+    else return -17;
+    if(imgType == IMG_TYPE_BMP && !SaveFrameToBmp(hCam, pFrame, path2)) ret = -18;
+    if(imgType == IMG_TYPE_JPG && !SaveFrameToJpg(hCam, pFrame, path2)) ret = -19;
+    sw_heap_free(path2);
+  }
+  else
+  {
+    if(imgType == IMG_TYPE_BMP && !SaveFrameToBmp(hCam, pFrame, path1)) ret = -18;
+    if(imgType == IMG_TYPE_JPG && !SaveFrameToJpg(hCam, pFrame, path1)) ret = -19;
+  }
+
+  return ret;
 }
 
 // 获取系统当前USBFS内存大小(MB), 成功返回: >=0, 失败返回: <0值

+ 10 - 10
hk_takephoto/takephoto.c

@@ -18,7 +18,7 @@ static MV_CAM_TRIGGER_MODE setTriggerMode = MV_TRIGGER_MODE_ON; /// 默认: 打
 #define AE_EXP_STABLE_FRAMES    4 // 相机处于自动曝光模式时, 累计曝光值稳定的帧数
 
 // 保存照片
-static int SavePhoto(HANDLE hCam, MV_FRAME_OUT *pFrame, HKImgType imgType, const char *imgFile);
+static int SavePhoto(HANDLE hCam, MV_FRAME_OUT *pFrame, HKImgType imgType, const char *imgPath);
 
 // 拍照回调
 typedef struct
@@ -298,12 +298,12 @@ end_p:
 }
 
 // 保存照片
-static int SavePhoto(HANDLE hCam, MV_FRAME_OUT *pFrame, HKImgType imgType, const char *imgFile)
+static int SavePhoto(HANDLE hCam, MV_FRAME_OUT *pFrame, HKImgType imgType, const char *imgPath)
 {
   MV_SAVE_IMAGE_PARAM_EX3 saveParams = { 0 }; MVCC_INTVALUE_EX iv;
-  char *filename1 = (char *)imgFile, *filename2 = NULL; int ret; char ext[5];
+  char *path1 = (char *)imgPath, *path2 = NULL; int ret; char ext[5];
 
-  if(!hCam || !pFrame || !filename1 || strlen(filename1) <= 0) return -15;
+  if(!hCam || !pFrame || !path1 || strlen(path1) <= 0) return -15;
 
   switch(imgType)
   {
@@ -339,17 +339,17 @@ static int SavePhoto(HANDLE hCam, MV_FRAME_OUT *pFrame, HKImgType imgType, const
   ret = MV_CC_SaveImageEx3(hCam, &saveParams);
   if(MV_OK != ret) goto end_p;
 
-  if(!xstrcasestr(filename1, "right", ext))
+  if(!xstrcasestr(path1, "right", ext))
   {
-    filename2 = (char *)sw_heap_malloc(strlen(filename1) +sizeof(ext));
-    if(filename2) sprintf(filename2, "%s%s", filename1, ext);
+    path2 = (char *)sw_heap_malloc(strlen(path1) + sizeof(ext));
+    if(path2) sprintf(path2, "%s%s", path1, ext);
     else { ret = -18; goto end_p; }
-    ret = sw_file_update(filename2, "wb", (const char *)saveParams.pImageBuffer, saveParams.nImageLen);
-    sw_heap_free(filename2);
+    ret = sw_file_update(path2, "wb", (const char *)saveParams.pImageBuffer, saveParams.nImageLen);
+    sw_heap_free(path2);
   }
   else
   {
-    ret = sw_file_update(filename1, "wb", (const char *)saveParams.pImageBuffer, saveParams.nImageLen);
+    ret = sw_file_update(path1, "wb", (const char *)saveParams.pImageBuffer, saveParams.nImageLen);
   }
 
   if(ret == saveParams.nImageLen) ret = MV_OK;