Challenge making inferences on openmV IDE using api key and model iD

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)

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…”)

print(“Connected to Wi-Fi”)
print(nic.ifconfig()) # Print the IP address, subnet mask, gateway, and DNS

Initialize the camera sensor


clock = time.clock()

Roboflow API details

MODEL_ID = “drive-drowsiness-detection/2”
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:
img = sensor.snapshot()

# Save the snapshot to a file
except OSError as e:
    print("Error saving snapshot:", e)

# Send the image to Roboflow for inference
with open("/snapshot.jpg", "rb") as img_file:
        response =, 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'])
            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("Image captured and processed")

except OSError as e:
    print("Error saving annotated snapshot:", e)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.