OpenCV python cv2.putText function doesn't work well due to high-speed computing

Hi, friend!

I have trained a human activity recognition model and implemented for a real-time applications. For each frame, there could be multiple humans. When I loop through each human and get the action label, I want to use cv2.putText() function to attach the label along with each human. However, I find that it only “works well” for the last human. When I used waitkey function, I can see the labels are flicking for other humans. Since this is a real-time application, using waitkey() is not a ideal solution.

Do you have better idea?

 for i, track_id in enumerate(track_ids):
    annotated_frame = cv2.putText(annotated_frame, human_action[track_id], (bbox[0] + 5, 
    bbox[1] + 15), cv2.FONT_HERSHEY_COMPLEX, 1, clr, 2)

you have to use pollKey each time you call putText

that is incorrect.

putText is purely drawing into a Mat/np.array. waitKey() has no effect on this.

OP’s code shows no actual imshow() calls. that is where GUI event processing has any effect at all.

last I checked, that only actually spares you from sleeping a nominal amount (winapi Sleep(1)) on win32. on all other GUI toolkits, it’s implemented as waitKey(1) as a placeholder for whoever cares enough to implement it properly for whatever respective GUI toolkit. I know because I introduced pollKey() :wink:

that little bit of GUI event processing and sleep shouldn’t affect “realtime” all that much.

OP’s problem is likely in the code they wrote and haven’t shown us.