forked from foxis/EasyRobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
consumer.go
52 lines (44 loc) · 1.32 KB
/
consumer.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
package main
import (
"context"
"github.com/itohio/EasyRobot/pkg/core/pipeline"
"github.com/itohio/EasyRobot/pkg/core/pipeline/steps"
"github.com/itohio/EasyRobot/pkg/core/pipeline/steps/fps"
"github.com/itohio/EasyRobot/pkg/core/plugin"
"github.com/itohio/EasyRobot/pkg/core/store"
"github.com/itohio/EasyRobot/pkg/vision/display"
"github.com/itohio/EasyRobot/pkg/vision/writer"
)
func setupConsumer(ctx context.Context, pipe pipeline.Pipeline, nc pipeline.Step, out, ext string, block, hide bool) (<-chan store.Store, error) {
fps, err := fps.New(fps.WithNumFrames(10), plugin.WithBlocking(block))
if err != nil {
panic(err)
}
fout, err := steps.NewFanOut(plugin.WithBlocking(block), plugin.WithClose(false))
if err != nil {
panic(err)
}
output, err := display.NewGoCV(
plugin.WithClose(out != ""),
display.WithKey(store.IMAGE),
plugin.WithBlocking(block),
)
if err != nil {
panic(err)
}
keys, err := pipe.ConnectSteps(nc, fps, fout, output)
if err != nil {
panic(err)
}
var sink pipeline.Step
if out == "" {
sink, err = writer.NewNull(plugin.WithClose(hide))
} else {
sink, err = writer.NewGoCV(plugin.WithClose(hide), writer.WithKey(store.IMAGE), writer.WithExtension(ext), writer.WithPrefix(out))
}
_, err = pipe.ConnectSteps(fout, sink)
if err != nil {
panic(err)
}
return keys, nil
}