jakaskerl
I did and is not working for my program, but on this one :
import cv2
import depthai as dai
import logging
from logging.handlers import TimedRotatingFileHandler
import os
from datetime import datetime
import sys
import traceback
# Set up logging
log_directory = "/home/PeopleCounter/PeopleCounterLogs"
if not os.path.exists(log_directory):
os.makedirs(log_directory)
# Create a log file with the current date
log_file = os.path.join(log_directory, f"people_tracker_{datetime.now().strftime('%Y-%m-%d')}.log")
logger = logging.getLogger("PeopleTrackerLogger")
logger.setLevel(logging.DEBUG)
# Create a TimedRotatingFileHandler that creates a new log file at midnight
handler = TimedRotatingFileHandler(log_file, when="midnight", interval=1, backupCount=30)
handler.suffix = "%Y-%m-%d"
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
handler.setFormatter(formatter)
logger.addHandler(handler)
# Function to log exceptions with detailed traceback
def log_exception(exc_type, exc_value, exc_traceback):
if issubclass(exc_type, KeyboardInterrupt):
sys.__excepthook__(exc_type, exc_value, exc_traceback)
return
logger.error("Uncaught exception", exc_info=(exc_type, exc_value, exc_traceback))
tb_lines = traceback.format_exception(exc_type, exc_value, exc_traceback)
logger.error("".join(tb_lines))
sys.excepthook = log_exception
logger.info("Starting People Tracker Application")
try:
# Create pipeline
logger.info("Creating pipeline")
pipeline = dai.Pipeline()
# Define sources and outputs
logger.info("Defining sources and outputs")
monoLeft = pipeline.create(dai.node.MonoCamera)
monoRight = pipeline.create(dai.node.MonoCamera)
xoutLeft = pipeline.create(dai.node.XLinkOut)
xoutRight = pipeline.create(dai.node.XLinkOut)
xoutLeft.setStreamName('left')
xoutRight.setStreamName('right')
# Set camera properties
logger.info("Setting camera properties")
monoLeft.setCamera("left")
monoLeft.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
monoRight.setCamera("right")
monoRight.setResolution(dai.MonoCameraProperties.SensorResolution.THE_720_P)
# Link nodes
logger.info("Linking nodes")
monoRight.out.link(xoutRight.input)
monoLeft.out.link(xoutLeft.input)
# Connect to device and start pipeline
logger.info("Connecting to device and starting pipeline")
with dai.Device(pipeline) as device:
logger.info("Pipeline started successfully")
# Output queues to get frames from the cameras
logger.info("Creating output queues")
qLeft = device.getOutputQueue(name="left", maxSize=4, blocking=False)
qRight = device.getOutputQueue(name="right", maxSize=4, blocking=False)
logger.info("Entering main loop")
while True:
# Get frames from the cameras
logger.debug("Attempting to get frames from the cameras")
inLeft = qLeft.tryGet()
inRight = qRight.tryGet()
if inLeft is not None:
logger.debug("Received left frame")
frame = inLeft.getCvFrame()
logger.debug("Left frame shape: %s", frame.shape)
cv2.imshow("left", frame)
logger.info("Displayed left frame")
if inRight is not None:
logger.debug("Received right frame")
frame = inRight.getCvFrame()
logger.debug("Right frame shape: %s", frame.shape)
cv2.imshow("right", frame)
logger.info("Displayed right frame")
# Check for exit signal
if cv2.waitKey(1) == ord('q'):
logger.info("Exit signal received, closing application")
break
except Exception as e:
logger.error("An error occurred: %s", traceback.format_exc())
finally:
logger.info("People Tracker Application finished")
I don't get the "Exception("No OAK device found to connect to!")"
Are you running the same app from the github or another app ?
Thanks