-
Notifications
You must be signed in to change notification settings - Fork 174
Calibrate Camera for Distance
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 ~/speed-camera folder then run ./menubox.sh
- Use menubox.sh to START webserver.py (record browser url) and speed-cam.py as background tasks. PID (process ID) will be displayed when running.
- Access URL for speed camera webserver using a network computer web browser. Wait for a motion tracking event or manually tigger, then View speed images and adjust camera to point to the view to be monitored.
- Use menubox.sh to edit config.py variable calibrate = True and optionally align_cam_on = True (default delay is 5 seconds between forced images".
- If required adjust the required x_left, x_right, y_upper, y_lower variable values to cover the road area of interest. Note image 0,0 is the top left hand corner and values are in pixels. Do not exceed the CAMERA_HEIGHT value. You may also need to vflip and/or hflip image by editing appropriate config.py setting.
- In nano press ctl-x y to save changes and exit.
- Use menubox.sh to STOP/START speed-cam.py so new settings will take effect. PID will be displayed when running.
- align_cam_on and/or motion tracking will automatically create calibration images and save in media/images folder with prefix calib-
- Adjust camera pointing as required. This can be done easily using the config.sys align_cam_on = True variable setting that will take continuous images (until deactivated)
- Use web browser to view calibration images. Refresh Web Browser to update display. You can also view the CSV data details using menubox.sh
- Use menubox.sh to STOP speed-cam.py (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 desired vehicle/object length. This can be a known length object or known vehicle length at the correct distance for L2R or R2L directions. Note each hash mark division is 10 pixels.
- Record cal_obj_mm_L2R and cal_obj_mm_R2L lengths of the object above images 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 Run ./speed-cam.py from console. Monitor ./speed-cam.py console messages. Perform a test in both directions 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 be monitored including large vehicles/objects. This will restrict motion tracking to area between these variable values.
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.
Wiki Home
Description, Issues, Features
How to Install or Upgrade
How to Run
How to Calibrate
Change Settings and Plugins
How to Tune Motion Tracking
Setup RTSP Camera
rclone Remote Storage File Transfer
How to View Speed Data
How to Generate Graphs
How to Run speed-search.py
How to Start on Boot
How to use run.sh
watch-app.sh Remote config
How to Manage Sqlite3 Database
How to move speed-camera to ext drive
How to use OPENALPR with speed camera
Github Repo