58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
|
|
import cv2
|
||
|
|
import depthai as dai
|
||
|
|
import time
|
||
|
|
|
||
|
|
FPS = 30
|
||
|
|
SIZE = (640, 400)
|
||
|
|
|
||
|
|
device = dai.Device()
|
||
|
|
|
||
|
|
print("[INFO] DepthAI:", dai.__version__)
|
||
|
|
print("[INFO] Cameras conectadas:")
|
||
|
|
print(device.getConnectedCameraFeatures())
|
||
|
|
print("[INFO] Sockets:", device.getConnectedCameras())
|
||
|
|
|
||
|
|
with dai.Pipeline(device) as pipeline:
|
||
|
|
queues = {}
|
||
|
|
|
||
|
|
sockets = device.getConnectedCameras()
|
||
|
|
|
||
|
|
for socket in sockets:
|
||
|
|
print(f"[INFO] Criando câmera no socket: {socket}")
|
||
|
|
|
||
|
|
cam = pipeline.create(dai.node.Camera).build(socket)
|
||
|
|
|
||
|
|
out = cam.requestOutput(
|
||
|
|
SIZE,
|
||
|
|
type=dai.ImgFrame.Type.BGR888p,
|
||
|
|
fps=FPS
|
||
|
|
)
|
||
|
|
|
||
|
|
queues[str(socket)] = out.createOutputQueue()
|
||
|
|
|
||
|
|
pipeline.start()
|
||
|
|
|
||
|
|
last = time.time()
|
||
|
|
frames = 0
|
||
|
|
|
||
|
|
while pipeline.isRunning():
|
||
|
|
for name, q in queues.items():
|
||
|
|
msg = q.tryGet()
|
||
|
|
|
||
|
|
if msg is not None:
|
||
|
|
frame = msg.getCvFrame()
|
||
|
|
cv2.imshow(f"OAK {name}", frame)
|
||
|
|
|
||
|
|
frames += 1
|
||
|
|
now = time.time()
|
||
|
|
|
||
|
|
if now - last >= 1.0:
|
||
|
|
print(f"[FPS LOOP] {frames / (now - last):.1f}")
|
||
|
|
frames = 0
|
||
|
|
last = now
|
||
|
|
|
||
|
|
key = cv2.waitKey(1)
|
||
|
|
if key == 27 or key == ord("q"):
|
||
|
|
break
|
||
|
|
|
||
|
|
cv2.destroyAllWindows()
|