Skip to content

Instantly share code, notes, and snippets.

@VanDavv
Created May 28, 2020 09:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VanDavv/8961c1458271f5c25e22d165ee4415c6 to your computer and use it in GitHub Desktop.
Save VanDavv/8961c1458271f5c25e22d165ee4415c6 to your computer and use it in GitHub Desktop.
A simple script with simple DepthAI pipeline init and preview
import consts.resource_paths
import cv2
import depthai
if not depthai.init_device(consts.resource_paths.device_cmd_fpath):
raise RuntimeError("Error initializing device. Try to reset it.")
p = depthai.create_pipeline(config={
"streams": ["metaout", "previewout"],
"ai": {
"blob_file": "/path/to/model.blob",
"blob_file_config": "/path/to/config.json"
}
})
if p is None:
raise RuntimeError("Error initializing pipelne")
entries_prev = []
while True:
nnet_packets, data_packets = p.get_available_nnet_and_data_packets()
for _, nnet_packet in enumerate(nnet_packets):
entries_prev = []
for _, e in enumerate(nnet_packet.entries()):
if e[0]['id'] == -1.0 or e[0]['confidence'] == 0.0:
break
if e[0]['confidence'] > 0.5:
entries_prev.append(e[0])
for packet in data_packets:
if packet.stream_name == 'previewout':
data = packet.getData()
data0 = data[0, :, :]
data1 = data[1, :, :]
data2 = data[2, :, :]
frame = cv2.merge([data0, data1, data2])
img_h = frame.shape[0]
img_w = frame.shape[1]
for e in entries_prev:
pt1 = int(e['left'] * img_w), int(e['top'] * img_h)
pt2 = int(e['right'] * img_w), int(e['bottom'] * img_h)
cv2.rectangle(frame, pt1, pt2, (0, 0, 255), 2)
cv2.imshow('previewout', frame)
if cv2.waitKey(1) == ord('q'):
break
del p
depthai.deinit_device()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment