-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
57 lines (44 loc) · 1.06 KB
/
main.go
File metadata and controls
57 lines (44 loc) · 1.06 KB
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
package main
import (
"gocv.io/x/gocv"
"log"
"image/color"
"fmt"
)
func main() {
deviceID := 0
webcam, err := gocv.VideoCaptureDevice(int(deviceID))
if err != nil {
log.Fatalf("Could not open capture device %v", deviceID)
return
}
defer webcam.Close()
window := gocv.NewWindow("Face Detect")
defer window.Close()
img := gocv.NewMat()
defer img.Close()
blue := color.RGBA{0, 0, 255, 0}
classifier := gocv.NewCascadeClassifier()
defer classifier.Close()
classifier.Load("data/haarcascade_frontalface_default.xml")
fmt.Printf("Start reading camera device: %v\n", deviceID)
for {
if ok := webcam.Read(img); !ok {
fmt.Printf("cannot read device %d\n", deviceID)
return
}
if img.Empty() {
continue
}
// detect faces
rects := classifier.DetectMultiScale(img)
fmt.Printf("found %d faces\n", len(rects))
// draw a rectangle around each face on the original image
for _, r := range rects {
gocv.Rectangle(img, r, blue, 3)
}
// show the image in the window, and wait 1 millisecond
window.IMShow(img)
window.WaitKey(1)
}
}