Object Tracking Using Color Models OpenCV-Python

In this tutorial, we will learn how we can use color models for object tracking. You can use any color model. Here, I have used HSI because it is easier to represent a color using the HSI model (as it separates the color component from greyscale). Let’s see how to do this


  1. Open the camera using cv2.VideoCapture()
  2. Create 3 Trackbars of H, S, and I using cv2.createTrackbar()
  3. Read frame by frame
  4. Record the current trackbar position using cv2.getTrackbarPos()
  5. Convert from BGR to HSV using cv2.cvtColor()
  6. Threshold the HSV image based on current trackbar position using cv2.inRange()
  7. Extract the desired result


Open in full screen and play with trackbar to get more intuition about HSI model. Hope you enjoy reading.

If you have any doubt/suggestion please feel free to ask and I will do my best to help or improve myself. Good-bye until next time.

Leave a Reply