From 4c1a3977752892e2bd2e5270c964648f70900ab6 Mon Sep 17 00:00:00 2001 From: lijun Date: Sat, 18 Jan 2025 14:55:02 +0800 Subject: [PATCH] =?UTF-8?q?=E5=86=85=E5=AD=98=E6=B3=84=E6=BC=8F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/tool.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/service/tool.go b/service/tool.go index c6244b9..d70081c 100644 --- a/service/tool.go +++ b/service/tool.go @@ -53,7 +53,7 @@ func SetDeviceCurrentFrame(frame gocv.Mat, device_id int) error { return nil } -func SetDeviceCurrentFrameV2(frame gocv.Mat, device_id int) error { +func SetDeviceCurrentFrameV2(frame *gocv.Mat, device_id int) error { //获取读写锁 mutex_, ok := DeviceRWMap.Load(device_id) if !ok { @@ -65,9 +65,9 @@ func SetDeviceCurrentFrameV2(frame gocv.Mat, device_id int) error { //设置当前帧 switch device_id { case 1: - Device1CurrentFrame = frame + Device1CurrentFrame = *frame case 50: - Device50CurrentFrame = frame + Device50CurrentFrame = *frame } frame_count, ok := DeviceFrameCount.Load(device_id) if !ok { @@ -224,6 +224,7 @@ func getVideoFrame(device proto.DeviceInfo) { fontColor := color.RGBA{G: 255} lineType := 2 z := 0 + var frame gocv.Mat for { if device.LogFrame > 0 && z%device.LogFrame == 0 { log.Printf("设备:%d 当前帧: %d\n", device.ID, z) @@ -231,7 +232,7 @@ func getVideoFrame(device proto.DeviceInfo) { if device.NextStop { break } - frame := gocv.NewMat() + frame = gocv.NewMat() ok := webcam.Read(&frame) if !ok { log.Printf("设备:%v 错误: 无法从视频流中读取帧\n", device) @@ -252,16 +253,16 @@ func getVideoFrame(device proto.DeviceInfo) { currentTime := time.Now().Format("2006-01-02 15:04:05") gocv.PutText(&frame, currentTime, image.Point{10, 20}, font, fontScale, fontColor, lineType) //需要将帧付给全局变量 - err3 := SetDeviceCurrentFrameV2(frame, device.ID) + err3 := SetDeviceCurrentFrameV2(&frame, device.ID) if err3 != nil { log.Printf("设备:%d 错误: 无法设置当前帧,err:%s \n", device.ID, err3.Error()) } z++ - //关闭帧 - err4 := frame.Close() - if err4 != nil { - log.Printf("设备:%d 错误: 无法关闭帧,err:%s \n", device.ID, err4.Error()) - } + } + //关闭帧 + err4 := frame.Close() + if err4 != nil { + log.Printf("设备:%d 错误: 无法关闭帧,err:%s \n", device.ID, err4.Error()) } }