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. See Accuracy Issues for factors that can affect speed results.

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 putty SSH or desktop terminal session and cd to speed-camera folder and run menubox.sh
  • Use menubox.sh to Run webserver (record browser url) and speed-cam.py as background tasks. NOTE PID (process ID) will be displayed when running.
  • Access URL for speed camera webserver using a network computer web browser. View speed images and adjust camera to point to the view to be monitored (you may need to manually trigger motion). 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 calibration images as motion tracking is triggered. Refresh Web Browser to update display. You can also view the CSV data details using menubox.sh
  • 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 by measurement or lookup value. You should use several images to confirm and average results in both directions. You may want to test using your own vehicle and logging actual speed and time for each run. You can then measure your vehicles actual mm length. Note you may have to manually adjust config.py cal_obj_mm value higher or lower to correspond with actual speeds recorded, since motion tracking is based on opencv contour width and may have discrepancies. This may require several tries to get the best accuracy. See Accuracy Issues for More Details
  • 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