From 3e3b79a7a35f8aa796fe05ce1af74547cd06e9c2 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期四, 27 六月 2019 16:23:40 +0800 Subject: [PATCH] get img Width height and Data from gocv --- controllers/camera.go | 18 ++++++++++-------- controllers/pollConfig.go | 2 +- service/FaceSdkService.go | 37 ++++++++++++++----------------------- 3 files changed, 25 insertions(+), 32 deletions(-) diff --git a/controllers/camera.go b/controllers/camera.go index 9efc660..087703d 100644 --- a/controllers/camera.go +++ b/controllers/camera.go @@ -254,26 +254,28 @@ } } +type CameraChangeRunVo struct { + CameraIds []string `json:"camera_ids"` + RunType int `json:"run_type"` +} + // @Summary 鎽勫儚鏈鸿疆璇㈠拰瀹炴椂鐘舵�佸垏鎹� // @Description 鎽勫儚鏈鸿疆璇㈠拰瀹炴椂鐘舵�佸垏鎹� // @Produce json // @Tags camera -// @Param cameraId query string true "鎽勫儚鏈篿d" -// @Param runType query int true "0锛氬疄鏃跺垏杞锛�1锛氳疆璇㈠垏瀹炴椂" +// @Param changeRunBody body controllers.CameraChangeRunVo true "鍙傛暟缁撴瀯浣�,0锛氬疄鏃跺垏杞锛�1锛氳疆璇㈠垏瀹炴椂" // @Success 200 {string} json "{"code":200, success:true, msg:"", data:""}" // @Failure 500 {string} json "{"code":500, success:false, msg:"",data:""}" // @Router /data/api-v/camera/changeRunType [post] func (cc CameraController) ChangeRunType(c *gin.Context){ - cameraId := c.PostForm("cameraId") - runTypeStr := c.PostForm("runType") - runType,err := strconv.Atoi(runTypeStr) - if cameraId == "" || err!=nil || (runType !=0 && runType !=1){ + var ccrVo CameraChangeRunVo + if err := c.BindJSON(&ccrVo);err !=nil{ util.ResponseFormat(c,code.RequestParamError,"鍙傛暟鏈夎") return } - + paramBody := util.Struct2Map(ccrVo) var api dbapi.CameraApi - b, data := api.ChangeRunType(cameraId, runType) + b, data := api.ChangeRunType(paramBody) if b { util.ResponseFormat(c,code.Success,data) } else { diff --git a/controllers/pollConfig.go b/controllers/pollConfig.go index 67ac74f..18a23e2 100644 --- a/controllers/pollConfig.go +++ b/controllers/pollConfig.go @@ -35,7 +35,7 @@ return } var api dbapi.SysSetApi - b, data := api.SavePollDelay(period) + b, data := api.SavePollPeriod(period) if b { util.ResponseFormat(c,code.Success,data) } else { diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go index a58a804..93935d1 100644 --- a/service/FaceSdkService.go +++ b/service/FaceSdkService.go @@ -8,9 +8,7 @@ "github.com/gogo/protobuf/proto" "github.com/pierrec/lz4" "github.com/satori/go.uuid" - "image" - "io/ioutil" - "os" + "gocv.io/x/gocv" "time" ) @@ -64,28 +62,21 @@ formatTimeStr := time.Unix(timeUnix, 0).Format("2006-01-02 15:04:05") filePath := "/home/user/workspace/timg.jpg" - file, err := os.Open(filePath) - defer file.Close() - if err !=nil{ - fmt.Println("image not exist") - return i - } else { - img, _, err := image.Decode(file) - bytes, err := ioutil.ReadFile(filePath) - if err !=nil { - return i - } - b := img.Bounds() - width := b.Max.X - height := b.Max.Y - i = protomsg.Image{ - Width:int32(width), - Height:int32(height), - Timestamp:formatTimeStr, - Data:bytes, - } + picMat := gocv.IMRead(filePath, gocv.IMReadColor) + + defer picMat.Close() + + if picMat.Empty() { + fmt.Println("file not exist") return i } + i = protomsg.Image{ + Width:int32(picMat.Rows()), + Height:int32(picMat.Cols()), + Timestamp:formatTimeStr, + Data:[]byte(picMat.DataPtrUint8()), + } + return i } func PushImgMsg(is protomsg.Recvmsg){ -- Gitblit v1.8.0