| | |
| | | "sort" |
| | | "strconv" |
| | | "strings" |
| | | "sync" |
| | | "time" |
| | | "webserver/extend/code" |
| | | "webserver/extend/config" |
| | |
| | | util.ResponseFormat(c, code.RequestParamError, "参数有误") |
| | | return |
| | | } |
| | | 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 faceB []byte |
| | | if searchBody.CaptureId != "" {//做查找此人 |
| | | searchPeople, err := esApi.Dbpersoninfosbyid([]string{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 err !=nil { |
| | | util.ResponseFormat(c, code.ComError, "本条抓怕特征不是base64,请检查") |
| | | return |
| | | } |
| | | faceB = decodeF |
| | | } |
| | | } |
| | | //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() |
| | |
| | | util.ResponseFormat(c, code.ComError, "analyServerId为空,配置有误") |
| | | return |
| | | } |
| | | if face,ok := faceExtractedMap[searchBody.PicUrl];!ok{ |
| | | 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 |
| | | } else { |
| | | arg := protomsg.CompareArgs{ |
| | | FaceFeature: face.FaceBytes, |
| | | CompareThreshold: searchBody.Threshold, |
| | | } |
| | | |
| | | 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) |
| | | break |
| | | } |
| | | } |
| | | arg.TableIds = searchBody.DataBases |
| | | } |
| | | arg.Source = true // 标识来源是web |
| | | arg.AlarmLevel = searchBody.AlarmLevel |
| | | arg.Tasks = searchBody.Tasks |
| | | arg.TreeNodes = searchBody.TreeNodes |
| | | arg.Tabs = searchBody.Tabs |
| | | arg.SearchTime = searchBody.SearchTime |
| | | arg.InputValue = searchBody.InputValue |
| | | arg.Collection = searchBody.Collection |
| | | arg.AnalyServerId = analyServerId |
| | | |
| | | logger.Debug("arg.TableIds:", arg.TableIds, ",alarmLevel:",arg.AlarmLevel,",treeNodes:",arg.TreeNodes,",searchTime:",arg.SearchTime, |
| | | ",inputValue:",arg.InputValue,",tasks:",arg.Tasks,",compThreshold:",arg.CompareThreshold) |
| | | timeStart := time.Now() |
| | | |
| | | compareService := service.NewFaceCompareService(arg) |
| | | compareOnce := compareService.Compare() |
| | | totalData := compareOnce.CompareData |
| | | |
| | | logger.Debug("comp 比对结束,用时:",time.Since(timeStart)) |
| | | 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["total"] = total |
| | | var sCompResult protomsg.SdkCompareResult |
| | | if total <= searchBody.Size { |
| | | sCompResult.CompareResult = *totalData |
| | | } else { |
| | | sCompResult.CompareResult = (*totalData)[0:searchBody.Size] |
| | | } |
| | | resultList := FillDataToCompareResult(&sCompResult) |
| | | m["totalList"] = resultList |
| | | logger.Debug("comp 比对加排序返回用时:", time.Since(timeStart)) |
| | | |
| | | } else { |
| | | m["total"] = 0 |
| | | m["compareNum"] = searchBody.CompareNum |
| | | m["totalList"] = []CompareResult{} |
| | | } |
| | | util.ResponseFormat(c,code.Success,m) |
| | | } |
| | | arg := protomsg.CompareArgs{ |
| | | FaceFeature: faceB, |
| | | CompareThreshold: searchBody.Threshold, |
| | | } |
| | | |
| | | 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) |
| | | break |
| | | } |
| | | } |
| | | arg.TableIds = searchBody.DataBases |
| | | } |
| | | arg.Source = true // 标识来源是web |
| | | arg.AlarmLevel = searchBody.AlarmLevel |
| | | arg.Tasks = searchBody.Tasks |
| | | arg.TreeNodes = searchBody.TreeNodes |
| | | arg.Tabs = searchBody.Tabs |
| | | arg.SearchTime = searchBody.SearchTime |
| | | arg.InputValue = searchBody.InputValue |
| | | arg.Collection = searchBody.Collection |
| | | arg.AnalyServerId = analyServerId |
| | | |
| | | logger.Debug("arg.TableIds:", arg.TableIds, ",alarmLevel:",arg.AlarmLevel,",treeNodes:",arg.TreeNodes,",searchTime:",arg.SearchTime, |
| | | ",inputValue:",arg.InputValue,",tasks:",arg.Tasks,",compThreshold:",arg.CompareThreshold) |
| | | timeStart := time.Now() |
| | | |
| | | compareService := service.NewFaceCompareService(arg) |
| | | compareOnce := compareService.Compare() |
| | | totalData := compareOnce.CompareData |
| | | |
| | | logger.Debug("comp 比对结束,用时:",time.Since(timeStart)) |
| | | 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["total"] = total |
| | | var sCompResult protomsg.SdkCompareResult |
| | | if total <= searchBody.Size { |
| | | sCompResult.CompareResult = *totalData |
| | | } else { |
| | | sCompResult.CompareResult = (*totalData)[0:searchBody.Size] |
| | | } |
| | | resultList := FillDataToCompareResult(&sCompResult) |
| | | m["totalList"] = resultList |
| | | logger.Debug("comp 比对加排序返回用时:", time.Since(timeStart)) |
| | | |
| | | } else { |
| | | m["total"] = 0 |
| | | m["compareNum"] = searchBody.CompareNum |
| | | m["totalList"] = []CompareResult{} |
| | | } |
| | | util.ResponseFormat(c,code.Success,m) |
| | | } |
| | | |
| | | func GetCompareDataTwice(co *service.CompareOnce,arg *models.EsSearch) map[string]interface{} { |
| | |
| | | } |
| | | 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() |
| | | fileInfo, e := esutil.PostFormData(weedfsUri, filename, "file", cutFaceImgData) |
| | | logger.Debug("上传到weedfs用时:", time.Since(t1)) |
| | | t1 = time.Now() |
| | | if e != nil { |
| | | fmt.Println(e.Error()) |
| | | return "", nil, e |
| | |
| | | dbperson.FaceFeature = faceBase64 // 特征值base64 码 |
| | | |
| | | result := addDbPerson(dbperson) |
| | | logger.Debug("addDbPerson用时:", time.Since(t1)) |
| | | return fileNameOnly, result, nil |
| | | |
| | | } |
| | | |
| | | //func getFaceFeaFromSdk(fileBytes []byte) ([]*protomsg.ResultFaceExtCom,error,*protomsg.Image){ |
| | | // s := service.NewFaceSdkService(fileBytes) |
| | | // i, err := s.ReadFromUploadImg() |
| | | // if err !=nil{ |
| | | // fmt.Println("readFromUploadImg err:",err) |
| | | // return nil,err,i |
| | | // } |
| | | // bc, err := service.ImgCompress(i) |
| | | // if err !=nil { |
| | | // fmt.Println("ImgCompress err:",err) |
| | | // return nil,err,i |
| | | // } |
| | | // s.PushImgMsg(bc) |
| | | // s.GetFaceFea() |
| | | // if s.Result == nil{ |
| | | // return nil,errors.New("no fea"),i |
| | | // } else { |
| | | // return s.Result,nil,i |
| | | // } |
| | | //} |
| | | |
| | | /**上传方法**/ |
| | | |
| | |
| | | addResult := make(map[string]interface{}, 0) |
| | | successList := make([]string, 0) |
| | | failList := make([]string,0) |
| | | tAllStart := time.Now() |
| | | var wg sync.WaitGroup |
| | | var lock sync.Mutex |
| | | for _, head := range fileHeaders { |
| | | //文件的名称 |
| | | filename := head.Filename |
| | | file, err := head.Open() |
| | | fmt.Println(file, err, filename) |
| | | if err != nil { |
| | | log.Fatal(err) |
| | | } |
| | | |
| | | field, _, err1 := uploadFileReturnAddr(file, filename, tableId) |
| | | //extNames = append(extNames, field) |
| | | |
| | | if err1 != nil || field == "" { |
| | | failList = append(failList, filename) |
| | | } else { |
| | | successList = append(successList, filename) |
| | | } |
| | | wg.Add(1) |
| | | go func(head *multipart.FileHeader,tableId string) { |
| | | defer wg.Done() |
| | | tIStart := time.Now() |
| | | filename := head.Filename |
| | | file, err := head.Open() |
| | | fmt.Println(file, err, filename) |
| | | if err != nil { |
| | | lock.Lock() |
| | | failList = append(failList, filename) |
| | | lock.Unlock() |
| | | return |
| | | } |
| | | field, _, err1 := uploadFileReturnAddr(file, filename, tableId) |
| | | lock.Lock() |
| | | if err1 != nil || field == "" { |
| | | failList = append(failList, filename) |
| | | } else { |
| | | successList = append(successList, filename) |
| | | } |
| | | lock.Unlock() |
| | | logger.Debug(filename,"切图用时:",time.Since(tIStart)) |
| | | }(head, tableId) |
| | | wg.Wait() |
| | | } |
| | | logger.Debug("切",len(fileHeaders),"张人脸用时:", time.Since(tAllStart)) |
| | | addResult["successList"] = successList |
| | | addResult["failList"] = failList |
| | | addResult["fields"] = extNames |
| | | //addResult["detail"] = details |
| | | //fields := fdfsclient.UploadFileByBuffer100(bytess, extNames) // fastdfs 上传 |
| | | |
| | | if len(successList)>0 { |
| | | util.ResponseFormat(c, code.DbPersonUploadSuccess, addResult) |
| | | } else { |
| | | util.ResponseFormat(c, code.ServiceInsideError, err.Error()) |
| | | util.ResponseFormat(c, code.DbPersonUploadFail, addResult) |
| | | } |
| | | } |
| | | |