To search
You are here : Linux > Linux > Science and Engineering > Python Traffic Camera Analyzer

Python Traffic Camera Analyzer

Freedownload8 rating:
License:
GPL (GNU General Public License)
Added:
Nov 30, -1
Submit date:
Feb 15, 2015
Publisher:
Pedram Amini
File size:
Downloads:
273
 

Python Traffic Camera Analyzer

by Pedram Amini

Python Traffic Analyzer is a Python base class and sample driver script written to retrieve and manipulate images from the TrafficLand cameras and calculate a numeric value representing the current traffic flow.PyTrAn, an example driver script, an image collector and an image mask creator are available for download from the link shown at the bottom. To use the PyTrAn package begin by choosing a camera that you wish to analyze, for this example we'll use the camera captioned above.We want to construct a mask over the area of the image that we are interested in, namely the road. In this particular example the road takes up the majority of the image but that is not always the case.We will apply the mask over captured images to fine tune the area over which we are looking for movement. To create the mask we will first need to collect a sequential series of snapshots from the target camera. The image_collector.py script was written for this task:$ mkdir mask_200003$ cd mask_200003$ ../image_collector.py 200003 30Collecting 30 images...30Done.The script is hard coded to capture images on a 2-second delay. The delay is necessary to ensure the image has changed. I believe 2-seconds to be the absolute minimum. Once complete, 30 images numbered 1 through 30 will be created in the current directory.We construct a mask from these captured images by creating a diff-image for each sequential image pair and then adding each diff-image together. Naturally, a script was written to automate this task as well:$ ../mask_maker.py 1 30Creating a diff for each sequential image pair.Diffing 29Creating the initial mask from the first image pair.Adding the rest of the diffs to the mask.Masking 29Done.A number of .diff files are generated in this process. These files repesent the movement between individual sequence pairs.The .diff files are simply intermediary files, the important bit is the 'mask' file, which is generated as the sum of all differences.The mask file may be dirty (as in this case) and require manual cleanup. The basic shape of the road however is clearly visible, evidence that we can with minimal effort automate the mask generation process. Also, this run was conducted at night, day-time images yield better results.There are a few final steps we need to take before we can use the example PyTrAn driver script. First we need to convert the mask to ASCII (noraw) format:$ pnmnoraw mask > mask_200003.asciiThen we need to open an ImageMagick 'display' window and get it's X-window-ID using 'xwininfo'. Finally, update 'camera_id' and 'window_id' in pytran_sampling.py and launch the driver:$ ../pytran_sampling.py DEBUG> grabbing frame from camera 200003DEBUG> rotating image: pytran.this > pytran.lastDEBUG> refreshing image in 3 secstaking a 5 minute sample at various thresholds.DEBUG> grabbing frame from camera 200003DEBUG> generating frame diff on pytran.last, pytran.thisDEBUG> displaying image: pytran.diffDEBUG> converting pytran.diff to asciiDEBUG> calculating traffic ratio...ratio[5]: 55%DEBUG> calculating traffic ratio...ratio[10]: 52%......5 minute sample[5]:67.885 minute sample[10]: 42.665 minute sample[15]: 30.575 minute sample[20]: 23.035 minute sample[25]: 18.395 minute sample[30]: 14.795 minute sample[35]: 12.425 minute sample[40]: 10.535 minute sample[45]: 9.065 minute sample[50]: 7.85The sampling script will take 5 minute samples at varying color thresholds. The optimal threshold must be manually chosen. Furthermore, you will need to sample the traffic ratio's during both heavy and light traffic times to get a good feel for your acceptable range. Also, keep in mind that the traffic ratio value is simply the percent change detected, or in other words the movement detected within the masked region. This means that a completely empty road will register similar values to a road so congested it looks like a parking lot. The time of day can be combined with the traffic ration to determine the logical truth.With this task implemented and abstracted more complex systems can be built. When I find the time I'd like to create a system that will take multiple potential travel routes and times, and during the travel time e-mail the traveler with the best route to take. Another idea I had would be to record the traffic flow values for each camera, for each day and for each half hour interval. Travelers and other interested parties can then analyze traffic patterns to determine the fastest route dependant on date/time.

Languages:

OS requirements for Python Traffic Camera Analyzer:

  • Download Python Traffic Camera Analyzer

User comments about Python Traffic Camera Analyzer

Comment Python Traffic Camera Analyzer

  1. What did you think of the program?

    Log in or Create Account to post a comment.
         
    *
    *
  2. Rate this software    
  1. Security Code: Captcha Image Change Image

Get Our News, Everywhere

Popular searches

Linux

Science and Engineering