liuxiaolong
2019-06-27 3e3b79a7a35f8aa796fe05ce1af74547cd06e9c2
get img Width height and Data from gocv
3个文件已修改
57 ■■■■■ 已修改文件
controllers/camera.go 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/pollConfig.go 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/FaceSdkService.go 37 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
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 "摄像机id"
// @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 {
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 {
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){