From 3a65f8c4684ebd38bd8a39ad04fd712fcfa1013d Mon Sep 17 00:00:00 2001 From: lijun Date: Wed, 15 Jan 2025 23:04:32 +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 --- handler/tool.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/handler/tool.go b/handler/tool.go index 5f053bc..b2900d3 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -169,7 +169,13 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) { if img.Empty() { fmt.Println("device:%d img is empty!", device_id) } else { - buf, _ := gocv.IMEncode(".jpg", img) + //gocv.Matrix转为jpeg + buf, err := gocv.IMEncode(".jpg", img) + if err != nil { + fmt.Println("img encode err:", err) + worker.SetRedisSetRemove(online_conn_key, con_id) + goto end + } buf1 := buf.GetBytes() err2 := ws.WriteMessage(websocket.BinaryMessage, buf1) @@ -193,6 +199,10 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) { } time.Sleep(100 * time.Millisecond) t_count++ + err := img.Close() + if err != nil { + fmt.Println("close img err:", err) + } } end: