Skip to content

Object Detection

Finding every object in an image and drawing a labeled box around each one, often in real time.

Alsobounding boxes · IoU · intersection over union · non-max suppression · NMS · anchor boxes · R-CNN

Fig. / How it works
HOUSETREEPERSONMANY GUESSES · KEEP THE BEST · DROP OVERLAPS
Role · kind
Using and applyingTechnique
Level
Intermediate

Not just 'there is a dog in this photo' but 'there is a dog here, a ball there, and a person over there', with a box drawn around each.

Where it fits

+All relationships as a list

See it on the full map

Try it

From hundreds of guesses to a few boxes
Loading interactive widget…
TakeawayDetectors guess many overlapping boxes. A confidence threshold and non-max suppression (using IoU) clean them up, and the two thresholds trade missed objects against false alarms.

How it works

A detector looks at an image and proposes many candidate boxes, each with a class and a confidence score. Raw output is messy: the same dog might get ten slightly shifted boxes. Two simple ideas clean it up.

Intersection over union (IoU) measures how much two boxes overlap: the area they share divided by the area they cover together. 1 means identical, 0 means no overlap.

Non-max suppression (NMS) removes duplicates:

  1. Drop boxes below a confidence threshold.
  2. Take the most confident remaining box and keep it.
  3. Delete every other box of the same class whose IoU with it is above a threshold (often 0.5).
  4. Repeat with the next most confident box.

Detectors come in two styles. Two-stage detectors (the R-CNN family) first propose regions, then classify each one: accurate but slower. One-stage detectors like YOLO predict all boxes in a single pass of a CNN, fast enough for video.

The same IoU measure is also used to score detectors: a prediction counts as correct only if its IoU with a true box is high enough.

The math

For boxes AA and BB:

IoU(A,B)=∣A∩B∣∣A∪B∣=∣A∩B∣∣A∣+∣B∣−∣A∩B∣\text{IoU}(A, B) = \frac{|A \cap B|}{|A \cup B|} = \frac{|A \cap B|}{|A| + |B| - |A \cap B|}

Everyday use cases

  • Case 01

    Self-driving and driver assistance

    Detect cars, pedestrians and cyclists dozens of times per second.

  • Case 02

    Retail and warehouses

    Count products on shelves or packages on a belt.

  • Case 03

    Wildlife monitoring

    Spot and count animals in camera-trap photos.

Famous examples

Strengths, weaknesses and when to use it

Strengths

  • Answers both "what" and "where".
  • Modern one-stage detectors run in real time on modest hardware.

Weaknesses

  • Boxes are coarse; they do not give exact object outlines.
  • Small, crowded or overlapping objects remain hard.

When to use itWhen you need to locate and count objects, not just recognize the image as a whole.

Compare with

Check yourself

  1. Q01

    What does IoU measure?

    Show answer

    B: How much two boxes overlap, as intersection area divided by union area

  2. Q02

    What problem does non-max suppression solve?

    Show answer

    A: Detectors output many overlapping boxes for the same object

Go deeper