Prechádzať zdrojové kódy

优化相机模块代码,拍照时,导出照片水印信息加入照片尺寸信息

niujiuru 3 týždňov pred
rodič
commit
e79064cdea

+ 19 - 0
camera/camera.go

@@ -6,6 +6,7 @@ import (
 	"net"
 	"os"
 	"os/exec"
+	"strings"
 	"syscall"
 	"time"
 
@@ -30,6 +31,8 @@ type SImgMark struct {
 	CamModelName    string  // 相机型号名
 	CamSerialNum    string  // 相机序列号
 	ImgExposureTime float64 // 曝光时间值
+	ImgWidth        uint    // 图像的宽度
+	ImgHeight       uint    // 图像的高度
 }
 
 // 配置连接网口相机的网卡ip
@@ -75,6 +78,18 @@ func PowerOnGigeCamera(on bool) error {
 	return nil
 }
 
+// 取网口相机电源的开关状态
+func GetGigeCameraPowerCtrl() (bool, error) {
+	data, err := os.ReadFile("/sys/class/gpio/gpio22/value")
+	if err != nil {
+		return false, err
+	}
+
+	value := strings.TrimSpace(string(data))
+
+	return value == "1", nil
+}
+
 func PingOnce(host string, timeoutSec int) error {
 	cmd := exec.Command("ping", "-c", "1", "-W", fmt.Sprint(timeoutSec), host)
 	return cmd.Run()
@@ -199,6 +214,8 @@ func TakePhoto(imgType int, saveImgPath string, timeout int) (SImgMark, error) {
 				CamModelName:    hkMark.CamModelName,
 				CamSerialNum:    hkMark.CamSerialNum,
 				ImgExposureTime: hkMark.ImgExposureTime,
+				ImgWidth:        hkMark.ImgWidth,
+				ImgHeight:       hkMark.ImgHeight,
 			}, nil
 		}
 		errs = append(errs, fmt.Errorf("HK: %w", err))
@@ -211,6 +228,8 @@ func TakePhoto(imgType int, saveImgPath string, timeout int) (SImgMark, error) {
 				CamModelName:    dhMark.CamModelName,
 				CamSerialNum:    dhMark.CamSerialNum,
 				ImgExposureTime: dhMark.ImgExposureTime,
+				ImgWidth:        dhMark.ImgWidth,
+				ImgHeight:       dhMark.ImgHeight,
 			}, nil
 		}
 		errs = append(errs, fmt.Errorf("DH: %w", err))

+ 4 - 0
dh_takephoto/bridge.go

@@ -21,6 +21,8 @@ type SImgMark struct {
 	CamModelName    string  // 相机型号名
 	CamSerialNum    string  // 相机序列号
 	ImgExposureTime float64 // 曝光时间值
+	ImgWidth        uint    // 图像的宽度
+	ImgHeight       uint    // 图像的高度
 }
 
 // 获取系统当前USBFS内存大小(MB), 成功返回: >=0, 失败返回: <0值
@@ -73,5 +75,7 @@ func TakePhoto(imgType int, saveImgPath string, timeout int) (SImgMark, error) {
 		CamModelName:    C.GoString((*C.char)(unsafe.Pointer(&imgMark.camModelName[0]))),
 		CamSerialNum:    C.GoString((*C.char)(unsafe.Pointer(&imgMark.camSerialNum[0]))),
 		ImgExposureTime: float64(imgMark.imgExposureTime),
+		ImgWidth:        uint(imgMark.imgWidth),
+		ImgHeight:       uint(imgMark.imgHeight),
 	}, nil
 }

+ 4 - 0
dh_takephoto/takephoto.c

@@ -30,6 +30,8 @@ typedef struct
   char manuName[MAX_LINE_CHARS]; //制造厂商名称
   DHImgType   saveImgType;    // 保存图像的类型
   const char *saveImgPath;    // 保存图像的路径
+  unsigned int imgWidth;      // 拍照图像宽度px
+  unsigned int imgHeight;     // 拍照图像高度px
   bool        isExposureAuto; // 自动曝光:是/否
   struct timespec expTime0;   // 曝光开始的时间
   float       lastExpTime;    // 上次的曝光时长(us)
@@ -83,6 +85,7 @@ static void OnFrameReceived(IMV_Frame *pFrame, void *pUser) // 数据帧的回
 
   // 3, 导出图像文件
   if(ctx->pUser) { sw_thrd_destroy(ctx->pUser, WAITTHRD_SAFEEXIT_TIMEOUT); ctx->pUser = NULL; }
+  ctx->imgWidth = pFrame->frameInfo.width; ctx->imgHeight = pFrame->frameInfo.height;
   ret = SavePhoto(ctx->hCam, pFrame, ctx->saveImgType, ctx->saveImgPath);
 
   // 4, 设置拍照完成
@@ -268,6 +271,7 @@ waitp:
     double curExpTime = 0.0;
     IMV_GetDoubleFeatureValue(hCam, "ExposureTime", &curExpTime);
     imgMark.imgExposureTime = curExpTime;
+    imgMark.imgWidth = ctx.imgWidth; imgMark.imgHeight = ctx.imgHeight;
     if(pImgMark) memcpy(pImgMark, &imgMark, sizeof(DHImgMark));
   }
 

+ 2 - 0
dh_takephoto/takephoto.h

@@ -16,6 +16,8 @@ typedef struct
   char camModelName[MAX_LINE_CHARS]; // 相机型号名
   char camSerialNum[MAX_LINE_CHARS]; // 相机序列号
   double imgExposureTime; //拍照曝光时间, 单位: us
+  unsigned int imgWidth; // 拍照图像宽度, 单位: px
+  unsigned int imgHeight;// 拍照图像高度, 单位: px
 } DHImgMark;
 
 // 图像类型

+ 4 - 0
hk_takephoto/bridge.go

@@ -24,6 +24,8 @@ type SImgMark struct {
 	CamModelName    string  // 相机型号名
 	CamSerialNum    string  // 相机序列号
 	ImgExposureTime float64 // 曝光时间值
+	ImgWidth        uint    // 图像的宽度
+	ImgHeight       uint    // 图像的高度
 }
 
 // 获取系统当前USBFS内存大小(MB), 成功返回: >=0, 失败返回: <0值
@@ -76,5 +78,7 @@ func TakePhoto(imgType int, saveImgPath string, timeout int) (SImgMark, error) {
 		CamModelName:    C.GoString((*C.char)(unsafe.Pointer(&imgMark.camModelName[0]))),
 		CamSerialNum:    C.GoString((*C.char)(unsafe.Pointer(&imgMark.camSerialNum[0]))),
 		ImgExposureTime: float64(imgMark.imgExposureTime),
+		ImgWidth:        uint(imgMark.imgWidth),
+		ImgHeight:       uint(imgMark.imgHeight),
 	}, nil
 }

+ 4 - 0
hk_takephoto/takephoto.c

@@ -29,6 +29,8 @@ typedef struct
   char manuName[MAX_LINE_CHARS]; //制造厂商名称
   HKImgType   saveImgType;    // 保存图像的类型
   const char *saveImgPath;    // 保存图像的路径
+  unsigned int imgWidth;      // 拍照图像宽度px
+  unsigned int imgHeight;     // 拍照图像高度px
   bool        isExposureAuto; // 自动曝光:是/否
   struct timespec expTime0;   // 曝光开始的时间
   float       lastExpTime;    // 上次的曝光时长(us)
@@ -91,6 +93,7 @@ static int PhotoProc(unsigned long wParam, unsigned long lParam) // 线程回调
       }
     }
 
+    ctx->imgWidth = frame.stFrameInfo.nWidth; ctx->imgHeight = frame.stFrameInfo.nHeight;
     ret = SavePhoto(ctx->hCam, &frame, ctx->saveImgType, ctx->saveImgPath);
     MV_CC_FreeImageBuffer(ctx->hCam, &frame);
   }
@@ -285,6 +288,7 @@ findp:
     MVCC_FLOATVALUE fv = { 0 };
     MV_CC_GetFloatValue(hCam, "ExposureTime", &fv);
     imgMark.imgExposureTime = fv.fCurValue;
+    imgMark.imgWidth = ctx.imgWidth; imgMark.imgHeight = ctx.imgHeight;
     if(pImgMark) memcpy(pImgMark, &imgMark, sizeof(HKImgMark));
   }
 

+ 2 - 0
hk_takephoto/takephoto.h

@@ -14,6 +14,8 @@ typedef struct
   char camModelName[MAX_LINE_CHARS]; // 相机型号名
   char camSerialNum[MAX_LINE_CHARS]; // 相机序列号
   float imgExposureTime; // 拍照曝光时间, 单位: us
+  unsigned int imgWidth; // 拍照图像宽度, 单位: px
+  unsigned int imgHeight;// 拍照图像高度, 单位: px
 } HKImgMark;
 
 // 图像类型