Skip to content
BoKSA

Object Detection

Object Detection

Introduction

A camera gives you pixels. A robot needs to know which objects are in the frame, where they are, and how sure the result is. Object detection is the step that turns an image into that list.

Classification, detection, and segmentation answer three different questions. Mixing them up leads to a program that says "there is a cup" when the arm needed a box around the cup. This page is those three outputs, plus the bounding box and the confidence score you use before you move anything. How the box becomes a robot motion is in Vision-guided robotics.


Three questions, three outputs

Task Question What you get
Classification What is this image, overall? One class label
Detection Which objects are where? A class and a bounding box for each object
Segmentation Which pixels belong to the object? A class and a mask of pixels
1
2
3
4
5
6
7
Classification     Detection                 Segmentation
+------------+     +------------+             +------------+
|   [cup]    |     |  +------+  |             |   ████     |
|            |     |  | cup  |  |             |  ██████    |
+------------+     |  +------+  |             |   ████     |
 "cup"             +------------+             +------------+
                   cup @ box                  cup pixels

Classification is enough for "is the bin empty?". Detection is what you want for "pick the cup, not the background". Segmentation is what you want when the outline matters: a grasp between two touching parts, or a scratch that is not a rectangle.

In plain terms

Classification names the photo. Detection puts a sticky note on each thing in the photo. Segmentation colours in the thing pixel by pixel.


The bounding box

A bounding box is an axis-aligned rectangle around one object. Two common ways to write it:

Form Numbers
Corner and size x, y, width, height
Two corners x_min, y_min, x_max, y_max

x and y are in image pixels, usually from the top-left of the frame. They are not millimetres in the robot's base until you calibrate. That conversion is part of Vision-guided robotics.

A detector can return several boxes in one frame: a cup, a hand, a second cup. Each box has its own class. Your firmware or vision node then chooses which box the task wants (the nearest cup, the only red part, the highest box).

On a small controller you might store one detection like this:

1
2
3
4
5
6
7
8
typedef struct {
    uint16_t x;
    uint16_t y;
    uint16_t width;
    uint16_t height;
    uint8_t class_id;
    uint8_t confidence; /* 0..100 */
} detection_t;

The struct is the contract between the vision step and the motion step. Agree the units (pixels, percent) in the same place you document the message.


Confidence

Confidence is the detector's score for "this box really is that class", often a number from 0 to 1 (or 0 to 100). A box with confidence 0.93 is a strong guess. A box with 0.40 is a weak one.

You set a threshold for the task. Boxes below the threshold are dropped. A higher threshold means fewer false objects and more missed objects. A lower threshold does the opposite. There is no universal cutoff: a demo that only needs "something moved" can sit lower than a pick that must not grab the table.

Score behaviour What you see
Threshold too low Extra boxes on shadows, reflections, background clutter
Threshold too high The part is in frame and the list stays empty
Two boxes on one part Overlap; keep the higher score or merge them

Confidence is not a distance and not a probability you can spend in a safety case without reading how that detector was trained and tested. Treat it as a filter on the list you are willing to act on.


Where detection sits

1
2
3
4
5
6
camera frame
    →  detection
    →  boxes with class and confidence
    →  choose one box
    →  pixels to robot coordinates
    →  motion

Before this step you may clean the image (Edge detection, Blob detection). A blob finder is enough when the part is just "the bright region". A detector is what you use when the region must be a named object: cup, person, box, tool.

Lighting, focus, and a background that looks like the part change the boxes more than a small tweak to the threshold. If the same object jumps class between two frames, fix the image first.


Relevant topics


Starting points

  1. Label three photos from a studio setup as classification, detection, or segmentation, and write the output each one needs (a word, a box, or a mask).
  2. Draw two bounding boxes on one image and write them as x, y, width, height in pixels from the top-left.
  3. Pick a confidence threshold for a pick task and say which error you would rather have: an extra box, or a missed part.
  4. List the fields a detection message must carry before a robot node is allowed to move.

Focus points

  • Name the task. A class label does not give you a place to move. A box does not give you a pixel-perfect outline.
  • Pixels stay pixels until calibration. Do not send x from the image to a joint solver as if it were millimetres.
  • Threshold on purpose. Write the cutoff down with the demo so the next person can reproduce the same boxes.
  • Several boxes are normal. Decide which one the task uses before you command motion.
  • Light and background move the result as much as the model does.

Key points

  • Classification labels the image. Detection adds a bounding box per object. Segmentation labels pixels.
  • A bounding box is a rectangle in image pixels, stored as origin plus size or as two corners.
  • Confidence ranks a box. A threshold drops weak boxes and trades misses against false objects.
  • Detection feeds vision-guided motion only after you choose a box and convert pixels to the robot frame.