| | |
| | | |
| | | "track/gohumantrack" |
| | | |
| | | "gocv.io/x/gocv" |
| | | "basic.com/valib/goffmpeg.git" |
| | | ) |
| | | |
| | | var ( |
| | |
| | | flag.StringVar(&url2, "cam2", "", "url") |
| | | } |
| | | func main() { |
| | | flag.Parse() |
| | | fmt.Println("url1: ", url1, " url2: ", url2) |
| | | if len(url1) == 0 || len(url2) == 0 { |
| | | fmt.Println("url null") |
| | | } |
| | | |
| | | cam1, err := gocv.OpenVideoCapture(url1) |
| | | if err != nil { |
| | | fmt.Println("cv open url1 error: ", err) |
| | | return |
| | | } |
| | | cam2, err := gocv.OpenVideoCapture(url2) |
| | | if err != nil { |
| | | fmt.Println("cv open url2 error: ", err) |
| | | return |
| | | } |
| | | goffmpeg.InitFFmpeg("./runtime/libcffmpeg.so") |
| | | |
| | | img1 := gocv.NewMat() |
| | | defer img1.Close() |
| | | img2 := gocv.NewMat() |
| | | defer img2.Close() |
| | | cam1 := goffmpeg.New(false, false) |
| | | cam1.Run(url1) |
| | | cam1.BuildDecoder() |
| | | cam1.CloseStream() |
| | | |
| | | cam2 := goffmpeg.New(false, false) |
| | | cam2.Run(url2) |
| | | cam2.BuildDecoder() |
| | | cam2.CloseStream() |
| | | |
| | | tracker := gohumantrack.NewHumanTracker(0, 2, 0) |
| | | fmt.Println("version: ", tracker.GetVersion()) |
| | | for { |
| | | if ok := cam1.Read(&img1); !ok || img1.Empty() { |
| | | fmt.Println("read url1 image error") |
| | | time.Sleep(40 * time.Millisecond) |
| | | continue |
| | | } |
| | | if ok := cam2.Read(&img2); !ok || img2.Empty() { |
| | | fmt.Println("read url2 image error") |
| | | time.Sleep(40 * time.Millisecond) |
| | | continue |
| | | } |
| | | data1, ow1, oh1, _ := cam1.GetYUV() |
| | | data2, ow2, oh2, _ := cam2.GetYUV() |
| | | if ow1 > 0 && oh1 > 0 && ow2 > 0 && oh2 > 0 { |
| | | |
| | | var images []gohumantrack.ImageHumanTracker |
| | | img := gohumantrack.ImageHumanTracker{ |
| | | Data: img1.ToBytes(), |
| | | Width: img1.Cols, |
| | | Height: img1.Rows, |
| | | Channel: img1.Channels, |
| | | var images []gohumantrack.ImageHumanTracker |
| | | img := gohumantrack.ImageHumanTracker{ |
| | | Data: data1, |
| | | Width: ow1, |
| | | Height: oh1, |
| | | Channel: 3, |
| | | } |
| | | images = append(images, img) |
| | | img = gohumantrack.ImageHumanTracker{ |
| | | Data: data2, |
| | | Width: ow2, |
| | | Height: oh2, |
| | | Channel: 3, |
| | | } |
| | | images = append(images, img) |
| | | res, err := tracker.Process(images) |
| | | if err == nil { |
| | | for _, v := range res { |
| | | fmt.Printf("result size: %d\n", v.FgNum) |
| | | for i := 0; i < int(v.FgNum); i++ { |
| | | r := v.Fginfo[i] |
| | | if r.Confidence > 0 { |
| | | fmt.Printf(" Index %d Rect: %dx%dx%dx%d", i, r.Left, r.Top, r.Right, r.Bottom) |
| | | fmt.Printf(" Confidence: %f", r.Confidence*100) |
| | | fmt.Printf(" Center: %dx%d", r.X, r.Y) |
| | | fmt.Printf(" ID: %d\n", r.ID) |
| | | } |
| | | } |
| | | |
| | | } |
| | | } else { |
| | | fmt.Println("process error: ", err) |
| | | } |
| | | } else { |
| | | // fmt.Println("cam1 size: ", ow1, "x", oh1, " cam2 size: ", ow2, "x", oh2) |
| | | time.Sleep(38 * time.Millisecond) |
| | | } |
| | | images = append(images, img) |
| | | img = gohumantrack.ImageHumanTracker{ |
| | | Data: img2.ToBytes(), |
| | | Width: img2.Cols, |
| | | Height: img2.Rows, |
| | | Channel: img2.Channels, |
| | | } |
| | | images = append(images, img) |
| | | |
| | | } |
| | | tracker.Free() |
| | | |
| | | goffmpeg.FreeFFmpeg() |
| | | } |