From 9d88c7c467f8d93af4aab9ba0b6d6c01c2ffc546 Mon Sep 17 00:00:00 2001 From: sunty <1172534965@qq.com> Date: 星期四, 20 八月 2020 20:35:30 +0800 Subject: [PATCH] add get buckets contrl --- controllers/fileController.go | 42 ++++++++++++++++++++++++++---------------- 1 files changed, 26 insertions(+), 16 deletions(-) diff --git a/controllers/fileController.go b/controllers/fileController.go index d6370fa..1ef8a2f 100644 --- a/controllers/fileController.go +++ b/controllers/fileController.go @@ -5,6 +5,7 @@ "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" @@ -12,7 +13,6 @@ "errors" "fmt" "github.com/gin-gonic/gin" - "gocv.io/x/gocv" "image" "image/color" "image/jpeg" @@ -148,7 +148,11 @@ 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{ @@ -171,19 +175,19 @@ } 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 { @@ -413,7 +417,7 @@ 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{ @@ -631,8 +635,10 @@ arg.Collection = searchBody.Collection arg.AnalyServerId = localConf.ServerId + ct := time.Now() captureIds := esApi.GetAllLocalVideopersonsId(arg, config.EsInfo.EsIndex.AiOcean.IndexName, localConf.AlarmIp, strconv.Itoa(int(localConf.AlarmPort)), alarmLevelTypes) - logger.Debug("searchPhoto first Result.len:",len(*co.CompareData),"twice len(captureIds):",len(captureIds)) + ut := time.Since(ct) + logger.Debug("searchPhoto first Result.len:",len(*co.CompareData),"twice len(captureIds):",len(captureIds), "useTime:", ut) if captureIds !=nil { var aResult protomsg.SdkCompareResult aList := getTwiceSearchResult(co, &captureIds, searchBody) @@ -764,7 +770,7 @@ break } //鏍规嵁浜鸿劯鍧愭爣鎵e嚭浜鸿劯灏忓浘 - 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,"鏂囦欢涓婁紶澶辫触") @@ -817,7 +823,11 @@ var weedfsUri = "http://"+localConf.WebPicIp+":"+strconv.Itoa(int(localConf.WebPicPort))+"/submit?collection=persistent" //鏍规嵁浜鸿劯鍧愭爣鎵e嚭浜鸿劯灏忓浘 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) -- Gitblit v1.8.0