From 3e3b79a7a35f8aa796fe05ce1af74547cd06e9c2 Mon Sep 17 00:00:00 2001
From: liuxiaolong <736321739@qq.com>
Date: 星期四, 27 六月 2019 16:23:40 +0800
Subject: [PATCH] get img Width height and Data from gocv

---
 service/FaceSdkService.go |   37 ++++++++++++++-----------------------
 1 files changed, 14 insertions(+), 23 deletions(-)

diff --git a/service/FaceSdkService.go b/service/FaceSdkService.go
index a58a804..93935d1 100644
--- a/service/FaceSdkService.go
+++ b/service/FaceSdkService.go
@@ -8,9 +8,7 @@
 	"github.com/gogo/protobuf/proto"
 	"github.com/pierrec/lz4"
 	"github.com/satori/go.uuid"
-	"image"
-	"io/ioutil"
-	"os"
+	"gocv.io/x/gocv"
 	"time"
 )
 
@@ -64,28 +62,21 @@
 	formatTimeStr := time.Unix(timeUnix, 0).Format("2006-01-02 15:04:05")
 	filePath := "/home/user/workspace/timg.jpg"
 
-	file, err := os.Open(filePath)
-	defer file.Close()
-	if err !=nil{
-		fmt.Println("image not exist")
-		return i
-	} else {
-		img, _, err := image.Decode(file)
-		bytes, err := ioutil.ReadFile(filePath)
-		if err !=nil {
-			return i
-		}
-		b := img.Bounds()
-		width := b.Max.X
-		height := b.Max.Y
-		i = protomsg.Image{
-			Width:int32(width),
-			Height:int32(height),
-			Timestamp:formatTimeStr,
-			Data:bytes,
-		}
+	picMat := gocv.IMRead(filePath, gocv.IMReadColor)
+
+	defer picMat.Close()
+
+	if picMat.Empty() {
+		fmt.Println("file not exist")
 		return i
 	}
+	i = protomsg.Image{
+		Width:int32(picMat.Rows()),
+		Height:int32(picMat.Cols()),
+		Timestamp:formatTimeStr,
+		Data:[]byte(picMat.DataPtrUint8()),
+	}
+	return i
 }
 
 func PushImgMsg(is protomsg.Recvmsg){

--
Gitblit v1.8.0