-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
67 lines (53 loc) · 1.45 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
60
61
62
63
64
65
66
67
package main
import (
"fmt"
"log"
"path/filepath"
"sync"
"github.com/Sup3r-Us3r/go-object-detection/internal/domain/entity"
"github.com/Sup3r-Us3r/go-object-detection/internal/infra/opencv"
"github.com/Sup3r-Us3r/go-object-detection/internal/infra/tensorflow"
"github.com/Sup3r-Us3r/go-object-detection/internal/usecase"
)
func worker(
workerId int,
camera entity.VideoStream,
openCV *opencv.OpenCVImageProcessor,
runDetectionUseCase *usecase.RunDetectionUseCase,
) {
fmt.Printf("WORKER ID [%v] - DEVICE [%v]\n", workerId, camera.Label)
openCV.CaptureStreamVideo(camera.Input, runDetectionUseCase.Execute)
}
// List of cameras to run object detection
func getCameras() (cameras []entity.VideoStream) {
cameras = []entity.VideoStream{
{
ID: "1",
Label: "Camera 1",
Input: "rtsp://host:port",
},
}
return cameras
}
func main() {
wg := sync.WaitGroup{}
tf := tensorflow.NewTensorflowMachineLearning()
openCV := opencv.NewOpenCVImageProcessor()
modelPath, err := filepath.Abs("data/models/ssd_mobilenet_v1_coco_2018_01_28/saved_model")
if err != nil {
log.Fatal(err)
}
model, tfSession, err := tf.LoadSavedModel(modelPath)
if err != nil {
log.Fatal(err)
}
defer model.Session.Close()
defer tfSession.Close()
runDetectionUseCase := usecase.NewRunDetectionUseCase(tf, openCV)
for index, camera := range getCameras() {
wg.Add(1)
defer wg.Done()
go worker(index+1, camera, openCV, runDetectionUseCase)
}
wg.Wait()
}