-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathplayer.go
79 lines (65 loc) · 1.55 KB
/
player.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Copyright 2011 <chaishushan@gmail.com>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// +build ingore
package main
import (
"fmt"
"log"
"os"
"github.com/chai2010/opencv"
)
func main() {
filename := "../testdata/test.avi"
if len(os.Args) >= 2 {
filename = os.Args[1]
}
cap := opencv.NewFileCapture(filename)
if cap == nil {
log.Fatalf("can not open video %s", filename)
}
defer cap.Release()
win := opencv.NewWindow("GoOpenCV: VideoPlayer")
defer win.Destroy()
fps := int(cap.GetProperty(opencv.CV_CAP_PROP_FPS))
frames := int(cap.GetProperty(opencv.CV_CAP_PROP_FRAME_COUNT))
stop := false
win.SetMouseCallback(func(event, x, y, flags int) {
if flags&opencv.CV_EVENT_LBUTTONDOWN != 0 {
stop = !stop
if stop {
fmt.Printf("status: stop\n")
} else {
fmt.Printf("status: palying\n")
}
}
})
win.CreateTrackbar("Seek", 1, frames, func(pos int) {
cur_pos := int(cap.GetProperty(opencv.CV_CAP_PROP_POS_FRAMES))
if pos != cur_pos {
cap.SetProperty(opencv.CV_CAP_PROP_POS_FRAMES, float64(pos))
fmt.Printf("Seek to %d(%d)\n", pos, frames)
}
})
for {
if !stop {
img := cap.QueryFrame()
if img == nil {
break
}
frame_pos := int(cap.GetProperty(opencv.CV_CAP_PROP_POS_FRAMES))
if frame_pos >= frames {
break
}
win.SetTrackbarPos("Seek", frame_pos)
win.ShowImage(img)
if key := opencv.WaitKey(1000 / fps); key == 27 {
break
}
} else {
if key := opencv.WaitKey(20); key == 27 {
break
}
}
}
}