| | |
| | | "basic.com/fileServer/WeedFSClient.git" |
| | | esApi "basic.com/pubsub/esutil.git" |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/godraw.git" |
| | | "basic.com/valib/logger.git" |
| | | "bytes" |
| | | "encoding/base64" |
| | |
| | | "errors" |
| | | "fmt" |
| | | "github.com/gin-gonic/gin" |
| | | "gocv.io/x/gocv" |
| | | "image" |
| | | "image/color" |
| | | "image/jpeg" |
| | |
| | | urlArr := make([]string,0) |
| | | for _,r := range faceArr { |
| | | rcFace := r.Pos.RcFace |
| | | cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom)) |
| | | cutFaceImgData,cutErr := util.SubCutImg(pI, rcFace, 20) |
| | | if cutErr != nil { |
| | | logger.Debug("util.SubCutImg err:", cutErr) |
| | | continue |
| | | } |
| | | weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, "FaceUrl", cutFaceImgData) |
| | | if e == nil{ |
| | | faceExtractedMap[weedFilePath] = FaceExtract{ |
| | |
| | | } |
| | | |
| | | func drawPolygonOnImg(i *protomsg.Image,faceArr *[]*protomsg.ResultFaceDetect) (*[]byte,error) { |
| | | rook, _ := gocv.NewMatFromBytes(int(i.Height), int(i.Width), gocv.MatTypeCV8UC3, i.Data) |
| | | defer rook.Close() |
| | | //yellow := color.RGBA{255, 255, 0, 0} |
| | | img,err := godraw.ToImage(i.Data, int(i.Width), int(i.Height)) |
| | | if err != nil { |
| | | return nil,err |
| | | } |
| | | red := color.RGBA{255, 0, 0, 0} |
| | | for _,faceResult := range *faceArr { |
| | | left := int(faceResult.Pos.RcFace.Left) |
| | | top := int(faceResult.Pos.RcFace.Top) |
| | | right := int(faceResult.Pos.RcFace.Right) |
| | | bottom := int(faceResult.Pos.RcFace.Bottom) |
| | | gocv.Rectangle(&rook, image.Rect(left,top,right,bottom), red, 1) |
| | | util.DrawRect(img.(*image.RGBA),int(faceResult.Pos.RcFace.Left),int(faceResult.Pos.RcFace.Top),int(faceResult.Pos.RcFace.Right), |
| | | int(faceResult.Pos.RcFace.Bottom), red) |
| | | } |
| | | fData,err := gocv.IMEncode(".jpg", rook) |
| | | return &fData,err |
| | | |
| | | quantity := 100 |
| | | jpgData, err := godraw.ImageToJpeg(img, &quantity) |
| | | return &jpgData,err |
| | | } |
| | | |
| | | type CompareResult struct { |
| | |
| | | faceArr, err, pI := service.GetFaceFeaFromSdk(fileBytes, time.Second*60) |
| | | if err ==nil && len(faceArr) ==1 { |
| | | rcFace := faceArr[0].Pos.RcFace |
| | | cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom)) |
| | | cutFaceImgData,_ := util.SubCutImg(pI, rcFace, 20) |
| | | weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, "FaceUrl", cutFaceImgData) |
| | | if e == nil{ |
| | | faceExtractedMap[weedFilePath] = FaceExtract{ |
| | |
| | | return |
| | | } |
| | | faceB = decodeF |
| | | } else { |
| | | util.ResponseFormat(c, code.ComError, "本条人脸抓拍特征为空,请检查") |
| | | return |
| | | } |
| | | } |
| | | |
| | |
| | | break |
| | | } |
| | | //根据人脸坐标扣出人脸小图 |
| | | cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom)) |
| | | cutFaceImgData,_ := util.SubCutImg(pI, rcFace, 20) |
| | | weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, "testCutFace", cutFaceImgData) |
| | | if e !=nil{ |
| | | util.ResponseFormat(c,code.ComError,"文件上传失败") |
| | |
| | | var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit?collection=persistent" |
| | | //根据人脸坐标扣出人脸小图 |
| | | t1 := time.Now() |
| | | cutFaceImgData := util.SubImg(*pI, int(rcFace.Left), int(rcFace.Top), int(rcFace.Right), int(rcFace.Bottom)) |
| | | cutFaceImgData,cutErr := util.SubCutImg(pI, rcFace, 20) |
| | | if cutErr != nil { |
| | | logger.Debug("util.SubCutImg err:", cutErr) |
| | | return "", nil, cutErr,"","" |
| | | } |
| | | logger.Debug("SubImg用时:", time.Since(t1)) |
| | | t1 = time.Now() |
| | | weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, filename, cutFaceImgData) |
| | |
| | | result = addDbPerson(dbperson) |
| | | } |
| | | |
| | | logger.Debug("addDbPerson用时:", time.Since(t1)) |
| | | logger.Debug("addDbPerson用时:", time.Since(t1), "result:", result) |
| | | return fileNameOnly, result, nil,faceBase64, weedFilePath |
| | | |
| | | } |