liuxiaolong
2019-08-29 9298b8b7228af9c07872b41bffc894a6d9dd4e59
add UpdateFace
3个文件已修改
78 ■■■■■ 已修改文件
controllers/dbtableperson.go 76 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
extend/code/code.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
router/router.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/dbtableperson.go
@@ -2,9 +2,15 @@
import (
    "basic.com/dbapi.git"
    "basic.com/fileServer/WeedFSClient.git"
    "basic.com/pubsub/protomsg.git"
    "encoding/base64"
    "encoding/json"
    "io/ioutil"
    "strconv"
    "time"
    "webserver/extend/logger"
    "webserver/service"
    "github.com/gin-gonic/gin"
    "github.com/satori/go.uuid"
@@ -98,6 +104,76 @@
    }
}
// @Summary 更新底库人脸照片
// @Description 更新底库人脸照片
// @Accept  json
// @Produce json
// @Tags 底库人员
// @Param id formData string true "人员id"
// @Param file formData file true "人脸图片"
// @Success 200 {string} json "{"code":200, msg:"", success:true}"
// @Failure 500 {string} json "{"code":500, msg:"", success:false}"
// @Router /data/api-v/dbperson/updateFace [POST]
func (dbc DbPersonController) UpdateFace(c *gin.Context) {
    file, header, err := c.Request.FormFile("file")
    id := c.Request.FormValue("id")
    if err != nil || id == "" {
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    //文件的名称
    filename := header.Filename
    defer file.Close()
    // weedfs 上传
    fileBytes, err := ioutil.ReadAll(file)
    if err !=nil {
        util.ResponseFormat(c,code.ComError,"图片读取失败")
        return
    }
    //将上传的图片交人脸检测和人脸提取,获得特征
    var faceBase64=""
    faceArr, err, pI := service.GetFaceFeaFromSdk(fileBytes, time.Second*5)
    if faceArr ==nil {
        util.ResponseFormat(c,code.ComError,"未到提取人脸")
        return
    }
    var rcFace *protomsg.Rect
    if err ==nil && len(faceArr) >0 {
        if len(faceArr) >1 {
            util.ResponseFormat(c,code.ComError,"人脸大于一张,请换一张人脸图片")
            return
        }
        for _,r := range faceArr {
            //拿到人脸的坐标
            rcFace = r.Pos.RcFace
            faceBase64 = base64.StdEncoding.EncodeToString(r.Feats)//获取提取到的第一张人脸特征
            break
        }
    }
    var weedfsUri = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/submit"
    //根据人脸坐标扣出人脸小图
    t1 := time.Now()
    cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom))
    logger.Debug("SubImg用时:", time.Since(t1))
    t1 = time.Now()
    weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, filename, cutFaceImgData)
    logger.Debug("上传到weedfs用时:", time.Since(t1))
    t1 = time.Now()
    if e != nil {
        util.ResponseFormat(c,code.ComError,"人脸上传失败")
        return
    }
    var dbpApi dbapi.DbPersonApi
    b,d := dbpApi.UpdateFace(id,faceBase64,weedFilePath)
    if b {
        util.ResponseFormat(c,code.UpdateSuccess,d)
    } else {
        util.ResponseFormat(c,code.UpdateFail,"更新人脸失败")
    }
}
func UpdateDbPersonsOfDbTable(id string) (message string) {
    url := "http://" + config.EsInfo.Masterip + ":" + config.EsInfo.Httpport +
        "/" + config.EsInfo.EsIndex.Dbtablepersons.IndexName + "/_update_by_query?refresh"
extend/code/code.go
@@ -14,6 +14,7 @@
    Success = &Code{http.StatusOK, true, "请求处理成功"}
    AddSuccess = &Code{http.StatusOK,true,"添加成功"}
    UpdateSuccess = &Code{http.StatusOK,true,"更新成功"}
    UpdateFail = &Code{http.StatusBadRequest,false,"更新失败"}
    DelSuccess = &Code{http.StatusOK,true,"删除成功"}
    // RequestParamError 请求参数错误
    RequestParamError = &Code{http.StatusBadRequest, false, "请求参数有误"}
router/router.go
@@ -168,6 +168,7 @@
        vdbperson.POST("/fileUploadTest", fileController.UploadPersonTest)
        vdbperson.POST("/faceExtract",fileController.FaceExtract)
        vdbperson.POST("/searchByPhoto",fileController.SearchByPhoto)
        vdbperson.POST("/updateFace", dbPersonCont.UpdateFace)
    }
    // 系统设置 操作