I'm trying to write a python program which reads frames in jpg format in real time using the imread() function.
The program work fines in pycharm but it suddenly stops working after around 3000-6000 iterations (it depends) if the program is packaged using pyinstaller on Windows.
I have tried to use cv2.VideoCapture(f"{src}/%d.jpg", cv2.CAP_IMAGES)
but still the problem exists.
Below is part of the code using imread() inside frames reading function, which is run on a thread.
while not self.isStopTask:
print("Debug - 1",flush=True)
imgpath = abspath( join(self.src,str(CurrFrameNum)+".jpg"))
print("Debug - 2",flush=True)
frame = cv2.imread(imgpath)
print("Debug - 3",flush=True)
if frame is None:
print("Debug - cv2.imread() failed. frameNum =", str(CurrFrameNum), flush=True)
time.sleep(0.1)
else:
...
It is noticed that the thread stop execution after running print("Debug - 2",flush=True). I guess opencv has raise an error which causes the thread to die.
So I have also checked if the thread is alive or not in a separate thread. It is noticed that the thread is still alive even the execution stopped as above. Therefore, I guess there is some problem with imread() that it causes the thread stop working and stuck without raising any errors.
I have tried to upgrade and downgrade both pyinstaller and opencv but the problem still cannot be resolved.
Does anyone know what's happening and how to fix it?
Thank you so much!