start_cam
reopening the same camera doesn’t in itself fix any blur. at best it wastes time until the camera’s servo auto-focus has found what it wants to focus on. you might as well keep the VideoCapture open, read and check frames, and do that until you’re satisfied with the focus
waitKey
to delay reading from the camera
bad idea. frames will be produced regardless. they’ll just queue up, so you aren’t getting a frame from a second later, but from one frame later (something around 16-40 milliseconds later).
messing with gc
I highly doubt that’s required to keep anything working. I have never in more than a decade experienced any issues with python that would require this, or where this would actually do anything noticeable. unless that provably does anything useful here, I’d call it superstition.
calling namedwindow/imshow/waitkey from a thread
that can be a bad idea. it may work, or it may cause trouble. depends on the GUI backend (win32/Qt/GTK/…). I haven’t had heisenbug issues with the win32 backend. either it works, or it fails noticeably (can’t remember if I had that problem).
it might be possible to run this, whatever it is, without threads entirely. that depends on what data_operation
is specifically… because that there is an obvious placeholder. whatever code is really there might actually be at fault.
anyway, it should certainly be possible to keep all the imshow/waitkey stuff in the main loop.
worth a try to leave imshow/waitkey out entirely, and see if that changes the behavior. you won’t see anything, but it’s an experiment.
code style
calling a class operator
, I find that misleading. first, the convention is to capitalize types/classes. second, the word “operator” usually refers to something like addition. what you do here is a container that holds a VideoCapture and a frame. call it a “capture thread” or whatever.
maybe consider deriving from threading.Thread (reimplement the run
method, which is just the function that gets executed in the thread) or keep the code as is, with an instantiation of a threading.Thread given a target
argument