Hi, I am trying to use the yolov8 model driver drowsiness detection on my arduino nicla vison board. I a using the openmv IDE for this… I have configured the API key and model ID but anytime i run the code i get inference failed with status code 0.
Below is the code I am currenty ruuning
import sensor, image, time
import network
import pyb
import urequests # MicroPython requests module
Wi-Fi connection details
SSID = “****”
PASSWORD = “*****”
Initialize the NIC (network interface controller)
nic = network.WLAN(network.STA_IF)
nic.active(True)
Connect to the Wi-Fi network
nic.connect(SSID, PASSWORD)
Wait for connection and log to the terminal
while not nic.isconnected():
print(“Connecting to Wi-Fi…”)
time.sleep(1)
print(“Connected to Wi-Fi”)
print(nic.ifconfig()) # Print the IP address, subnet mask, gateway, and DNS
Initialize the camera sensor
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
clock = time.clock()
Roboflow API details
MODEL_ID = “drive-drowsiness-detection/2”
API_KEY = “********”
ROBOFLOW_URL = f"https://inference.roboflow.com/infer/object_detection/{MODEL_ID}?api_key={API_KEY}"
roboflow_config = {
“model_id”: MODEL_ID,
“api_key”: API_KEY,
“image”: [
{
“type”: “url”,
“value”: “Redirect Notice”
}
],
“disable_preproc_auto_orient”: False,
“disable_preproc_contrast”: False,
“disable_preproc_grayscale”: False,
“disable_preproc_static_crop”: False,
“class_agnostic_nms”: False,
“class_filter”: [“yawn”, “open_eye”, “no_yawn”],
“confidence”: 0.5,
“fix_batch_size”: False,
“iou_threshold”: 0.5,
“max_detections”: 300,
“max_candidates”: 3000,
“visualization_labels”: False,
“visualization_stroke_width”: 1,
“visualize_predictions”: False
}
def draw_bounding_box(img, x, y, w, h, color, label, confidence):
img.draw_rectangle(x, y, w, h, color=color, thickness=2)
label_text = f"{label}: {confidence:.2f}"
img.draw_string(x, y - 10, label_text, color=color, scale=2)
while True:
clock.tick()
img = sensor.snapshot()
# Save the snapshot to a file
try:
img.save("/snapshot.jpg")
except OSError as e:
print("Error saving snapshot:", e)
# Send the image to Roboflow for inference
with open("/snapshot.jpg", "rb") as img_file:
try:
response = urequests.post(ROBOFLOW_URL, headers={"Content-Type": "application/json"}, json=roboflow_config)
if response.status_code == 200:
predictions = response.json().get('predictions', [])
for pred in predictions:
x, y, w, h = int(pred['x'] - pred['width'] / 2), int(pred['y'] - pred['height'] / 2), int(pred['width']), int(pred['height'])
draw_bounding_box(img, x, y, w, h, (255, 0, 0), pred['class'], pred['confidence'])
else:
print(f"Error: Inference request failed with status code {response.status_code}")
except OSError as e:
print("Error sending image to Roboflow:", e)
img.draw_string(10, 10, "Inference Active", color=(255, 0, 0))
# Print FPS for debugging purposes
print(clock.fps())
print("Image captured and processed")
try:
img.save("/annotated_snapshot.jpg")
except OSError as e:
print("Error saving annotated snapshot:", e)