-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
59 lines (46 loc) · 1.04 KB
/
main.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
package main
import (
"fmt"
"image/color"
"gocv.io/x/gocv"
"gocv.io/x/gocv/cuda"
)
func main() {
deviceID := "0"
webcam, err := gocv.OpenVideoCapture(deviceID)
if err != nil {
fmt.Printf("Error opening video capture device: %v\n", deviceID)
return
}
defer webcam.Close()
window := gocv.NewWindow("Capture Window")
defer window.Close()
img := gocv.NewMat()
defer img.Close()
hog := cuda.CreateHOG()
hog.SetSVMDetector(hog.GetDefaultPeopleDetector())
gpumat := cuda.NewGpuMat()
defer gpumat.Close()
graygpumat := cuda.NewGpuMat()
defer graygpumat.Close()
fmt.Printf("Start reading device: %v\n", deviceID)
for {
if ok := webcam.Read(&img); !ok {
fmt.Printf("Device closed: %v\n", deviceID)
return
}
if img.Empty() {
continue
}
gpumat.Upload(img)
cuda.CvtColor(gpumat, &graygpumat, gocv.ColorBGRToGray)
rects := hog.DetectMultiScale(graygpumat)
for _, rect := range rects {
gocv.Rectangle(&img, rect, color.RGBA{0, 0, 255, 0}, 2)
}
window.IMShow(img)
if window.WaitKey(1) == 27 {
break
}
}
}