| | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | "basic.com/valib/deliver.git" |
| | | "encoding/base64" |
| | | "fmt" |
| | | "github.com/gogo/protobuf/proto" |
| | | "github.com/pierrec/lz4" |
| | | "github.com/satori/go.uuid" |
| | | "image" |
| | | "io/ioutil" |
| | | "os" |
| | | "gocv.io/x/gocv" |
| | | "time" |
| | | ) |
| | | |
| | | const ( |
| | | Url_Service_PUSH = "ipc:///tmp///virtual-faceextract-sdk-pull_2.ipc" |
| | | Url_Service_PULL = "ipc:///tmp///virtual-faceextract-sdk-pull_1.ipc" |
| | | Ipc_Push_Ext = "_2.ipc" |
| | | Ipc_Pull_Ext = "_1.ipc" |
| | | Ipc_Url_Pre = "ipc:///tmp///" |
| | | Virtual_FaceTaskId = "92496BDF-2BFA-98F2-62E8-96DD9866ABD2" |
| | | Virtual_FaceSdkId = "virtual-faceextract-sdk-pull" |
| | | 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 client_push deliver.Deliver |
| | |
| | | Picdata:bc, |
| | | }) |
| | | fmt.Println("pushed img") |
| | | time.Sleep(10*time.Second) |
| | | 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 |
| | | } |
| | | i = protomsg.Image{ |
| | | Width:int32(picMat.Rows()), |
| | | Height:int32(picMat.Cols()), |
| | | Timestamp:formatTimeStr, |
| | | Data:[]byte(picMat.DataPtrUint8()), |
| | | } |
| | | return i |
| | | } |
| | | |
| | | func PushImgMsg(is protomsg.Recvmsg){ |
| | |
| | | func InitService(){ |
| | | fmt.Println("service init!") |
| | | imgPushChan = make(chan protomsg.Recvmsg) |
| | | 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) |
| | | defer func() { |
| | |
| | | continue |
| | | } |
| | | rMsg := protomsg.SdkMessage{} |
| | | if err := proto.Unmarshal(resultBytes, &rMsg);err !=nil{ |
| | | fmt.Println("recv MSG:",rMsg) |
| | | resultMap[rMsg.Cid] = rMsg |
| | | if err := proto.Unmarshal(resultBytes, &rMsg);err ==nil{ |
| | | fmt.Println("received MSG:",rMsg.Cid) |
| | | perId := rMsg.Cid //数据id |
| | | if rMsg.Tasklab !=nil && rMsg.Tasklab.Taskid == Virtual_FaceTaskId { |
| | | sdkInfos := rMsg.Tasklab.Sdkinfos |
| | | fmt.Println("Len(sdkInfos)=",len(sdkInfos)) |
| | | for _,swt :=range sdkInfos{ |
| | | 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) |
| | | } else { |
| | | fmt.Println("目标数:",len(pff.ExtComp)) |
| | | for _,fea :=range pff.ExtComp{ |
| | | base64Fea := base64.StdEncoding.EncodeToString(fea.Feats) |
| | | fmt.Println("perId:",perId) |
| | | fmt.Println("faceFeature:",base64Fea) |
| | | } |
| | | } |
| | | break |
| | | } |
| | | } |
| | | |
| | | } |
| | | //resultMap[rMsg.Cid] = rMsg |
| | | } else { |
| | | fmt.Println("recv msg Err:",err) |
| | | } |
| | | |
| | | } |