From 725d54ef5f16ede9c39cb003ed9d474edf02c0e5 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期五, 30 八月 2019 13:58:25 +0800
Subject: [PATCH] add facedetect grpc

---
 service/FaceSdkService.go |   49 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go
index 148375f..9547060 100644
--- a/service/FaceSdkService.go
+++ b/service/FaceSdkService.go
@@ -34,24 +34,45 @@
 )
 
 func GetFaceFeaFromSdk(fileBytes []byte,deadTime time.Duration) ([]*protomsg.ResultFaceDetect,error,*protomsg.Image){
+	t1 := time.Now()
 	s := NewFaceSdkService(fileBytes, deadTime)
 	i, err := s.ReadFromUploadImg()
+	logger.Debug("ReadFromUploadImg鐢ㄦ椂:", time.Since(t1))
+	t1 = time.Now()
 	if err !=nil{
 		logger.Debug("readFromUploadImg err:",err)
 		return nil,err,i
 	}
-	bc, err := ImgCompress(i)
+	imgBytes, err := proto.Marshal(i)
 	if err !=nil {
-		logger.Debug("ImgCompress err:",err)
+		logger.Debug("i marshal err:",err)
 		return nil,err,i
 	}
-	s.PushImgMsg(bc)
-	s.GetFaceFea()
-	if s.Result == nil{
-		return nil,errors.New("no fea"),i
+	detectResults, err := DoFDetectWithRpc(&protomsg.FaceDetectRequest{ReqParam: imgBytes}, deadTime)
+	if err !=nil {
+		logger.Debug("DoFDetectWithRpc err:",err)
+		return nil,err,i
 	} else {
-		return s.Result,nil,i
+		return detectResults,nil,i
 	}
+
+	//bc, err := ImgCompress(i)
+	//logger.Debug("ImgCompress鐢ㄦ椂:", time.Since(t1))
+	//t1 = time.Now()
+	//if err !=nil {
+	//	logger.Debug("ImgCompress err:",err)
+	//	return nil,err,i
+	//}
+	//s.PushImgMsg(bc)
+	//logger.Debug("PushImgMsg鐢ㄦ椂:", time.Since(t1))
+	//t1 = time.Now()
+	//s.GetFaceFea()
+	//logger.Debug("GetFaceFea鐢ㄦ椂:", time.Since(t1))
+	//if s.Result == nil{
+	//	return nil,errors.New("no fea"),i
+	//} else {
+	//	return s.Result,nil,i
+	//}
 }
 
 func NewFaceSdkService(fileBytes []byte, deadTime time.Duration) FaceSdkService{
@@ -88,14 +109,21 @@
 		logger.Debug("gocv.IMDecode err:",err)
 		return nil,err
 	}
+	logger.Debug("picMat.Data.len:", len(picMat.ToBytes()))
 	newMat := gocv.NewMat()
-	if picMat.Rows() > 1000 || picMat.Cols() > 1000 {
-		gocv.Resize(picMat,&newMat, image.Pt(0,0), 0.5,  0.5, gocv.InterpolationDefault)
+	size := 1024
+	if picMat.Rows() > size || picMat.Cols() > size {
+		fx := float64(size)/float64(picMat.Rows())
+		fy := float64(size)/float64(picMat.Cols())
+		ff := fx
+		if fx > fy{
+			ff = fy
+		}
+		gocv.Resize(picMat,&newMat, image.Pt(0,0), ff, ff, gocv.InterpolationDefault)
 		picMat = newMat
 	}
 
 	defer picMat.Close()
-	defer newMat.Close()
 
 	if picMat.Empty() {
 		logger.Debug("file not exist")
@@ -263,7 +291,6 @@
 		}
 		rMsg := protomsg.SdkMessage{}
 		if err := proto.Unmarshal(resultBytes, &rMsg); err == nil {
-			logger.Debug("received MSG:", rMsg.Cid)
 			i := protomsg.Image{}
 			bdata, err := util.UnCompress(rMsg.Data)
 			if err !=nil {

--
Gitblit v1.8.0