From 0cc8d28ff6bae56fe8f4388aedd4ab1d46a11c96 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期三, 24 七月 2019 19:03:39 +0800 Subject: [PATCH] config compServerList --- controllers/fileController.go | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 113 insertions(+), 0 deletions(-) diff --git a/controllers/fileController.go b/controllers/fileController.go index 8aa82b6..2123a1b 100644 --- a/controllers/fileController.go +++ b/controllers/fileController.go @@ -3,11 +3,14 @@ import ( "basic.com/pubsub/protomsg.git" "basic.com/fileServer/WeedFSClient.git" + "basic.com/valib/deliver.git" "bytes" "encoding/base64" + "encoding/json" "errors" "fmt" "github.com/gin-gonic/gin" + "github.com/gogo/protobuf/proto" "github.com/satori/go.uuid" "image" "image/jpeg" @@ -25,6 +28,7 @@ "webserver/extend/util" "webserver/models" "webserver/service" + esApi "basic.com/pubsub/esutil.git" ) type FileController struct { @@ -94,6 +98,115 @@ } } + +type FaceExtract struct { + Url string `json:"url"` + FaceBytes []byte `json:"faceBytes"` +} +var faceExtractedMap = make(map[string]FaceExtract,0) + +// @Summary 浜鸿劯鎻愬彇 +// @Description 浜鸿劯鎻愬彇 +// @Produce json +// @Tags 浠ュ浘鎼滃浘 +// @Param file formData file true "浜哄憳鍥剧墖" +// @Success 200 {string} json "{"code":200, msg:"", data:"", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"", data:"", success:false}" +// @Router /data/api-v/dbperson/faceExtract [POST] +func (controller FileController) FaceExtract(c *gin.Context) { + file, _, err := c.Request.FormFile("file") //image杩欎釜鏄痷plaodify鍙傛暟瀹氫箟涓殑 'fileObjName':'image' + if err != nil { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") + return + } + var weedfsUri = "http://"+config.WeedFs.Ip+":"+strconv.Itoa(config.WeedFs.UploadPort)+"/submit" + + //灏嗕笂浼犵殑鍥剧墖浜や汉鑴告娴嬪拰浜鸿劯鎻愬彇锛岃幏寰楃壒寰� + fileBytes, _ := ioutil.ReadAll(file) + faceArr, err, pI := service.GetFaceFeaFromSdk(fileBytes, time.Second*60) + if err ==nil && len(faceArr) >0 { + 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)) + weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, "FaceUrl", cutFaceImgData) + if e == nil{ + faceExtractedMap[weedFilePath] = FaceExtract{ + Url:weedFilePath, + FaceBytes:r.Feats, + } + urlArr = append(urlArr, weedFilePath) + } + } + + util.ResponseFormat(c,code.Success,urlArr) + } else { + util.ResponseFormat(c,code.ComError,"鏈彁鍙栧埌浜鸿劯") + } +} + +// @Summary 浠ュ浘鎼滃浘 +// @Description 浠ュ浘鎼滃浘 +// @Produce json +// @Tags 浠ュ浘鎼滃浘 +// @Param url formData string true "url" +// @Success 200 {string} json "{"code":200, msg:"", data:"", success:true}" +// @Failure 500 {string} json "{"code":500, msg:"", data:"", success:false}" +// @Router /data/api-v/dbperson/searchByPhoto [POST] +func (controller FileController) SearchByPhoto(c *gin.Context) { + photoUrl := c.Request.FormValue("url") + if photoUrl == "" { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") + return + } + if face,ok := faceExtractedMap[photoUrl];!ok{ + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") + return + } else { + arg := protomsg.CompareArgs{ + FaceFeature:face.FaceBytes, + CompareThreshold:0.2, + } + b, err := proto.Marshal(&arg) + if err !=nil{ + util.ResponseFormat(c, code.ComError, "璇锋眰marshal澶辫触") + return + } + compServerList := config.CompServerInfo.Url + fmt.Println("compServerList:", compServerList) + resultList :=make([]protomsg.Dbperson,0) + for _,str :=range compServerList{ + reqUrl := "tcp://"+str + reqClient := deliver.NewClient(deliver.ReqRep, reqUrl) + err = reqClient.Send(b) + if err !=nil{ + continue + } + resultB, err := reqClient.Recv() + if err !=nil{ + continue + } + m :=make(map[string]float32,0) + err = json.Unmarshal(resultB, &m) + if err !=nil{ + continue + } + personIds := make([]string,len(m)) + for k,_ :=range m{ + personIds = append(personIds,k) + } + esServerIp := config.EsInfo.Masterip + esServerPort := config.EsInfo.Httpport + index := config.EsInfo.EsIndex.Dbtablepersons.IndexName + dbpeople, e := esApi.Dbpersoninfosbyid(personIds, index, esServerIp, esServerPort) + if e ==nil{ + resultList = append(resultList,dbpeople...) + } + } + util.ResponseFormat(c,code.Success,resultList) + } +} + // @Description 浜哄憳鐓х墖涓婁紶骞惰幏鍙栫壒寰佸�� // @Router /data/api-v/dbperson/fileUploadTest [POST] func (controller FileController) UploadPersonTest(c *gin.Context) { -- Gitblit v1.8.0