| | |
| | | package util |
| | | |
| | | import ( |
| | | "basic.com/pubsub/protomsg.git" |
| | | "bufio" |
| | | "bytes" |
| | | "encoding/json" |
| | | "errors" |
| | | "fmt" |
| | | "gocv.io/x/gocv" |
| | | "image" |
| | | "image/color" |
| | | "io" |
| | |
| | | "mime/multipart" |
| | | "net/http" |
| | | "os" |
| | | "ruleprocess/cache" |
| | | "ruleprocess/ruleserver" |
| | | "time" |
| | | |
| | | "gocv.io/x/gocv" |
| | | ) |
| | | |
| | | func CvRTSP() { |
| | |
| | | } |
| | | } |
| | | |
| | | func DrawPolygonOnImage()(maps map[string]interface{}, err0 error){ |
| | | // draw the rook |
| | | //rook := gocv.NewMatWithSize(w, w, gocv.MatTypeCV8UC3) |
| | | //imgs := gocv.NewMat() |
| | | ddd, err := RetrieveROM("/home/user/workspace/ruleprocess/util/105.jpg") |
| | | if err != nil { |
| | | fmt.Println("解码有误",err) |
| | | } |
| | | bbb := bytes.NewBuffer(ddd) // 必须加一个buffer 不然没有read方法就会报错 |
| | | rook, _ := gocv.NewMatFromBytes(500, 500, gocv.MatTypeCV8UC3, bbb.Bytes()) |
| | | func DrawPolygonOnImage(cameraId string, img protomsg.Image, results []ruleserver.Result) (maps map[string]interface{}, err0 error) { |
| | | |
| | | rook, _ := gocv.NewMatFromBytes(int(img.Height), int(img.Width), gocv.MatTypeCV8UC3, img.Data) |
| | | //rook := gocv.IMRead("/home/user/workspace/ruleprocess/util/105.jpg",gocv.IMReadColor) |
| | | defer rook.Close() |
| | | green := color.RGBA{0, 255, 0, 0} |
| | | points := [][]image.Point{ |
| | | { |
| | | image.Pt(100., 100), |
| | | image.Pt(100., 400), |
| | | image.Pt(400, 400), |
| | | image.Pt(400, 100), |
| | | }, |
| | | |
| | | red := color.RGBA{255, 0, 0, 0} |
| | | // 查到摄像机所有的区域并画框 |
| | | var cameraPolygons []protomsg.CameraPolygon |
| | | cameraPolygons = cache.GetPolygonsByCameraId(cameraId) |
| | | for _, polygon := range cameraPolygons { |
| | | points := ruleserver.Json2points(polygon.Polygon) |
| | | for index := 0; index < len(points); index++ { |
| | | if index == len(points)-1 { // 闭合图形 |
| | | gocv.Line(&rook, image.Pt(int(points[index].X), int(points[index].Y)), image.Pt(int(points[0].X), int(points[0].Y)), red, 2) |
| | | } else { |
| | | gocv.Line(&rook, image.Pt(int(points[index].X), int(points[index].Y)), image.Pt(int(points[index+1].X), int(points[index+1].Y)), red, 2) |
| | | } |
| | | |
| | | } |
| | | } |
| | | gocv.FillPoly(&rook, points, green) |
| | | // 把目标框出来 |
| | | for _,result := range results { |
| | | for _,rect := range result.Location { |
| | | gocv.Rectangle(&rook, image.Rect(int(rect.X), int(rect.Y), int(rect.X+rect.Width), int(rect.Y+rect.Height)), red, 1) |
| | | } |
| | | } |
| | | //return nil,nil |
| | | // 上传 |
| | | fdata,_ := gocv.IMEncode(".jpg",rook) |
| | | fdata, _ := gocv.IMEncode(".jpg", rook) |
| | | body := &bytes.Buffer{} |
| | | writer := multipart.NewWriter(body) |
| | | _, err1 := writer.CreateFormFile("file", "fasjuierf") |