From 00a04ff28706f51a1534965ef792edb2df505074 Mon Sep 17 00:00:00 2001 From: lijun Date: Wed, 15 Jan 2025 23:20:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A9=BA=E6=8C=87=E9=92=88=E5=AF=BC=E8=87=B4?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/tool.go | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/service/tool.go b/service/tool.go index 1ed98f1..78cff2d 100644 --- a/service/tool.go +++ b/service/tool.go @@ -46,13 +46,30 @@ func GetDeviceCurrentFrame(device_id int) (gocv.Mat, int) { if !ok { return gocv.NewMat(), -1 } - mutex := mutex_.(*sync.RWMutex) + mutex, ok := mutex_.(*sync.RWMutex) + if !ok { + log.Fatalf("DeviceRWMap 存储的不是 *sync.RWMutex 类型,device_id: %d", device_id) + } mutex.RLock() defer mutex.RUnlock() //获取当前帧 - frame, ok := DeviceCurrentFrameMap.Load(device_id) - frame_count, ok := DeviceFrameCount.Load(device_id) - return frame.(gocv.Mat), frame_count.(int) + frameIface, ok := DeviceCurrentFrameMap.Load(device_id) + if !ok { + return gocv.NewMat(), -1 + } + frame, ok := frameIface.(gocv.Mat) + if !ok { + log.Fatalf("DeviceCurrentFrameMap 存储的不是 gocv.Mat 类型,device_id: %d", device_id) + } + frame_countIface, ok := DeviceFrameCount.Load(device_id) + if !ok { + return gocv.NewMat(), -1 + } + frame_count, ok := frame_countIface.(int) + if !ok { + log.Fatalf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", device_id) + } + return frame, frame_count } func getVideoFrame(device proto.DeviceInfo) {