From 2a447c237b95f5fb45cb5d74fe3ca71de06ba1b5 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 28 六月 2019 20:58:06 +0800
Subject: [PATCH] test

---
 service/FaceSdkService.go |   44 ++++++++++++++++++++++++--------------------
 1 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go
index 58b5cf2..4749496 100644
--- a/service/FaceSdkService.go
+++ b/service/FaceSdkService.go
@@ -10,14 +10,16 @@
 	"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
+	Result []*protomsg.ResultFaceExtCom
 }
 
 const (
@@ -32,7 +34,7 @@
 
 func NewFaceSdkService(file multipart.File) FaceSdkService{
 	return FaceSdkService{
-		File:file,
+		File:&file,
 		Id:uuid.NewV4().String(),
 	}
 }
@@ -58,12 +60,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 +81,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 +89,7 @@
 		Width: width,
 		Height: height,
 		Timestamp: formatTimeStr,
-		Data: data,
+		Data: imgB,
 		Id: timeUnix,
 		Cid:s.Id,
 	},nil
@@ -111,33 +116,32 @@
 	}
 }
 
-func (s *FaceSdkService) GetFaceFea() (feas []*protomsg.ResultFaceExtCom,err error){
+func (s *FaceSdkService) GetFaceFea(){
 	var wg sync.WaitGroup
 	wg.Add(1)
-	ch := make(chan []*protomsg.ResultFaceExtCom,0)
+
 	go func() {
+		Exit:
 		for {
 			select {
-			case <-time.Tick(time.Second*10):
-				ch <- nil
+			case <-time.Tick(time.Second*2):
+				fmt.Println("鍊掕鏃剁粨鏉�")
 				wg.Done()
-				return
+				break Exit
 			default:
 				if feas,ok := resultMap[s.Id];ok {
 					fmt.Println("faceFea got!!!")
-					ch <- feas
-					return
+					s.Result = feas
+					break Exit
+				} else {
+					fmt.Println("灏氭湭鎷垮埌fea")
 				}
 			}
 		}
 	}()
+	fmt.Println("wa.Wait")
 	wg.Wait()
-	msg := <- ch
-	if msg != nil {
-		return msg,nil
-	} else {
-		return msg,errors.New("no fea")
-	}
+	fmt.Println("<-ch")
 }
 
 func readTestImgFile() protomsg.Image{

--
Gitblit v1.8.0