Detection zone moodel learning

Hi everyone,

I made a model in roboflow (Roboflow 3.0 model) to detect yellow goals, blue goals, and black walls, but when I tried to use the model with my phone the whole screen could detect the goals and walls. But when I put the model on my openMV N6 camera it only detected the goals and walls in a 400x400 square in the middle, I thought I fixed it by resizing the format in the pre-processing step to 640x480 and then making a new version of the model with the different format, but that didn’t do anything.

Here is my OpenMV code:

import csi
import time
import math
import ml
from ml.postprocessing.ultralytics import YoloV8
from machine import UART
import ustruct

# Initialize the sensor.
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.VGA)
csi0.window((640, 480)) #((0, 170, 640, 200))

# Initialize bus, baudrate
uart = UART(3, 115200)

clock = time.clock()


# Load YOLO V8 model.
model = ml.Model("/rom/openmv_goal-and-wall-detection_v3.bin",

    postprocess=YoloV8(threshold=0.4)
)

model.labels = ["Black wall", "blue-goal", "yellow-goal"]

# Colors
n = len(model.labels)
model_class_colors = [
    (int(255 * i // n), int(255 * (n - i - 1) // n), 255)
    for i in range(n)
]


while True:
    clock.tick()
    img = csi0.snapshot()

    boxes = model.predict([img])

    for i, class_detections in enumerate(boxes):
        rects = [r for r, score in class_detections]
        labels = [model.labels[i] for j in range(len(rects))]
        colors = [model_class_colors[i] for j in range(len(rects))]

        ml.utils.draw_predictions(img, rects, labels, colors, format=None)

        for (x, y, w, h), score in class_detections:
            center_x = math.floor(x + (w / 2))
            center_y = math.floor(y + (h / 2))

            rel_x = center_x - 320
            rel_y = 240 - center_y
            label = model.labels[i]

            # Draw red line (this is your “tangent visualization”)

            if label == "blue-goal" or label == "yellow-goal":
                img.draw_line((320, 240, center_x, center_y), color=(255, 0, 0), thickness=2)

            img.draw_circle((center_x, center_y, 5), color=(255, 255, 255))

Does anyone have an idea to make the camera detect goals and walls in the whole screen, instead of just the square in the middle?

Thank you very much!

Hi, with the latest dev release firmware just remove

csi0.window((640, 480)) #((0, 170, 640, 200))

E.g. See openmv/scripts/examples/03-Machine-Learning/00-TensorFlow/yolo_v8_detector.py at master · openmv/openmv · GitHub

Hi,

Thank you for answering so fast!

I downloaded the latest firmware (4.8.10) and removed the line of code, but it still only detected the middle square. I also tried the example code with our camera, but still, only the middle square.

Do you have any idea what the problem could be?

Thanks!

Hi, it’s because you are using the non-v5.0.0 firmware which forces the center to be a square.

Please install the latest IDE from here: Release Development Release · openmv/openmv-ide · GitHub

Any non factory IDE version. Then, click the Tools->Install the Latest Development firmware to get the pre-release v5.0.0 firmware. The examples have change around since v4.8.1 so you will need to pull them from here: openmv/scripts/examples at master · openmv/openmv · GitHub

I will have another release of the IDE next week that resolves the versioning issues and has the examples in sync with the firmware.