From a527225f7f3cc93882aa870c20f0985d07d6fe92 Mon Sep 17 00:00:00 2001 From: sunty <suntianyu0923@163.com> Date: 星期四, 22 八月 2019 18:12:03 +0800 Subject: [PATCH] set yn main port 7100 --- controllers/fileController.go | 176 +++++++++++++++++++++++++--------------------------------- 1 files changed, 77 insertions(+), 99 deletions(-) diff --git a/controllers/fileController.go b/controllers/fileController.go index 6b8016f..696584d 100644 --- a/controllers/fileController.go +++ b/controllers/fileController.go @@ -46,8 +46,8 @@ //var weedfsUri = "http://192.168.1.182:9500/submit" -// @Summary 渚濇嵁鍥剧墖娣诲姞搴曞簱浜哄憳 -// @Description 渚濇嵁鍥剧墖娣诲姞搴曞簱杩斿洖鏁版嵁浜哄憳 +// @Summary 鍗曞紶鍥剧墖涓婁紶锛屾坊鍔犲簳搴撲汉鍛� +// @Description 鍗曞紶鍥剧墖涓婁紶锛屾坊鍔犲簳搴撹繑鍥炴暟鎹汉鍛� // @Accept mpfd // @Produce json // @Tags dbperson 搴曞簱浜哄憳 @@ -184,48 +184,45 @@ Enable int32 `json:"enable"` } -type CompareSortResult []CompareResult - -func (s CompareSortResult) Len() int{ - return len(s) -} -func (s CompareSortResult) Swap(i,j int){ - s[i],s[j] = s[j],s[i] -} -func (s CompareSortResult) Less(i,j int) bool{ - return s[i].CompareScore > s[j].CompareScore +type ScoreIndex struct { + CompareScore float32 + Index int } //濉厖鍚戝墠绔繑鍥炵殑鏁版嵁 -func FillDataToCompareResult(compResult *protomsg.SdkCompareResult) CompareSortResult { - //resultList :=make([]CompareResult,0) - var resultList = CompareSortResult{} +func FillDataToCompareResult(compResult *protomsg.SdkCompareResult) []CompareResult { - dbPersonM := make(map[string]*protomsg.SdkCompareEach, 0) - captureM := make(map[string]*protomsg.SdkCompareEach, 0) - personIds :=make([]string,0) + var resultList = make([]CompareResult, len(compResult.CompareResult)) + dbPersonM := make(map[string]ScoreIndex, 0) + captureM := make(map[string]ScoreIndex, 0) + personIds := make([]string,0) captureIds := make([]string,0) - for _,v :=range compResult.CompareResult{ + for idx,v :=range compResult.CompareResult{ if v.Tableid == service.CaptureTable { - captureM[v.Id] = v + captureM[v.Id] = ScoreIndex{ + Index: idx, + CompareScore: v.CompareScore, + } captureIds = append(captureIds,v.Id) } else { - dbPersonM[v.Id] = v + dbPersonM[v.Id] = ScoreIndex{ + Index: idx, + CompareScore: v.CompareScore, + } personIds = append(personIds,v.Id) } } logger.Debug("comp len(personIds):", len(personIds)) logger.Debug("comp len(captureIds):", len(captureIds)) - esServerIp := config.EsInfo.Masterip - esServerPort := config.EsInfo.Httpport - index := config.EsInfo.EsIndex.Dbtablepersons.IndexName + var dbpersons []protomsg.Dbperson if len(personIds) >0 { - dbpersons, _ = esApi.Dbpersoninfosbyid(personIds, index, esServerIp, esServerPort) + var dbpApi dbapi.DbPersonApi + dbpersons, _ = dbpApi.Dbpersoninfosbyid(personIds) } - logger.Debug("comp dbpersons.len:", len(dbpersons)) - if dbpersons !=nil { + if len(dbpersons) >0 { + var dtApi dbapi.DbTableApi for _,p :=range dbpersons { var dbP = DbPersonVo { PersonId: p.Id, @@ -239,15 +236,15 @@ TableId: p.TableId, Enable: p.Enable, } - dbTableInfos, _ := esApi.Dbtablefosbyid([]string{p.TableId}, config.EsInfo.EsIndex.DbTables.IndexName, esServerIp, esServerPort) + dbTableInfos, _ := dtApi.DbtablesById([]string{ p.TableId }) if dbTableInfos !=nil{ dbP.BwType = dbTableInfos[0].BwType dbP.TableName = dbTableInfos[0].TableName } - var cr = CompareResult{ + + resultList[dbPersonM[p.Id].Index] = CompareResult{ BaseInfo:[]DbPersonVo{ dbP }, } - resultList = append(resultList,cr) } } if len(captureIds) >0 { @@ -289,10 +286,9 @@ BaseInfo: bi, SdkName: "浜鸿劯", } - resultList = append(resultList,vpE) + resultList[captureM[vp.Id].Index] = vpE } } - sort.Sort(resultList) return resultList } @@ -321,41 +317,38 @@ func (controller FileController) SearchByPhoto(c *gin.Context) { var searchBody models.EsSearch err := c.BindJSON(&searchBody) - if err !=nil || searchBody.PicUrl == "" || len(searchBody.DataBases) == 0 { + if err !=nil{ util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") return } var faceB []byte - if searchBody.CaptureId != "" {//鍋氭煡鎵炬浜� - searchPeople, err := esApi.Dbpersoninfosbyid([]string{searchBody.CaptureId}, config.EsInfo.EsIndex.VideoPersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) + if searchBody.CaptureId != "" {//鍋氭煡鎵炬浜�,鎼滄墍鏈夋姄鎷嶅拰搴曞簱 + searchBase64Fea, err := esApi.GetVideoPersonFaceFeatureById(searchBody.CaptureId, config.EsInfo.EsIndex.VideoPersons.IndexName, config.EsInfo.Masterip, config.EsInfo.Httpport) if err !=nil { util.ResponseFormat(c, code.ComError, "鎶撴媿鏁版嵁涓嶅瓨鍦紝璇锋鏌�") return } - if searchPeople !=nil && len(searchPeople) == 1{ - decodeF, err := base64.StdEncoding.DecodeString(searchPeople[0].FaceFeature) + if searchBase64Fea !=""{ + decodeF, err := base64.StdEncoding.DecodeString(searchBase64Fea) if err !=nil { util.ResponseFormat(c, code.ComError, "鏈潯鎶撴�曠壒寰佷笉鏄痓ase64锛岃妫�鏌�") return } faceB = decodeF } + } else {//鍋氫互鍥炬悳鍥� + if searchBody.PicUrl == "" || len(searchBody.DataBases) == 0 { + util.ResponseFormat(c, code.RequestParamError, "鍙傛暟鏈夎") + return + } + if face,ok := faceExtractedMap[searchBody.PicUrl];!ok{ + util.ResponseFormat(c, code.RequestParamError, "璇烽噸鏂颁笂浼犲浘鐗�") + return + } else { + faceB = face.FaceBytes + } } - //if searchBody.CompareNum !="" { - // //浜屾鎼滅储锛屼笉闇�瑕佸啀姣斿浜� - // co := service.GetCompResultByNum(searchBody.CompareNum) - // if co != nil { - // //浜屾鎼滅储鍜屾帓搴� - // twiceM := GetCompareDataTwice(co,&searchBody) - // util.ResponseFormat(c,code.Success,twiceM) - // } else { - // m :=make(map[string]interface{},0) - // m["compareNum"] = searchBody.CompareNum - // m["total"] = 0 - // m["totalList"] = []CompareResult{} - // util.ResponseFormat(c,code.CompareResultGone,m) - // } - //} + var sysSetApi dbapi.SysSetApi analyServerId := "" flag, sysconf := sysSetApi.GetServerInfo() @@ -365,14 +358,7 @@ util.ResponseFormat(c, code.ComError, "analyServerId涓虹┖锛岄厤缃湁璇�") return } - if searchBody.CaptureId == ""{ - if face,ok := faceExtractedMap[searchBody.PicUrl];!ok{ - util.ResponseFormat(c, code.RequestParamError, "璇烽噸鏂颁笂浼犲浘鐗�") - return - } else { - faceB = face.FaceBytes - } - } + if faceB == nil { util.ResponseFormat(c, code.RequestParamError, "璇烽噸鏂颁笂浼犲浘鐗�") return @@ -382,15 +368,18 @@ CompareThreshold: searchBody.Threshold, } + var hasCompEsPerson = false if searchBody.DataBases !=nil { for idx,tableId :=range searchBody.DataBases { if tableId == "esData" { searchBody.DataBases = append(searchBody.DataBases[:idx], searchBody.DataBases[idx+1:]...) - searchBody.DataBases = append(searchBody.DataBases,service.CaptureTable) + hasCompEsPerson = true break } } arg.TableIds = searchBody.DataBases + } else { + arg.TableIds = []string{} } arg.Source = true // 鏍囪瘑鏉ユ簮鏄痺eb arg.AlarmLevel = searchBody.AlarmLevel @@ -407,33 +396,38 @@ timeStart := time.Now() compareService := service.NewFaceCompareService(arg) - compareOnce := compareService.Compare() - totalData := compareOnce.CompareData + var totalData service.CompareList + if len(arg.TableIds) >0 {//鏈夋瘮瀵瑰簳搴� + dbPersonTargets := compareService.CompareDbPersons() + if dbPersonTargets !=nil { + totalData = append(totalData,*dbPersonTargets...) + } + } + if hasCompEsPerson {//鏈夋瘮瀵笶s鎶撴媿 + esPersons := compareService.CompareVideoPersons() + if esPersons !=nil { + totalData = append(totalData, *esPersons...) + } + } logger.Debug("comp 姣斿缁撴潫锛岀敤鏃讹細",time.Since(timeStart)) + service.SetCompResultByNum(&service.CompareOnce{ + CompareNum: compareService.CompareNum, + CompareData: &totalData, + }) + m := make(map[string]interface{},3) if totalData != nil && totalData.Len() > 0{ - //鎸夊垎鍊兼帓搴� - var scorePre []float32 - for _,f1 :=range *totalData { - scorePre = append(scorePre, f1.CompareScore) - } - //logger.Debug("comp 鎺掑簭鍓嶅垎鍊兼暟缁勶細",scorePre) sort.Sort(totalData) - var scoreAf []float32 - for _,f2 :=range *totalData { - scoreAf = append(scoreAf, f2.CompareScore) - } - //logger.Debug("comp 鎺掑簭鍚庡垎鍊兼暟缁勶細",scoreAf) total := totalData.Len() - m["compareNum"] = compareOnce.CompareNum + m["compareNum"] = compareService.CompareNum m["total"] = total var sCompResult protomsg.SdkCompareResult if total <= searchBody.Size { - sCompResult.CompareResult = *totalData + sCompResult.CompareResult = totalData } else { - sCompResult.CompareResult = (*totalData)[0:searchBody.Size] + sCompResult.CompareResult = totalData[0:searchBody.Size] } resultList := FillDataToCompareResult(&sCompResult) m["totalList"] = resultList @@ -441,7 +435,7 @@ } else { m["total"] = 0 - m["compareNum"] = searchBody.CompareNum + m["compareNum"] = compareService.CompareNum m["totalList"] = []CompareResult{} } util.ResponseFormat(c,code.Success,m) @@ -529,8 +523,6 @@ } -// @Description 浜哄憳鐓х墖涓婁紶骞惰幏鍙栫壒寰佸�� -// @Router /data/api-v/dbperson/fileUploadTest [POST] func (controller FileController) UploadPersonTest(c *gin.Context) { file, _, err := c.Request.FormFile("file") //image杩欎釜鏄痷plaodify鍙傛暟瀹氫箟涓殑 'fileObjName':'image' if err != nil { @@ -571,7 +563,6 @@ func uploadFileReturnAddr(file multipart.File, filename string, tableId string) (string, map[string]interface{}, error) { defer file.Close() - field := "" // weedfs 涓婁紶 fileBytes, err := ioutil.ReadAll(file) if err !=nil { @@ -603,29 +594,22 @@ 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() - fileInfo, e := esutil.PostFormData(weedfsUri, filename, "file", cutFaceImgData) + weedFilePath, e := WeedFSClient.UploadFile(weedfsUri, filename, cutFaceImgData) logger.Debug("涓婁紶鍒皐eedfs鐢ㄦ椂:", time.Since(t1)) t1 = time.Now() if e != nil { fmt.Println(e.Error()) return "", nil, e - } else { - field = fileInfo[picUrlField].(string) // 鏂囦欢璺緞 } - if strings.Contains(field,"/"){ - idx := strings.Index(field, "/") - field = field[idx+1:] - } + ext := path.Ext(filename) fileNameOnly := strings.TrimSuffix(filename, ext) dbperson := new(models.Dbtablepersons) - dbperson.PersonPicUrl = field // 鍥剧墖璺粡 + dbperson.PersonPicUrl = weedFilePath // 鍥剧墖璺粡 dbperson.TableId = tableId // dbperson.PersonName = fileNameOnly // 鍥剧墖鍚� dbperson.Enable = 1 //榛樿鏈夋晥 - // 婕旂ずbase64缂栫爜 - dbperson.FaceFeature = faceBase64 // 鐗瑰緛鍊糱ase64 鐮� result := addDbPerson(dbperson) @@ -643,8 +627,8 @@ // @Tags dbperson 搴曞簱浜哄憳 // @Param files formData file[] true "澶氫釜搴曞簱浜哄憳鍥剧墖" // @Param tableId formData string false "搴曞簱id,鏈塱d 鍒欏姞鍏ュ簳搴擄紝鏃犲垯鍙笂浼犲浘鐗�" -// @Success 200 {string} json "{"code":200, msg:"鐩綍缁撴瀯鏁版嵁", success:true,data:{}}" -// @Failure 500 {string} json "{"code":500, msg:"杩斿洖閿欒淇℃伅", success:false,data:null}" +// @Success 200 {string} json "{"code":200, msg:"", success:true,data:{}}" +// @Failure 500 {string} json "{"code":500, msg:"", success:false,data:null}" // @Router /data/api-v/dbperson/moreFileUpload [POST] func (fc FileController) MoreFileUpload(c *gin.Context) { //寰楀埌涓婁紶鐨勬枃浠� @@ -783,10 +767,4 @@ //} // linux result["smImage"] = smUrl util.ResponseFormat(c, code.Success, result) -} - -/**涓嬭浇鏂规硶**/ -func Filedown(c *gin.Context) { - //鏆傛椂娌℃湁鎻愪緵鏂规硶 - } -- Gitblit v1.8.0