panlei
2019-07-03 0c920726510355313e90dc802799f96981777a80
转换年龄描述,性别,种族
2个文件已修改
50 ■■■■ 已修改文件
insertdata/insertDataToEs.go 49 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
util/image.go 1 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
insertdata/insertDataToEs.go
@@ -30,10 +30,10 @@
    SdkName         string   `json:"sdkName"`
    Content         string   `json:"content"`
    LikeDate        string   `json:"likeDate"`
    Sex             int32    `json:"sex"`
    Sex             string   `json:"sex"`
    Age             int32    `json:"age"`
    AgeDescription  string   `json:"ageDescription"`
    Race            int32    `json:"race"`
    Race            string   `json:"race"`
    SmileLevel      int32    `json:"smileLevel"`
    BeautyLevel     int32    `json:"beautyLevel"`
    FaceFeature     string   `json:"faceFeature"`
@@ -131,11 +131,21 @@
                }
                i := protomsg.Image{}
                err = proto.Unmarshal(bdata, &i)
                log.Println("-------------------------------------------看下宽和高",i.Width,i.Height)
                bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height))
                resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String())
                if err != nil {
                    log.Println("上传小图出错")
                }
                sex := ""
                if face.ThftRes.Gender == 1 {
                    sex = "男"
                } else {
                    sex = "女"
                }
                race := getRaceString(face.ThftRes.Race)
                ageDescription := getDescription(face.ThftRes.Age)
                pervideo := PerVideoPicture{
                    uuid.NewV4().String(),
                    msg.Cid,
@@ -147,10 +157,10 @@
                    "人脸",
                    "",
                    time.Now().Format("2006-01-02 15:04:05"), // 只检测,没有比对时间
                    face.ThftRes.Gender,
                    sex,
                    face.ThftRes.Age,
                    "",
                    face.ThftRes.Race,
                    ageDescription,
                    race,
                    face.ThftRes.Smile,
                    face.ThftRes.Beauty,
                    "不是每个人脸算法都有",
@@ -310,3 +320,32 @@
    }
    return alarm
}
//获取年龄描述
func getDescription (age int32) string{
    ageInfo := "青年"
    if age > 0 && age < 7 {
        ageInfo = "童年"
    } else if age >= 7 && age < 18 {
        ageInfo = "少年"
    } else if age >= 18 && age < 40 {
        ageInfo = "青年"
    } else if age >= 40 && age < 65 {
        ageInfo = "中年"
    } else if age >= 65 {
        ageInfo = "老年"
    }
    return ageInfo
}
func getRaceString (i int32) string{
    race := ""
    if i == 1 {
        race = "white"
    } else if i == 2{
        race = "yellow"
    } else {
        race = "black"
    }
    return race
}
util/image.go
@@ -7,7 +7,6 @@
)
// 按尺寸去切图
func SubImg(i protomsg.Image,x0,y0,x1,y1 int,) []byte{
    img,_ := gocv.NewMatFromBytes(int(i.Height),int(i.Width),gocv.MatTypeCV8UC3,i.Data)
    rect := image.Rect(x0,y0,x1,y1)
    region := img.Region(rect)