From cefb30a1e8737b52e46da86f2decafb7d7e150f0 Mon Sep 17 00:00:00 2001 From: liuxiaolong <736321739@qq.com> Date: 星期五, 28 六月 2019 20:33:21 +0800 Subject: [PATCH] test --- service/FaceSdkService.go | 25 +++++++++++++++++-------- 1 files changed, 17 insertions(+), 8 deletions(-) diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go index 58b5cf2..64e5f6c 100644 --- a/service/FaceSdkService.go +++ b/service/FaceSdkService.go @@ -10,13 +10,14 @@ "github.com/pkg/errors" "github.com/satori/go.uuid" "gocv.io/x/gocv" + "io/ioutil" "mime/multipart" "sync" "time" ) type FaceSdkService struct { - File multipart.File + File *multipart.File Id string } @@ -32,7 +33,7 @@ func NewFaceSdkService(file multipart.File) FaceSdkService{ return FaceSdkService{ - File:file, + File:&file, Id:uuid.NewV4().String(), } } @@ -58,12 +59,15 @@ } func (s *FaceSdkService) ReadFromUploadImg() (*protomsg.Image,error){ - defer s.File.Close() - imgB := make([]byte,0) - if _, err := s.File.Read(imgB);err !=nil{ + defer (*(s.File)).Close() + imgB, err := ioutil.ReadAll(*(s.File)) + if err !=nil{ fmt.Println("File.Read err:",err) return nil,err } + + fmt.Println("imgB.len:",len(imgB)) + picMat, err := gocv.IMDecode(imgB, gocv.IMReadColor) if err !=nil { fmt.Println("gocv.IMDecode err:",err) @@ -76,7 +80,7 @@ } height := int32(picMat.Rows()) width := int32(picMat.Cols()) - data := picMat.ToBytes() + //data := picMat.ToBytes() timeUnix := time.Now().Unix() formatTimeStr := time.Unix(timeUnix, 0).Format("2006-01-02 15:04:05") @@ -84,7 +88,7 @@ Width: width, Height: height, Timestamp: formatTimeStr, - Data: data, + Data: imgB, Id: timeUnix, Cid:s.Id, },nil @@ -118,7 +122,8 @@ go func() { for { select { - case <-time.Tick(time.Second*10): + case <-time.Tick(time.Second*5): + fmt.Println("鍊掕鏃剁粨鏉�") ch <- nil wg.Done() return @@ -127,11 +132,15 @@ fmt.Println("faceFea got!!!") ch <- feas return + } else { + fmt.Println("灏氭湭鎷垮埌fea") } } } }() + fmt.Println("wa.Wait") wg.Wait() + fmt.Println("<-ch") msg := <- ch if msg != nil { return msg,nil -- Gitblit v1.8.0