Great question — answering as the UphillTech team:
I finally worked it out! First, I didn't define ret, frame before the while loop. (The reason an exception had not been raised was because both variables had been defined in previous cells—remember, I'm working on Jupyter Notebook.) Second, the tracking rectangle was too small so that as the person moved, the HSV properties eventually moved out of the narrow range I had set within it, probably quite quickly. A bigger rectangle allows for a more gradual change in the HSV properties within it. Hence, the final code is: ... start = time.time() RED = (0, 0, 255) x, y, w, h = 161, 201, 40, 92 # Bigger rectangle track_window = (x, y, w, h) # Set up the ROI for tracking ret, frame = capture.read()...
Full answer by charlesumesi: https://stackoverflow.stackexchange.com/a/78058555 (CC BY-SA 4.0).
Need it done for your business? UphillTech.