Excuse the poor formatting, the insert code function on the post reply is driving me crazy
Ccitsystems
- May 24, 2024
- Joined May 23, 2024
- 0 best answers
- Edited
Hi All,
Can the DepthAI SDK run two Roboflow models? I've got my code setup to run two models, it seems to run successfully but when I trigger either model it appears to execute the same trigger either way.
from depthai_sdk import OakCamera from depthai_sdk.classes import DetectionPacket from depthai_sdk.trigger_action import Action, DetectionTrigger import requests from datetime import datetime class SendAlertAction(Action): def __init__(self, data_value, name, \*args, \*\*kwargs): super().__init__(\*args, \*\*kwargs) self.data_value = data_value self.name = name def activate(self): print(f"{self.name} activated") self.send_alert() def send_alert(self): url = "http://x.x.x.x:x/x/createAlert" headers = { "Authorization": "Basic x", "Content-Type": "application/json", "Accept": "application/json" } data = { "public": "", "fw_version": "", "userid": "", "published_at": datetime.now().isoformat(), "data": self.data_value, "event": "", "deviceId": "xxxxxxxxxx" } response = requests.post(url, json=data, headers=headers) print(f"Alert sent, status code: {response.status_code}, data sent: {self.data_value}") \# Callback function for detection packets def detection_callback(packet: DetectionPacket, model_name: str): print(f"Detections for {model_name}: {packet.img_detections}") with OakCamera("192.168.0.10") as oak: color = oak.create_camera('color') # Configure the first Roboflow model model_config1 = { 'source': 'roboflow', 'model': 'people-falling-h8xp1/5', # Replace with your actual model and version 'key': 'xxxxxxxxxx' # Replace with your actual API key } nn1 = oak.create_nn(model_config1, color) # Configure the second Roboflow model model_config2 = { 'source': 'roboflow', 'model': 'gesture-detection-pb99q/4', # Update to version 4 'key': 'xxxxxxxxxx' # Use the same API key if applicable } nn2 = oak.create_nn(model_config2, color) # Define the detection trigger for 'fall' class for the first model trigger1 = DetectionTrigger(input=nn1, min_detections={'fall': 1}, cooldown=30) print("Trigger1 created") # Define the detection trigger for 'waving' class for the second model trigger2 = DetectionTrigger(input=nn2, min_detections={'waving': 1}, cooldown=30) print("Trigger2 created") # Define the custom actions to send an alert with different data values action1 = SendAlertAction(data_value="x1", name="Action1") action2 = SendAlertAction(data_value="x2", name="Action2") # Set up the trigger-action pairs oak.trigger_action(trigger=trigger1, action=action1) print("Trigger1 action set") oak.trigger_action(trigger=trigger2, action=action2) print("Trigger2 action set") # Set up callbacks to check detection packets oak.callback(nn1.out.main, callback=lambda packet: detection_callback(packet, "people-falling"), enable_visualizer=False) oak.callback(nn2.out.main, callback=lambda packet: detection_callback(packet, "gesture-detection"), enable_visualizer=False) # Start the camera and processing loop oak.start(blocking=True)
Thank's that appeared to work, what about If I want to run a group of POE IP Cameras on one model, Do I have to create multiple OAK Camera objects?
Hi All,
I've decided to use the depthai_sdk library instead of the direct depthai library, how do I initialise the POE camera and specify it's IP, is there a particular property that needs to be set?
Reason I'm using the sdk library is because I want to embed a roboflow model and that functionality is built into the SDK.
Thanks
Ben