520 Rate Checking#

GitHub

Introduction#

This script uses the Google Cloud Vision API to extract text information from images. It was used in conjunction with WSDOT’s traffic cameras to capture images of SR 520 toll rate signs, process the images into text information, and compare the expected toll rates to those posted by the tolling vendor.

While the script was specifically designed for the SR 520 bridge toll rates, it can be adjusted to analyze the results of any toll system. All results are logged in a file with the naming convention yyyymmdd_hhmmss_vision_process.log. This log file can be reviewed to verify the accuracy of the posted toll rates.

Installation#

Running the script requires installing the Google Cloud SDK. It also requires access to the Google Cloud Vision API. The easiest way to enable access is to create a cloud project, add an access account, and download the JSON API key so that the script can be run locally.

Execution#

The results will be best during the day and when the traffic cameras are centered on the signs. The URLs should be modified based on the cameras used. It can be done by modifying the following lines of code:

# default configuration
urls['east'][0] = 'https://images.wsdot.wa.gov/nw/520vc00414.jpg'
urls['west'][0] = 'https://images.wsdot.wa.gov/nw/520vc00430.jpg'

# new configuration
urls['east'][0] = 'new_east_camera_url'
urls['west'][0] = 'new_west_camera_url'

The script has been set up to end at a user-determined time so that API calls do not run indefinitely and results can be analyzed and summarized. Please adjust the end date before running the script.

end_time = datetime.datetime(end_year, end_month, end_day)
image_download_interval_secs = [analysis_interval]

Running the script#

It is important to import the environment variable for the Google cloud API JSON key before running the script, otherwise an exception will be raised.

python check_web_images.py

Pricing#

At the time the script was developed, the pricing for the API calls was affordable. The first 1k requests are free, the next 1k-5M requests are $1.50/1,000 requests. So if requests are made every 5 minutes for a week, this amounts to around $3.00 - for around 2,000 requests.