| | |
| | | "github.com/gogo/protobuf/proto" |
| | | "github.com/pierrec/lz4" |
| | | "github.com/satori/go.uuid" |
| | | "image" |
| | | "io/ioutil" |
| | | "os" |
| | | "gocv.io/x/gocv" |
| | | "time" |
| | | ) |
| | | |
| | |
| | | Url_Service_PUSH = Ipc_Url_Pre + Virtual_FaceSdkId + Ipc_Push_Ext |
| | | Url_Service_PULL = Ipc_Url_Pre + Virtual_FaceSdkId + Ipc_Pull_Ext |
| | | ) |
| | | var imgPushChan chan protomsg.Recvmsg |
| | | var imgPushChan chan []byte |
| | | var client_push deliver.Deliver |
| | | var client_pull deliver.Deliver |
| | | |
| | | func TestPushImgMsg() { |
| | | InitService() |
| | | proImg := readImgFile() |
| | | |
| | | if b, err := proto.Marshal(&proImg);err !=nil{ |
| | | i := readImgFile() |
| | | |
| | | fmt.Printf("width:%d,height:%d,data.length:%d,timestamp:%s,id:%d\n",i.Width,i.Height,len(i.Data),i.Timestamp,i.Id) |
| | | if b, err := proto.Marshal(&i);err !=nil{ |
| | | fmt.Println("protoImage marshal err") |
| | | return |
| | | } else { |
| | | bc := make([]byte,len(b)) |
| | | ht := make([]int, 64<<10) |
| | | n,err := lz4.CompressBlock(b,bc,ht) |
| | | n,err := lz4.CompressBlock(b, bc, ht) |
| | | if err !=nil { |
| | | fmt.Println(err) |
| | | } |
| | |
| | | } |
| | | bc = bc[:n] |
| | | for { |
| | | PushImgMsg(protomsg.Recvmsg{ |
| | | Id:uuid.NewV4().String(), |
| | | Addr:"", |
| | | Picdata:bc, |
| | | }) |
| | | PushImgMsg(bc) |
| | | fmt.Println("pushed img") |
| | | time.Sleep(5*time.Second) |
| | | } |
| | |
| | | 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 |
| | | } |
| | | height := int32(picMat.Rows()) |
| | | width := int32(picMat.Cols()) |
| | | data := picMat.ToBytes() |
| | | //wrMat,_ := gocv.NewMatFromBytes(picMat.Rows(),picMat.Cols(),gocv.MatTypeCV8UC3,data) |
| | | // |
| | | //gocv.IMWrite("xxx.jpg", wrMat) |
| | | |
| | | i = protomsg.Image{ |
| | | Width: width, |
| | | Height: height, |
| | | Timestamp: formatTimeStr, |
| | | Data: data, |
| | | Id: timeUnix, |
| | | } |
| | | i.Cid = uuid.NewV4().String()//数据唯一id |
| | | fmt.Println("gocv read img completed") |
| | | return i |
| | | } |
| | | |
| | | func PushImgMsg(is protomsg.Recvmsg){ |
| | | func PushImgMsg(is []byte){ |
| | | imgPushChan <- is |
| | | } |
| | | |
| | |
| | | |
| | | func InitService(){ |
| | | fmt.Println("service init!") |
| | | imgPushChan = make(chan protomsg.Recvmsg) |
| | | imgPushChan = make(chan []byte) |
| | | resultMap = make(map[string]protomsg.SdkMessage,0) |
| | | client_push = deliver.NewClient(deliver.PushPull, Url_Service_PUSH) |
| | | client_pull = deliver.NewClient(deliver.PushPull, Url_Service_PULL) |
| | |
| | | func thSend(){ |
| | | for { |
| | | select { |
| | | case is := <- imgPushChan: |
| | | case d := <- imgPushChan: |
| | | fmt.Println("imgPushChan in") |
| | | b, _ := proto.Marshal(&is) |
| | | err := client_push.Send(b) |
| | | err := client_push.Send(d) |
| | | if err !=nil { |
| | | fmt.Println("img Send err:",err) |
| | | } |
| | |
| | | sdkInfos := rMsg.Tasklab.Sdkinfos |
| | | fmt.Println("Len(sdkInfos)=",len(sdkInfos)) |
| | | for _,swt :=range sdkInfos{ |
| | | fmt.Println("sdkName:",swt.SdkName) |
| | | if swt.Sdktype =="FaceDetect"{ |
| | | fmt.Println("人脸检测结果") |
| | | var pfp protomsg.ParamFacePos |
| | | err := proto.Unmarshal(swt.Sdkdata, &pfp) |
| | | if err !=nil { |
| | | fmt.Println("faceDetect result unmarshal err:",err) |
| | | } else { |
| | | for _,face :=range pfp.Faces{ |
| | | fmt.Println("FacePos:",face.Pos) |
| | | fmt.Println("ThftResult:",face.Result) |
| | | } |
| | | } |
| | | } |
| | | if swt.Sdktype == "FaceExtract"{ |
| | | fmt.Println("sdkName:",swt.SdkName) |
| | | fmt.Println("sdkData.len:",len(swt.Sdkdata)) |
| | | var pff protomsg.ParamFaceFeature |
| | | if err := proto.Unmarshal(swt.Sdkdata, &pff);err !=nil{ |
| | | fmt.Println("ParamFaceFeature unmarshal err:",err) |
| | | //fmt.Println("ParamFaceFeature unmarshal err:",err) |
| | | } else { |
| | | fmt.Println("目标数:",len(pff.ExtComp)) |
| | | for _,fea :=range pff.ExtComp{ |