| | |
| | | package insertdata |
| | | |
| | | import ( |
| | | "ruleprocess/logger" |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "io/ioutil" |
| | | "net" |
| | | "ruleprocess/cache" |
| | | "ruleprocess/logger" |
| | | "strings" |
| | | "time" |
| | | |
| | |
| | | "github.com/satori/go.uuid" |
| | | "ruleprocess/ruleserver" |
| | | "ruleprocess/util" |
| | | "github.com/go-yaml/yaml" |
| | | ) |
| | | var weedfsUrl string |
| | | type conf struct { |
| | | PhotoUrl string `yaml:"photoUrl"` |
| | | } |
| | | func init() { |
| | | data, err := ioutil.ReadFile("./config/conf.yml") |
| | | if err != nil { |
| | | fmt.Println("读取配置文件出错--",err) |
| | | logger.Error("读取配置文件出错--",err) |
| | | } |
| | | c := conf{} |
| | | //把yaml形式的字符串解析成struct类型 |
| | | yaml.Unmarshal(data, &c) |
| | | weedfsUrl = c.PhotoUrl |
| | | } |
| | | |
| | | var weedfsUrl = "http://192.168.1.182:6333/submit" |
| | | // 人脸的数据结构 |
| | | type PerVideoPicture struct { |
| | | Id string `json:"id"` |
| | |
| | | AnalyServerName string `json:"analyServerName"` |
| | | AnalyServerIp string `json:"analyServerIp"` |
| | | ClusterId string `json:"clusterId"` |
| | | DetectScore float64 `json:"detectScore"` |
| | | IsAlarm int `json:"isAlarm"` |
| | | IsAckAlarm int `json:"isAckAlarm"` |
| | | IsCollect int `json:"isCollect"` |
| | |
| | | func InsertToEs(msg ruleserver.ResultMsg) { |
| | | |
| | | // 直接从规则的标签数据里拿符合规则的人脸结果 |
| | | //logger.Info("------------------------------------从配置文件读取的值:",weedfsUrl) |
| | | if msg.RuleResult["face"] != nil && len(msg.RuleResult["face"].([]ruleserver.Arg)) > 0 { |
| | | logger.Info("往ES插人脸数据") |
| | | for _, face := range msg.RuleResult["face"].([]ruleserver.Arg) { |
| | |
| | | } |
| | | i := protomsg.Image{} |
| | | err = proto.Unmarshal(bdata, &i) |
| | | //logger.Info("-------------------------------------------看下宽和高", i.Width, i.Height) |
| | | logger.Info("-------------------------------------------看下宽和高", int(face.Location.X),int(face.Location.Y),int(face.Location.X+face.Location.Width),int(face.Location.Y+face.Location.Height)) |
| | | bytes := util.SubImg(i, int(face.Location.X), int(face.Location.Y), int(face.Location.X+face.Location.Width), int(face.Location.Y+face.Location.Height)) |
| | | resp, err := util.PostFormBufferData1(weedfsUrl, bytes, uuid.NewV4().String()) |
| | | if err != nil { |
| | |
| | | localConfig.ServerName, |
| | | serverIp, |
| | | "", |
| | | face.Score, |
| | | 1, |
| | | 0, |
| | | 0, |
| | |
| | | return |
| | | |
| | | } |
| | | err = EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody) |
| | | err1 := EsReq("POST", "http://192.168.1.182:9200/videopersons/perVideoPicture", requstbody) |
| | | if err1 != nil { |
| | | logger.Error("上传ES出错!---",err1) |
| | | } |
| | | //logger.Info(err.Error()) |
| | | } else { |
| | | // 人脸提取 |
| | | // 人脸比对 |
| | | logger.Warn("___________________________________________这是有baseinfo的") |
| | | localConfig, err := cache.GetServerInfo() |
| | | if err != nil { |
| | | logger.Info("查询本机信息失败!") |
| | |
| | | localConfig.ServerName, |
| | | serverIp, |
| | | "", |
| | | face.Score, |
| | | 1, |
| | | 0, |
| | | 0, |
| | |
| | | if err != nil { |
| | | logger.Error("往ES插入数据失败", err) |
| | | } else { |
| | | logger.Info("__________________________________________往ES插入yolo数据成功") |
| | | logger.Warn("__________________________________________往ES插入yolo数据成功") |
| | | //os.Exit(1) |
| | | } |
| | | } |
| | | } |