liuxiaolong
2019-06-26 021679b25d25b608380be9e50d09184a3f49eb62
test faceSdkExtract
3个文件已修改
73 ■■■■ 已修改文件
controllers/camera.go 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/FaceSdkService.go 43 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
service/FaceSdkService_test.go 28 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
controllers/camera.go
@@ -243,8 +243,10 @@
        util.ResponseFormat(c,code.RequestParamError,"参数有误")
        return
    }
    var api dbapi.CameraApi
    b, data := api.UpdateRunEnable(cameraId, runEnable)
    fmt.Println("data:",data)
    if b {
        util.ResponseFormat(c,code.Success,data)
    } else {
service/FaceSdkService.go
@@ -1,33 +1,50 @@
package service
import (
    "basic.com/pubsub/protomsg.git"
    "basic.com/valib/deliver.git"
    "github.com/gin-gonic/gin/internal/json"
    "encoding/json"
    "fmt"
    "github.com/gogo/protobuf/proto"
)
type ImageSource struct {
    Id string `json:"id"`
    Data []byte `json:"data"`
}
const (
    Url_Service_PUSH = "tcp:///tmp///webserver-2.ipc"
    Url_Service_PULL = "tcp:///tmp///webserver-1.ipc"
)
var imgChan chan ImageSource
func PushImgMsg(is ImageSource){
    imgChan <- is
var imgPushChan chan protomsg.Recvmsg
func PushImgMsg(is protomsg.Recvmsg){
    imgPushChan <- is
}
var resultMap map[string]protomsg.SdkMessage
func InitService(){
    imgChan = make(chan ImageSource)
    client := deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
    imgPushChan = make(chan protomsg.Recvmsg)
    client_push := deliver.NewClient(deliver.PushPull, Url_Service_PUSH)
    client_pull := deliver.NewClient(deliver.PushPull, Url_Service_PULL)
    for {
        select {
        case is := <- imgChan:
            b, _ := json.Marshal(is)
            client.Send(b)
            case is := <- imgPushChan:
                b, _ := json.Marshal(is)
                client_push.Send(b)
        }
    }
    //接收人脸提取结果
    for {
        resultBytes, err := client_pull.Recv()
        if err !=nil{
            fmt.Println("pull err:",err)
            continue
        }
        rMsg := protomsg.SdkMessage{}
        if err := proto.Unmarshal(resultBytes, &rMsg);err !=nil{
            fmt.Println(rMsg)
            resultMap[rMsg.Cid] = rMsg
        }
    }
service/FaceSdkService_test.go
@@ -1 +1,29 @@
package service
import (
    "basic.com/pubsub/protomsg.git"
    "github.com/satori/go.uuid"
    "io/ioutil"
    "testing"
    "time"
)
func TestPushImgMsg(t *testing.T) {
    InitService()
    imgData := readImgFile()
    for {
        PushImgMsg(protomsg.Recvmsg{
            Id:uuid.NewV4().String(),
            Addr:"",
            Picdata:imgData,
        })
        time.Sleep(5*time.Second)
    }
}
func readImgFile() []byte{
    filePath := "/home/user/workspace/timg.jpg"
    bytes, _ := ioutil.ReadFile(filePath)
    return bytes
}