Skip to content

Calibrate Camera for Distance

Claude Pageau edited this page Mar 19, 2018 · 64 revisions

Calibration Procedure

speed-cam.py needs to be calibrated in order to display a better speed result.

IMPORTANT: If you are using a plugin then the calibration settings will be in each plugin file. Make sure you change the plugin setting rather than the config.py settings.

Measure vehicle/object using a tape measure or reference make and model lengths here http://www.automobiledimension.com/

To Calibrate cal_obj_px and cal_obj_mm variables perform the following

  • Login to RPI using SSH or desktop terminal session and cd to speed-camera folder and run menubox.sh
  • Use menubox.sh to Run webserver and speed-cam.py as background tasks. NOTE PID (process ID) will be displayed when running.
  • Access speed camera webserver images from a web browser and adjust camera to point to the view to be monitored. Note you may need to vflip and/or hflip image by editing appropriate config.py setting. Then stop/start speed-cam.py using menubox.sh PID will be displayed when running.
  • Use menubox.sh to edit config.py variable calibrate = True. If required Adjust the y_upper and y_lower variables values to cover the road area. Note image 0,0 is the top left hand corner and values are in pixels. Do not exceed the CAMERA_HEIGHT value
  • In nano save changes ctl-x y to save
  • Use menubox.sh to stop then restart speed-cam.py so new settings will take effect. PID will be displayed when running.
  • Motion will automatically be tracked and calibration images will be put in media/images folder with prefix calib-
  • Use web browser to view images and monitor progress and calibration images.
  • Use menubox.sh to stop speed camera (No PID will be displayed).
  • From a web browser access webserver to View calibration images and use image hash marks to record cal_obj_px for vehicle/object length Note each division is 10 pixels.
  • Record cal_obj_mm length of the speed object above in millimeters. You should use several photos to confirm and average results.
  • Use menubox.sh to edit the config.py settings. Change values for variables cal_obj_px and cal_obj_mm to new values. Also change variable calibrate = False. and verbose = True. ctrl-x y to save nano changes.
  • Use menubox.sh to stop speed-cam.py. PID will NOT be displayed on menu.
  • Exit menubox.sh and start speed-cam.py from console. Monitor ./speed-cam.py console messages. Perform a test using a vehicle at a known speed to verify calibration.
  • Make sure y_upper and y_lower variables are correctly set for the area to monitor zone. This will restrict motion tracking to area between these variable values. Make sure top of vehicles/objects is included.

Please note that if road is too close and/or vehicles are moving too quickly then the camera may not capture motion and/or record vehicle in speed photo.

How to View Speed Data