| | |
| | | } |
| | | |
| | | const ( |
| | | Ipc_Push_Ext = "_2.ipc" |
| | | Ipc_Pull_Ext = "_1.ipc" |
| | | Ipc_Url_Pre = "ipc:///tmp///" |
| | | 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 |
| | | 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 |
| | | ) |
| | | |
| | | func NewFaceSdkService(file multipart.File) FaceSdkService{ |
| | |
| | | } |
| | | |
| | | func ImgCompress(i *protomsg.Image) ([]byte,error){ |
| | | if b, err := proto.Marshal(i);err !=nil{ |
| | | if b, err := proto.Marshal(i); err != nil { |
| | | fmt.Println("protoImage marshal err") |
| | | return nil,err |
| | | } else { |
| | | bc := make([]byte,len(b)) |
| | | bc := make([]byte, len(b)) |
| | | ht := make([]int, 64<<10) |
| | | n,err := lz4.CompressBlock(b, bc, ht) |
| | | if err !=nil { |
| | | n, err := lz4.CompressBlock(b, bc, ht) |
| | | if err != nil { |
| | | fmt.Println(err) |
| | | return nil,err |
| | | } |
| | | if n >= len(b){ |
| | | if n >= len(b) { |
| | | fmt.Println("image is not compressible") |
| | | return nil,errors.New("compressed len is 0") |
| | | } |
| | |
| | | //gocv.IMWrite("xxx.jpg", wrMat) |
| | | |
| | | i = protomsg.Image{ |
| | | Width: width, |
| | | Height: height, |
| | | Width: width, |
| | | Height: height, |
| | | Timestamp: formatTimeStr, |
| | | Data: data, |
| | | Id: timeUnix, |
| | | Data: data, |
| | | Id: timeUnix, |
| | | } |
| | | i.Cid = uuid.NewV4().String()//数据唯一id |
| | | i.Cid = uuid.NewV4().String() //数据唯一id |
| | | fmt.Println("gocv read img completed") |
| | | return i |
| | | } |
| | |
| | | |
| | | var resultMap map[string][]*protomsg.ResultFaceExtCom |
| | | |
| | | |
| | | func InitService(){ |
| | | func InitService() { |
| | | fmt.Println("service init!") |
| | | imgPushChan = make(chan []byte) |
| | | |
| | | resultMap = make(map[string][]*protomsg.ResultFaceExtCom,0) |
| | | |
| | | client_push = deliver.NewClient(deliver.PushPull, Url_Service_PUSH) |
| | | client_pull = deliver.NewClient(deliver.PushPull, Url_Service_PULL) |
| | | defer func() { |
| | |
| | | go thRecv() |
| | | } |
| | | |
| | | func thSend(){ |
| | | func thSend() { |
| | | for { |
| | | select { |
| | | case d := <- imgPushChan: |
| | | case d := <-imgPushChan: |
| | | fmt.Println("imgPushChan in") |
| | | err := client_push.Send(d) |
| | | if err !=nil { |
| | | fmt.Println("img Send err:",err) |
| | | if err != nil { |
| | | fmt.Println("img Send err:", err) |
| | | } |
| | | default: |
| | | //fmt.Println("no img in") |
| | |
| | | } |
| | | } |
| | | |
| | | func thRecv(){ |
| | | func thRecv() { |
| | | for { |
| | | resultBytes, err := client_pull.Recv() |
| | | if err !=nil{ |
| | | fmt.Println("pull err:",err) |
| | | if err != nil { |
| | | fmt.Println("pull err:", err) |
| | | continue |
| | | } |
| | | rMsg := protomsg.SdkMessage{} |
| | | if err := proto.Unmarshal(resultBytes, &rMsg);err ==nil{ |
| | | fmt.Println("received MSG:",rMsg.Cid) |
| | | 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 { |
| | | 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 =="FaceDetect"{ |
| | |
| | | } |
| | | } |
| | | } else { |
| | | fmt.Println("recv msg Err:",err) |
| | | fmt.Println("recv msg Err:", err) |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |