Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to initialize the OpenCV tracker.
Computer Vision
tracker = cv2.TrackerCSRT_create() # Create CSRT tracker success, frame = video.read() bbox = cv2.selectROI(frame, False) tracker = cv2.TrackerCSRT_create() tracker.init(frame, [1])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the whole frame instead of the bounding box to tracker.init()
Using video or success variables instead of bbox
✗ Incorrect
The tracker needs the bounding box (bbox) to know what object to track in the initial frame.
2fill in blank
mediumComplete the code to update the tracker and get the new bounding box.
Computer Vision
success, frame = video.read() success, [1] = tracker.update(frame) if success: p1 = (int(bbox[0]), int(bbox[1])) p2 = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3])) cv2.rectangle(frame, p1, p2, (255,0,0), 2, 1)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using frame instead of bbox to store the updated location
Confusing success with bbox in the assignment
✗ Incorrect
The tracker.update() returns success and the new bounding box (bbox) for the tracked object.
3fill in blank
hardFix the error in the code to correctly select the ROI for tracking.
Computer Vision
frame = video.read()[1] bbox = cv2.selectROI([1], False)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the video capture object instead of the frame image
Passing the tracker object instead of the frame
✗ Incorrect
cv2.selectROI requires the current frame image to select the region of interest (ROI).
4fill in blank
hardFill both blanks to create a dictionary of trackers and update each one.
Computer Vision
trackers = {}
trackers['car'] = cv2.TrackerKCF_create()
trackers['car'].init(frame, bbox_car)
trackers['person'] = cv2.TrackerMIL_create()
trackers['person'].init(frame, bbox_person)
for name, tracker in trackers.items():
success, [1] = tracker.update(frame)
if success:
p1 = (int([2][0]), int([2][1])) Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using bbox_car or bbox_person inside the loop instead of the updated bbox
Using frame instead of bbox for the bounding box variable
✗ Incorrect
The update returns the new bounding box which should be stored in bbox to draw the rectangle.
5fill in blank
hardFill all three blanks to create a dictionary comprehension that tracks objects with bounding boxes larger than 5000 pixels.
Computer Vision
large_objects = {name: bbox for name, bbox in object_bboxes.items() if ([1] * [2]) [3] 5000} Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using x or y instead of width and height for area calculation
Using less than instead of greater than for filtering
✗ Incorrect
The width (bbox[2]) times height (bbox[3]) gives the area. We filter for area greater than 5000.