|
1 | | -import cv2 |
2 | | -import numpy as np |
3 | | - |
4 | | -from depthai_sdk import OakCamera, DetectionPacket, Visualizer |
5 | | - |
6 | | -NN_WIDTH, NN_HEIGHT = 513, 513 |
7 | | - |
8 | | - |
9 | | -def process_mask(output_tensor): |
10 | | - class_colors = [[0, 0, 0], [0, 255, 0]] |
11 | | - class_colors = np.asarray(class_colors, dtype=np.uint8) |
12 | | - output = output_tensor.reshape(NN_WIDTH, NN_HEIGHT) |
13 | | - output_colors = np.take(class_colors, output, axis=0) |
14 | | - return output_colors |
15 | | - |
16 | | - |
17 | | -def callback(packet: DetectionPacket, visualizer: Visualizer): |
18 | | - frame = packet.frame |
19 | | - mask = packet.img_detections.mask |
20 | | - |
21 | | - output_colors = process_mask(mask) |
22 | | - output_colors = cv2.resize(output_colors, (frame.shape[1], frame.shape[0])) |
23 | | - |
24 | | - frame = cv2.addWeighted(frame, 1, output_colors, 0.2, 0) |
25 | | - cv2.imshow('DeepLabV3 person segmentation', frame) |
| 1 | +from depthai_sdk import OakCamera |
26 | 2 |
|
27 | 3 |
|
28 | 4 | with OakCamera() as oak: |
29 | 5 | color = oak.create_camera('color', resolution='1080p') |
30 | 6 |
|
31 | 7 | nn = oak.create_nn('deeplabv3_person', color) |
32 | | - nn.config_nn(resize_mode='stretch') |
| 8 | + nn.config_nn(resize_mode='letterbox') |
33 | 9 |
|
34 | | - oak.callback(nn, callback=callback) |
| 10 | + visualizer = oak.visualize([nn, nn.out.passthrough], fps=True) |
35 | 11 | oak.start(blocking=True) |
0 commit comments