I have a program that uses OpenCV to detect a passing train and its direction. I tweet an alert so subscribers know a train is coming - and I include a picture of the train as a reply to the initial tweet. This has been running fine for a couple of years. (Freight trains are very disruptive in the town where I live.)
I want to get a “better” train image to tweet - which means I need to wait a few seconds after the train is detected - to enable more of the train to enter the frame.
After the train detection logic I have the following code:
ret, pic1 = cap.read() pic1_cropped = pic1[picy:picy + picyheight, picx:picx + picxwidth] cv2.imwrite("C:\\TrainAlertImages\\Pic1.jpg", pic1_cropped) print("Time before sleep: %s" % time.ctime()) if direction == "SOUTHBOUND": time.sleep(2) else: time.sleep(15) print("Time after sleep: %s" % time.ctime()) ret, pic2 = cap.read() pic2_cropped = pic2[picy:picy + picyheight, picx:picx + picxwidth] cv2.imwrite("C:\\TrainAlertImages\\Pic2.jpg", pic2_cropped)
Both Pic1 and Pic2 are exactly the same. The sleep function appears to be working correctly based on the output in the log file from the print statements.
The camera is an Amcrest bullet camera. No apparent issues with it. It can deliver images to my code quickly. During the detection process I’m grabbing about 10 frames/second.
I don’t understand how the same image is getting written to different files after a 15 second delay. (‘direction’ == NORTHBOUND in the test).
P.S.: I tried posting both pics (they’re identical) but this forum will only let a new user post one media object.