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
Steps
- Open the camera using cv2.VideoCapture()
- Create 3 Trackbars of H, S, and I using cv2.createTrackbar()
- Read frame by frame
- Record the current trackbar position using cv2.getTrackbarPos()
- Convert from BGR to HSV using cv2.cvtColor()
- Threshold the HSV image based on current trackbar position using cv2.inRange()
- Extract the desired result
Code
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.