| | |
| | | } |
| | | } |
| | | |
| | | func DrawPolygonOnImage(cameraId string, img protomsg.Image) (maps map[string]interface{}, err0 error) { |
| | | // draw the rook |
| | | //ddd, err := RetrieveROM("/home/user/workspace/ruleprocess/util/105.jpg") |
| | | //if err != nil { |
| | | // fmt.Println("解码有误",err) |
| | | //} |
| | | //bbb := bytes.NewBuffer(ddd) // 必须加一个buffer 不然没有read方法就会报错 |
| | | //rook,_ := gocv.IMDecode(bbb.Bytes(),gocv.IMReadColor) |
| | | 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), |
| | | // }, |
| | | //} |
| | | //gocv.FillPoly(&rook, points, green) |
| | | red := color.RGBA{255, 0, 0, 0} |
| | | // 查到摄像机所有的区域并画框 |
| | | var cameraPolygons []protomsg.CameraPolygon |
| | | cameraPolygons = cache.GetPolygonsByCameraId(cameraId) |
| | |
| | | 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)), green, 2) |
| | | 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)), green, 2) |
| | | 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) |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | // 把目标框出来 |
| | | 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) |