Compare commits
17 Commits
8de01c90c2
...
69f81addeb
| Author | SHA1 | Date |
|---|---|---|
|
|
69f81addeb | |
|
|
1d48452f23 | |
|
|
1e8b72e9b2 | |
|
|
5bd2707ffd | |
|
|
74d04602d5 | |
|
|
a202a2ef4c | |
|
|
318907eeac | |
|
|
a965a9dd7d | |
|
|
66e341e938 | |
|
|
b8b6cb838c | |
|
|
6aeb4dd4f8 | |
|
|
87c3522374 | |
|
|
59ae9d7f6f | |
|
|
4c1a397775 | |
|
|
8fbc54c2af | |
|
|
749eb5c2ee | |
|
|
f83e720224 |
1
go.mod
1
go.mod
|
|
@ -11,6 +11,7 @@ require (
|
|||
github.com/google/uuid v1.6.0
|
||||
github.com/gorilla/websocket v1.5.3
|
||||
github.com/robfig/cron/v3 v3.0.1
|
||||
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6
|
||||
gocv.io/x/gocv v0.39.0
|
||||
gorm.io/driver/mysql v1.5.7
|
||||
gorm.io/driver/postgres v1.5.11
|
||||
|
|
|
|||
4
go.sum
4
go.sum
|
|
@ -106,10 +106,10 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
|
|||
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
|
||||
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
|
||||
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
|
||||
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6 h1:TtyC78WMafNW8QFfv3TeP3yWNDG+uxNkk9vOrnDu6JA=
|
||||
github.com/ulule/deepcopier v0.0.0-20200430083143-45decc6639b6/go.mod h1:h8272+G2omSmi30fBXiZDMkmHuOgonplfKIKjQWzlfs=
|
||||
gocv.io/x/gocv v0.39.0 h1:vWHupDE22LebZW6id2mVeT767j1YS8WqGt+ZiV7XJXE=
|
||||
gocv.io/x/gocv v0.39.0/go.mod h1:zYdWMj29WAEznM3Y8NsU3A0TRq/wR/cy75jeUypThqU=
|
||||
gocv.io/x/gocv v0.40.0 h1:kGBu/UVj+dO6A9dhQmGOnCICSL7ke7b5YtX3R3azdXI=
|
||||
gocv.io/x/gocv v0.40.0/go.mod h1:zYdWMj29WAEznM3Y8NsU3A0TRq/wR/cy75jeUypThqU=
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
|
||||
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ func SetUpToolGroup(router *gin.Engine) {
|
|||
}
|
||||
|
||||
// 跨域访问:cross origin resource share
|
||||
func CorsHandler() gin.HandlerFunc {
|
||||
func CrosHandler() gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
//method := context.Request.Method
|
||||
context.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
|
@ -68,17 +68,17 @@ func GetVideoStream(c *gin.Context) {
|
|||
var req videoStreamReq
|
||||
id, _ := c.Get("id")
|
||||
id1 := id.(int)
|
||||
//将query参数绑定到结构体
|
||||
//校验权限
|
||||
device := service.GetDevice(req.ID, id1)
|
||||
if device.ID == 0 {
|
||||
c.JSON(400, gin.H{"error": "device not exist"})
|
||||
return
|
||||
}
|
||||
|
||||
if err := c.ShouldBind(&req); err != nil {
|
||||
c.JSON(400, gin.H{"error": err.Error()})
|
||||
return
|
||||
} else {
|
||||
//校验权限
|
||||
device := service.GetDevice(req.ID, id1)
|
||||
if device.ID == 0 {
|
||||
c.JSON(400, gin.H{"error": "device not exist"})
|
||||
return
|
||||
}
|
||||
//查看id是否存在
|
||||
index := -1
|
||||
for _, device := range proto.Config.DeviceInfo {
|
||||
|
|
@ -99,20 +99,14 @@ func GetVideoStream(c *gin.Context) {
|
|||
//设备流
|
||||
c.Stream(func(w io.Writer) bool {
|
||||
var count int
|
||||
var frame gocv.Mat
|
||||
for {
|
||||
cnt := service.GetDeviceCurrentFrameV2(&frame, req.ID)
|
||||
frame, cnt := service.GetDeviceCurrentFrame(req.ID)
|
||||
if cnt == count {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
//gocv.Matrix转为jpeg
|
||||
img, err2 := gocv.IMEncode(".jpg", frame)
|
||||
if err2 != nil {
|
||||
fmt.Printf("img encode err:%v", err2)
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
img, err := gocv.IMEncode(".jpg", frame)
|
||||
frame_ := img.GetBytes()
|
||||
|
||||
_, err = w.Write([]byte("--frame\r\nContent-Type: image/jpeg\r\n\r\n"))
|
||||
|
|
@ -167,15 +161,14 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) {
|
|||
//图片计数器
|
||||
count := 0
|
||||
//定时器,发送计数器
|
||||
tCount := 0
|
||||
//从service获取当前帧
|
||||
var img gocv.Mat
|
||||
t_count := 0
|
||||
for {
|
||||
c := service.GetDeviceCurrentFrameV2(&img, device_id)
|
||||
//从service获取当前帧
|
||||
img, c := service.GetDeviceCurrentFrameV3(device_id)
|
||||
if c != count {
|
||||
//将img转[]byte
|
||||
if img.Empty() {
|
||||
log.Printf("device:%d img is empty! count=%d", device_id, c)
|
||||
log.Printf("device:%d img is empty! count = %d \n", device_id, c)
|
||||
} else {
|
||||
//gocv.Matrix转为jpeg
|
||||
buf, err := gocv.IMEncode(".jpg", img)
|
||||
|
|
@ -200,23 +193,19 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) {
|
|||
}
|
||||
} else {
|
||||
//每秒发送一次心跳检测
|
||||
if tCount%10 == 0 {
|
||||
if t_count%10 == 0 {
|
||||
err := ws.WriteControl(websocket.PingMessage, []byte{}, time.Now().Add(time.Second))
|
||||
if err != nil {
|
||||
log.Printf("Connection check failed:%v", err)
|
||||
worker.SetRedisSetRemove(online_conn_key, con_id)
|
||||
break
|
||||
} else {
|
||||
log.Printf("Connection check success")
|
||||
}
|
||||
}
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
tCount++
|
||||
}
|
||||
|
||||
//关闭img
|
||||
err := img.Close()
|
||||
if err != nil {
|
||||
log.Printf("img close err:%v", err)
|
||||
t_count++
|
||||
}
|
||||
|
||||
// 查看是否还有其他连接,没有则设置 is_play 为 0
|
||||
|
|
|
|||
18
main.go
18
main.go
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/gin-gonic/gin"
|
||||
"github.com/golang-jwt/jwt"
|
||||
"github.com/robfig/cron/v3"
|
||||
"gocv.io/x/gocv"
|
||||
"log"
|
||||
"runtime"
|
||||
"strconv"
|
||||
|
|
@ -34,7 +35,7 @@ func main() {
|
|||
if err0 != nil {
|
||||
panic("failed to connect redis:" + err0.Error())
|
||||
}
|
||||
r.Use(handler.CorsHandler())
|
||||
r.Use(handler.CrosHandler())
|
||||
r.Use(JWTAuthMiddleware()) // 使用 JWT 认证中间件
|
||||
handler.SetUpToolGroup(r) // Tool
|
||||
err := worker.InitRedis()
|
||||
|
|
@ -70,14 +71,13 @@ func init() {
|
|||
if err != nil {
|
||||
panic("failed to read config file:" + err.Error())
|
||||
}
|
||||
service.DeviceFrameCount = make(map[int]int)
|
||||
for _, device := range proto.Config.DeviceInfo {
|
||||
//service.DeviceRWMap[device.ID] = sync.RWMutex{}
|
||||
//service.DeviceCurrentFrameMap[device.ID] = gocv.NewMat()
|
||||
//service.DeviceIsGettingFrame[device.ID] = false
|
||||
service.DeviceRWMap.Store(device.ID, &sync.RWMutex{})
|
||||
//service.DeviceCurrentFrameMap.Store(device.ID, gocv.NewMat())
|
||||
service.DeviceFrameCount[device.ID] = 0
|
||||
service.DeviceCurrentFrameMap.Store(device.ID, gocv.NewMat())
|
||||
service.DeviceFrameCount.Store(device.ID, 0)
|
||||
service.DeviceIsGettingFrame.Store(device.ID, false)
|
||||
}
|
||||
}
|
||||
|
|
@ -99,11 +99,17 @@ func ReadConfigAndSetSystem() {
|
|||
if !ok {
|
||||
//说明没有这个设备,需初始化添加
|
||||
service.DeviceRWMap.Store(device.ID, &sync.RWMutex{})
|
||||
//service.DeviceCurrentFrameMap.Store(device.ID, gocv.NewMat())
|
||||
service.DeviceFrameCount[device.ID] = 0
|
||||
service.DeviceCurrentFrameMap.Store(device.ID, gocv.NewMat())
|
||||
service.DeviceFrameCount.Store(device.ID, 0)
|
||||
service.DeviceIsGettingFrame.Store(device.ID, false)
|
||||
}
|
||||
if is_get == false && device.NextStop == false { //如果设备流已经停止且不暂停,则开启
|
||||
switch device.ID {
|
||||
case 1:
|
||||
service.Device1CurrentFrame = gocv.NewMat()
|
||||
case 50:
|
||||
service.Device50CurrentFrame = gocv.NewMat()
|
||||
}
|
||||
go service.GetVideoStream(device.ID)
|
||||
log.Printf("device:%d has started!\n", device.ID)
|
||||
}
|
||||
|
|
|
|||
208
service/tool.go
208
service/tool.go
|
|
@ -15,15 +15,45 @@ import (
|
|||
)
|
||||
|
||||
var DeviceRWMap = &sync.Map{}
|
||||
|
||||
// var DeviceCurrentFrameMap = &sync.Map{}
|
||||
var DeviceFrameCount map[int]int
|
||||
var DeviceCurrentFrameMap = &sync.Map{}
|
||||
var DeviceFrameCount = &sync.Map{}
|
||||
var DeviceIsGettingFrame = &sync.Map{}
|
||||
var Device1CurrentFrame gocv.Mat
|
||||
var Device50CurrentFrame gocv.Mat
|
||||
var Device73CurrentFrame gocv.Mat
|
||||
|
||||
func SetDeviceCurrentFrame(frame *gocv.Mat, device_id int) error {
|
||||
func SetDeviceCurrentFrame(frame gocv.Mat, device_id int) error {
|
||||
//获取读写锁
|
||||
mutex_, ok := DeviceRWMap.Load(device_id)
|
||||
if !ok {
|
||||
return fmt.Errorf("设备:%s 读写锁不存在", device_id)
|
||||
}
|
||||
mutex := mutex_.(*sync.RWMutex)
|
||||
mutex.Lock()
|
||||
defer mutex.Unlock()
|
||||
//获取前一帧,将前一帧释放
|
||||
framePrev, ok := DeviceCurrentFrameMap.Load(device_id)
|
||||
if ok {
|
||||
frame_, ok2 := framePrev.(gocv.Mat)
|
||||
if ok2 {
|
||||
err2 := frame_.Close()
|
||||
if err2 != nil {
|
||||
log.Printf("设备:%d, 错误: 无法关闭帧\n", device_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
//设置当前帧
|
||||
DeviceCurrentFrameMap.Store(device_id, frame)
|
||||
frame_count, ok := DeviceFrameCount.Load(device_id)
|
||||
if !ok {
|
||||
return fmt.Errorf("设备:%s 当前帧计数不存在", device_id)
|
||||
}
|
||||
frame_count_ := frame_count.(int)
|
||||
frame_count_++
|
||||
DeviceFrameCount.Store(device_id, frame_count_)
|
||||
return nil
|
||||
}
|
||||
|
||||
func SetDeviceCurrentFrameV2(frame *gocv.Mat, device_id int) error {
|
||||
//获取读写锁
|
||||
mutex_, ok := DeviceRWMap.Load(device_id)
|
||||
if !ok {
|
||||
|
|
@ -35,28 +65,34 @@ func SetDeviceCurrentFrame(frame *gocv.Mat, device_id int) error {
|
|||
//设置当前帧
|
||||
switch device_id {
|
||||
case 1:
|
||||
//err := Device1CurrentFrame.Close()
|
||||
//if err != nil {
|
||||
// log.Printf("设备:%d, 错误: 无法关闭帧\n", device_id)
|
||||
//}
|
||||
if Device1CurrentFrame.Empty() {
|
||||
Device1CurrentFrame = gocv.NewMatWithSize((*frame).Rows(), (*frame).Cols(), (*frame).Type())
|
||||
}
|
||||
(*frame).CopyTo(&Device1CurrentFrame)
|
||||
//err := deepcopier.Copy(*frame).To(&Device1CurrentFrame)
|
||||
//if err != nil {
|
||||
// log.Printf("设备:%d, 错误: 无法设置帧,err: %s \n", device_id, err.Error())
|
||||
//}
|
||||
//查看帧状态
|
||||
//log.Printf("frame:%v,Device1CurrentFrame:%v \n", (*frame).Empty(), Device1CurrentFrame.Empty())
|
||||
//Device1CurrentFrame = *frame
|
||||
case 50:
|
||||
if Device50CurrentFrame.Empty() {
|
||||
Device50CurrentFrame = gocv.NewMatWithSize((*frame).Rows(), (*frame).Cols(), (*frame).Type())
|
||||
}
|
||||
(*frame).CopyTo(&Device50CurrentFrame)
|
||||
case 73:
|
||||
if Device73CurrentFrame.Empty() {
|
||||
Device73CurrentFrame = gocv.NewMatWithSize((*frame).Rows(), (*frame).Cols(), (*frame).Type())
|
||||
}
|
||||
(*frame).CopyTo(&Device73CurrentFrame)
|
||||
}
|
||||
|
||||
frameCount, ok := DeviceFrameCount[device_id]
|
||||
frame_count, ok := DeviceFrameCount.Load(device_id)
|
||||
if !ok {
|
||||
return fmt.Errorf("设备:%s 当前帧计数不存在", device_id)
|
||||
}
|
||||
frameCount++
|
||||
DeviceFrameCount[device_id] = frameCount
|
||||
frame_count_ := frame_count.(int)
|
||||
frame_count_++
|
||||
DeviceFrameCount.Store(device_id, frame_count_)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -79,33 +115,77 @@ func GetDeviceCurrentFrameV2(frame *gocv.Mat, deviceId int) int {
|
|||
}
|
||||
mutex.RLock()
|
||||
defer mutex.RUnlock()
|
||||
var frame_ gocv.Mat
|
||||
//获取当前帧
|
||||
switch deviceId {
|
||||
case 1:
|
||||
if frame.Empty() {
|
||||
*frame = gocv.NewMatWithSize(Device1CurrentFrame.Rows(), Device1CurrentFrame.Cols(), Device1CurrentFrame.Type())
|
||||
}
|
||||
Device1CurrentFrame.CopyTo(frame)
|
||||
case 50:
|
||||
if frame.Empty() {
|
||||
*frame = gocv.NewMatWithSize(Device50CurrentFrame.Rows(), Device50CurrentFrame.Cols(), Device50CurrentFrame.Type())
|
||||
}
|
||||
Device50CurrentFrame.CopyTo(frame)
|
||||
case 73:
|
||||
if frame.Empty() {
|
||||
*frame = gocv.NewMatWithSize(Device73CurrentFrame.Rows(), Device73CurrentFrame.Cols(), Device73CurrentFrame.Type())
|
||||
}
|
||||
Device73CurrentFrame.CopyTo(frame)
|
||||
|
||||
}
|
||||
|
||||
frameCount, ok := DeviceFrameCount[deviceId]
|
||||
frameIface, ok := DeviceCurrentFrameMap.Load(deviceId)
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
return frameCount
|
||||
frame_, ok = frameIface.(gocv.Mat)
|
||||
if !ok {
|
||||
log.Printf("DeviceCurrentFrameMap 存储的不是 gocv.Mat 类型,device_id: %d \n", deviceId)
|
||||
}
|
||||
*frame = frame_
|
||||
frame_countIface, ok := DeviceFrameCount.Load(deviceId)
|
||||
if !ok {
|
||||
return -1
|
||||
}
|
||||
frame_count, ok := frame_countIface.(int)
|
||||
if !ok {
|
||||
log.Printf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", deviceId)
|
||||
}
|
||||
return frame_count
|
||||
}
|
||||
|
||||
func GetDeviceCurrentFrameV3(deviceId int) (gocv.Mat, int) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
log.Printf("设备:%d 错误: %v\n", deviceId, err)
|
||||
}
|
||||
}()
|
||||
|
||||
//获取读写锁
|
||||
mutex_, ok := DeviceRWMap.Load(deviceId)
|
||||
if !ok {
|
||||
log.Printf("DeviceRWMap 读写锁不存在,device_id: %d \n", deviceId)
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
mutex, ok := mutex_.(*sync.RWMutex)
|
||||
if !ok {
|
||||
log.Printf("DeviceRWMap 存储的不是 *sync.RWMutex 类型,device_id: %d \n", deviceId)
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
mutex.RLock()
|
||||
defer mutex.RUnlock()
|
||||
//获取当前帧
|
||||
var frame gocv.Mat
|
||||
switch deviceId {
|
||||
case 1:
|
||||
frame = gocv.NewMatWithSize(Device1CurrentFrame.Rows(), Device1CurrentFrame.Cols(), Device1CurrentFrame.Type())
|
||||
Device1CurrentFrame.CopyTo(&frame)
|
||||
//查看帧状态
|
||||
//log.Printf("frame:%v,Device1CurrentFrame:%v \n", frame.Empty(), Device1CurrentFrame.Empty())
|
||||
|
||||
case 50:
|
||||
frame = gocv.NewMatWithSize(Device50CurrentFrame.Rows(), Device50CurrentFrame.Cols(), Device50CurrentFrame.Type())
|
||||
Device50CurrentFrame.CopyTo(&frame)
|
||||
//查看帧状态
|
||||
//log.Printf("frame:%v,Device50CurrentFrame:%v\n", frame.Empty(), Device50CurrentFrame.Empty())
|
||||
|
||||
}
|
||||
|
||||
frame_countIface, ok := DeviceFrameCount.Load(deviceId)
|
||||
if !ok {
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
frame_count, ok := frame_countIface.(int)
|
||||
if !ok {
|
||||
log.Printf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", deviceId)
|
||||
}
|
||||
//查看地址
|
||||
//log.Printf("frame:%p,Device1CurrentFrame:%p,Device50CurrentFrame:%p\n", &frame, &Device1CurrentFrame, &Device50CurrentFrame)
|
||||
return frame, frame_count
|
||||
}
|
||||
func GetDeviceCurrentFrame(deviceId int) (gocv.Mat, int) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
|
|
@ -126,34 +206,24 @@ func GetDeviceCurrentFrame(deviceId int) (gocv.Mat, int) {
|
|||
}
|
||||
mutex.RLock()
|
||||
defer mutex.RUnlock()
|
||||
var ret gocv.Mat
|
||||
if ret.Empty() {
|
||||
|
||||
}
|
||||
//获取当前帧
|
||||
switch deviceId {
|
||||
case 1:
|
||||
if ret.Empty() {
|
||||
ret = gocv.NewMatWithSize(Device1CurrentFrame.Rows(), Device1CurrentFrame.Cols(), Device1CurrentFrame.Type())
|
||||
}
|
||||
Device1CurrentFrame.CopyTo(&ret)
|
||||
case 50:
|
||||
if ret.Empty() {
|
||||
ret = gocv.NewMatWithSize(Device50CurrentFrame.Rows(), Device50CurrentFrame.Cols(), Device50CurrentFrame.Type())
|
||||
}
|
||||
Device50CurrentFrame.CopyTo(&ret)
|
||||
case 73:
|
||||
if ret.Empty() {
|
||||
ret = gocv.NewMatWithSize(Device73CurrentFrame.Rows(), Device73CurrentFrame.Cols(), Device73CurrentFrame.Type())
|
||||
}
|
||||
Device73CurrentFrame.CopyTo(&ret)
|
||||
}
|
||||
frameCount, ok := DeviceFrameCount[deviceId]
|
||||
frameIface, ok := DeviceCurrentFrameMap.Load(deviceId)
|
||||
if !ok {
|
||||
log.Printf("设备:%d 当前帧计数不存在\n", deviceId)
|
||||
frameCount = -1
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
return ret, frameCount
|
||||
frame, ok := frameIface.(gocv.Mat)
|
||||
if !ok {
|
||||
log.Printf("DeviceCurrentFrameMap 存储的不是 gocv.Mat 类型,device_id: %d \n", deviceId)
|
||||
}
|
||||
frame_countIface, ok := DeviceFrameCount.Load(deviceId)
|
||||
if !ok {
|
||||
return gocv.NewMat(), -1
|
||||
}
|
||||
frame_count, ok := frame_countIface.(int)
|
||||
if !ok {
|
||||
log.Printf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", deviceId)
|
||||
}
|
||||
return frame, frame_count
|
||||
}
|
||||
|
||||
func getVideoFrame(device proto.DeviceInfo) {
|
||||
|
|
@ -182,7 +252,6 @@ func getVideoFrame(device proto.DeviceInfo) {
|
|||
lineType := 2
|
||||
z := 0
|
||||
var frame gocv.Mat
|
||||
frame = gocv.NewMat()
|
||||
for {
|
||||
if device.LogFrame > 0 && z%device.LogFrame == 0 {
|
||||
log.Printf("设备:%d 当前帧: %d\n", device.ID, z)
|
||||
|
|
@ -190,6 +259,7 @@ func getVideoFrame(device proto.DeviceInfo) {
|
|||
if device.NextStop {
|
||||
break
|
||||
}
|
||||
frame = gocv.NewMat()
|
||||
ok := webcam.Read(&frame)
|
||||
if !ok {
|
||||
log.Printf("设备:%v 错误: 无法从视频流中读取帧\n", device)
|
||||
|
|
@ -208,17 +278,23 @@ func getVideoFrame(device proto.DeviceInfo) {
|
|||
break
|
||||
}
|
||||
currentTime := time.Now().Format("2006-01-02 15:04:05")
|
||||
gocv.PutText(&frame, currentTime, image.Point{X: 10, Y: 20}, font, fontScale, fontColor, lineType)
|
||||
gocv.PutText(&frame, currentTime, image.Point{10, 20}, font, fontScale, fontColor, lineType)
|
||||
//需要将帧付给全局变量
|
||||
err3 := SetDeviceCurrentFrame(&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())
|
||||
}
|
||||
}
|
||||
err2 := frame.Close()
|
||||
if err2 != nil {
|
||||
log.Printf("设备:%d 错误: 无法释放帧资源,err:%s \n", device.ID, err.Error())
|
||||
//关闭帧
|
||||
err4 := frame.Close()
|
||||
if err4 != nil {
|
||||
log.Printf("设备:%d 错误: 无法关闭帧,err:%s \n", device.ID, err4.Error())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue