CSRT(Discriminative Correlation Filter with Channel and Spatial Reliability)
Runs at a lower speed, but the quality is higher.
How CSRT Works?
- Step 1 (Training patch)
Select the object we want to track as you can see in the image below. It is related to the information selected from the image about the pixels of the object.
- Step 2 (Spatial prior)
Extract useful information from the image using HOG, as you can see in the image below.
- Step 3 (Backprojection)
Apply a Random Markov Test to generate probabilities. As you can see in the image below, we have the same shape as the original image, as if it were the person’s next movement.
In short, probabilities are generated to indicate the person’s movement and keep tracking the objects.
- Step 4 (Posterior)
Mask the training patch using the confidence map. As you can see in the image below, We have only the object with a mask.
- Step 5 (Overlayed patched)
We have the complete object to be tracked, as shown in the image below.
Example Code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
tracker = cv2.TrackerCSRT_create()
video = cv2.VideoCapture('race.mp4')
ok, frame = video.read()
bbox = cv2.selectROI(frame)
ok = tracker.init(frame, bbox)
# Accessing frame by frame
while True:
ok, frame = video.read()
if not ok:
break
ok, bbox = tracker.update(frame)
if ok:
(x, y, w, h) = [int(v) for v in bbox]
cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 255), 2, 1)
else:
cv2.putText(frame, 'Error', (100, 80), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
cv2.imshow('Tracking', frame)
if cv2.waitKey(1) & 0XFF == 27:
break
Result
As in KCF, a window named ROI selector will appear after existing code above.
In the window, select the object you want to track using the mouse, as shown in the image below.
After selecting the object to be tracked, a screen like the one below will appear.
As you can see in the GIF above, CSRT is slower than KCF because the mathematical background of CSRT is much deeper than that of KCF. Although CSRT is slow, it uses many other techniques like the random mark of probabilities and HOG.