| | |
| | | filename := header.Filename |
| | | var result = make(map[string]string) |
| | | if picType == "1" { |
| | | fileNameOnly, _, err, faceFeature := uploadFileReturnAddr(file, filename, "", false) |
| | | _, _, err, faceFeature, faceUrlPath := uploadFileReturnAddr(file, filename, "", false) |
| | | if err != nil { |
| | | if err.Error() == "NotFeatureFindError" { |
| | | util.ResponseFormat(c, code.NotFeatureFindError, filename) |
| | |
| | | } |
| | | return |
| | | } |
| | | result["picUrl"] = fileNameOnly |
| | | result["picUrl"] = faceUrlPath |
| | | result["faceFeature"] = faceFeature |
| | | } else { |
| | | localConf, err2 := cache.GetServerInfo() |
| | |
| | | log.Fatalln(err) |
| | | }*/ |
| | | |
| | | func uploadFileReturnAddr(file multipart.File, filename string, tableId string, add2Db bool) (string, map[string]interface{}, error, string) { |
| | | func uploadFileReturnAddr(file multipart.File, filename string, tableId string, add2Db bool) (string, map[string]interface{}, error, string, string) { |
| | | defer file.Close() |
| | | // weedfs 上传 |
| | | fileBytes, err := ioutil.ReadAll(file) |
| | | if err !=nil { |
| | | return "",nil,err,"" |
| | | return "",nil,err,"","" |
| | | } |
| | | |
| | | //将上传的图片交人脸检测和人脸提取,获得特征 |
| | | var faceBase64="" |
| | | faceArr, err, pI := service.GetFaceFeaFromSdk(fileBytes, time.Second*5) |
| | | if faceArr ==nil { |
| | | return "",nil,errors.New("NotFeatureFindError"),"" |
| | | return "",nil,errors.New("NotFeatureFindError"),"","" |
| | | } |
| | | var rcFace *protomsg.Rect |
| | | if err ==nil && len(faceArr) >0 { |
| | | if len(faceArr) >1 { |
| | | return "",nil, errors.New("TooManyFaces"),"" |
| | | return "",nil, errors.New("TooManyFaces"),"","" |
| | | } |
| | | for _,r := range faceArr { |
| | | //拿到人脸的坐标 |
| | |
| | | localConf, err2 := cache.GetServerInfo() |
| | | if err2 !=nil || localConf.WebPicIp == "" { |
| | | logger.Debug("localConfig is wrong!!!") |
| | | return "",nil,err2,"" |
| | | return "",nil,err2,"","" |
| | | } |
| | | var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit?collection=persistent" |
| | | //根据人脸坐标扣出人脸小图 |
| | |
| | | t1 = time.Now() |
| | | if e != nil { |
| | | logger.Debug("WeedFSClient.UploadFile err:", e) |
| | | return "", nil, e,"" |
| | | return "", nil, e,"","" |
| | | } |
| | | |
| | | ext := path.Ext(filename) |
| | |
| | | } |
| | | |
| | | logger.Debug("addDbPerson用时:", time.Since(t1)) |
| | | return fileNameOnly, result, nil,faceBase64 |
| | | return fileNameOnly, result, nil,faceBase64, weedFilePath |
| | | |
| | | } |
| | | |
| | |
| | | lock.Unlock() |
| | | return |
| | | } |
| | | field, _, err1,_ := uploadFileReturnAddr(file, filename, tableId, true) |
| | | field, _, err1,_,_ := uploadFileReturnAddr(file, filename, tableId, true) |
| | | lock.Lock() |
| | | if err1 != nil || field == "" { |
| | | if err1 !=nil && err1.Error() == "NotFeatureFindError" { |