pageauc / speed-camera

A Unix, Windows, Raspberry Pi Object Speed Camera using python, opencv, video streaming, motion tracking. Includes a Standalone Web Server Interface, Image Search using opencv template match and a whiptail Admin Menu Interface Includes picam and webcam Plugins for motion track security camera configuration including rclone sync script. watch-app allows remotely controller camera configuration from a remote storage service name. Uses sqlite3 and gnuplot for reporting. Recently added openalpr license plate reader support.
Apache License 2.0
960 stars 169 forks source link

double frame read #134

Closed carterw closed 1 year ago

carterw commented 1 year ago

It looks like two image frames are being acquired for every cycle through the scanning loop and the first one is not used.

On line 1326 there is the scanning loop; while still_scanning: # process camera thread images and calculate speed

Then there's a frame read; image2 = vs.read() # Read image data from video steam thread instance And then speed_get_contours() is called, passing in the frame that was read; grayimage1, contours = speed_get_contours(image2, grayimage1)

But then speed_get_contours() ignores the frame that was passed in and does another read in the while not image_ok: loop.

Was this intentional? It seems like that second frame read could be eliminated.

pageauc commented 1 year ago

function def speed_get_contours(image, grayimage1):

Does the contour processing. It receives the current frame image and converts it to grayscale and compares it to previous grayscale array to calculate contours. When finished the previous grayscale array is updated to the most recent grayscale line 1218, that is returned by the function ready for the next loop. This is done to reduce processing and is by design.

Anyone can send changes via github push for review if they have an improved method.

Claude

On Tue, Aug 1, 2023 at 3:28 PM Bill Carter @.***> wrote:

It looks like two image frames are being acquired for every cycle through the scanning loop and the first one is not used.

On line 1326 there is the scanning loop; while still_scanning: # process camera thread images and calculate speed

Then there's a frame read; image2 = vs.read() # Read image data from video steam thread instance And then speed_get_contours() is called, passing in the frame that was read; grayimage1, contours = speed_get_contours(image2, grayimage1)

But then speed_get_contours() ignores the frame that was passed in and does another read in the while not image_ok: loop.

Was this intentional? It seems like that second frame read could be eliminated.

— Reply to this email directly, view it on GitHub https://github.com/pageauc/speed-camera/issues/134, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABNPKZEUF4XSCYECYDROSNLXTFKHDANCNFSM6AAAAAA3AHGUJY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

-- YouTube Channel at https://www.youtube.com/user/pageaucp http://www.youtube.com/user/pageaucp GitHub Repository at https://github.com/pageauc

carterw commented 1 year ago

Yes I understand what the method does. I was pointing out that speed_get_contours() ignores the incoming frame and performs a second frame read in a loop before a crop is attempted. Maybe the vs.read() could be moved to the bottom of that loop? But if you are happy with it as-is that's fine with me.

pageauc commented 1 year ago

Thanks for your correct explanation. See speed-cam.py ver 12.01 for updated logic Claude ...

carterw commented 1 year ago

Thanks for the helpful fix!

pageauc commented 1 year ago

Note 12.02 replaces np.std with np.median for calculating ave speed.

Speed camera is written as an object tracker. I will look at adding an option to use vehicle recognition (opencv haarcascade) that can improve speed calculation.

Claude.