Colour Coding

Hue-Saturation-Value (HSV)

Hans Georg Schaathun

NTNU, Noregs Teknisk-Naturvitskaplege Universitet

September 2023

RGB (Red/Green/Blue)

By SharkD - Own work Source-code available at the POV-Ray Object Collection., CC BY-SA 4.0

0% green

50% green

100% green

HSV (Hue/Saturation/Value)

Aka. HSB (Hue/Saturation/Brightness)

By Wapcaplet - From en wiki, CC BY-SA 3.0

Value is 100%.

Saturation is 100%.

  • RGB $$\vec{c} \in [0,1]^3\subset\mathbb{R}^3$$
  • HSV $$\vec{c}' \in \frac{\mathbb{R}}{2\pi}\times[0,1]^2 \subset\frac{\mathbb{R}}{2\pi}\times\mathbb{R}^2$$
  • Conversion in OpenCV

    hsv_img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2HSV)

  • google for formulæ
    • straight-forward but quite a few step
    • absolute values make it non-linear

Colour Detection

  • Detect, say, yellow
  • Hue in $[55,63]$
  • Saturation $>50$ (otherwise white)
  • Value $>50$ (otherwise black)
  • NB Judgement call.

Detect Coloured Areas

  1. Find pixels
  2. Connect coloured areas using Connected Components

Project tracker

  1. Set up a moving scene with a moving object
    • No constraints, but keep it simple for your own sake
    • Brightly coloured box sent sliding across a smooth table
  2. Record a video using your own camera
  3. Program a prototype to
    • Locate the object in a single frame
    • Track the object from one frame to the next
  4. To make a robust solution it is wise to combine techniques
    • Detect brightly coloured faces
    • Detect corners - are they adjacent to the face?
    • Track features differentially (potentially high precision)
    • Redect features in new frame and match with SIFT. Do you find the features where they should be?