-
Notifications
You must be signed in to change notification settings - Fork 392
Expand file tree
/
Copy pathdiff.py
More file actions
63 lines (51 loc) · 1.91 KB
/
diff.py
File metadata and controls
63 lines (51 loc) · 1.91 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
58
59
60
61
62
63
import depthai as dai
from pathlib import Path
from utils.arguments import initialize_argparser
from utils.colorize_diff import ColorizeDiff
NN_DIFF_SIZE = (720, 720)
_, args = initialize_argparser()
device = dai.Device(dai.DeviceInfo(args.device)) if args.device else dai.Device()
visualizer = dai.RemoteConnection(httpPort=8082)
with dai.Pipeline(device) as pipeline:
platform = device.getPlatformAsString()
cam_rgb = pipeline.create(dai.node.Camera).build(
boardSocket=dai.CameraBoardSocket.CAM_A
)
cam_rgb_diff_out = cam_rgb.requestOutput(
size=NN_DIFF_SIZE,
type=dai.ImgFrame.Type.BGR888i
if platform == "RVC4"
else dai.ImgFrame.Type.BGR888p,
fps=args.fps_limit,
)
script = pipeline.create(dai.node.Script)
script.setScript("""
old = node.io['in'].get()
while True:
frame = node.io['in'].get()
node.io['img1'].send(old)
node.io['img2'].send(frame)
old = frame
""")
cam_rgb_diff_out.link(script.inputs["in"])
# DIFF
diff_nn_archive_path = Path(__file__).parent / Path(
f"models/diff.{platform.lower()}.tar.xz"
)
diff_nn_archive = dai.NNArchive(archivePath=str(diff_nn_archive_path))
nn_diff = pipeline.create(dai.node.NeuralNetwork)
nn_diff.setNNArchive(diff_nn_archive)
script.outputs["img1"].link(nn_diff.inputs["img1"])
script.outputs["img2"].link(nn_diff.inputs["img2"])
diff_color = pipeline.create(ColorizeDiff).build(nn=nn_diff.out)
visualizer.addTopic("Diff", diff_color.out, "images")
visualizer.addTopic("Passthrough", script.outputs["img1"], "images")
print("Pipeline created.")
pipeline.start()
visualizer.registerPipeline(pipeline)
while pipeline.isRunning():
pipeline.processTasks()
key = visualizer.waitKey(1)
if key == ord("q"):
print("Got q key from the remote connection!")
break