-
Notifications
You must be signed in to change notification settings - Fork 172
How to Run speed search.py
Search for similar moving objects using opencv template matching
- Introduction
- Run from SSH or Terminal Session
- Display opencv windows on GUI Desktop
- How to Change Settings
Occasionally you may want to track a particular vehicle/object. It can be difficult going through thousands of images. I wrote this utility to allow searching for similar images that can reduce the total number of files to review. It is not perfect but can be useful. I find it works reasonably well with white vehicles but others not as reliably.
-
Use menubox.sh SEARCH menu pick then SELECT menu pick to copy one or more speed image(s) from media/images to the default search folder media/search. Make sure an up-to-date speed-cam.csv file is available.
-
From SSH or terminal session, Run commands below. search-speed.py will read each /media/search speed image file(s) and perform a search against all images in the media/images folder
cd ~/speed-camera
./search-speed.py -
If the config.py variable copy_results_on=True then image match files including the original search file are copied to a subfolder with the same name as the search image filename but without the file extension. If copy_results_on=False then search is performed but no copying occurs and search image remains in media/search folder. This is useful for testing various search settings to optimize search result matches prior to copying.
-
Results can be reviewed from a web browser by running webserver.py and accessing link for search/subfolder
If you want to view Target and Searching image results directly as speed-search.py is running then.
-
Edit config.py using menubox.sh or nano and set
cd ~/speed-camera
nano search_config.py
In nano edit the variable below then ctrl-x y to save changes (you can also edit variable using menubox.sh)
gui_window_on = True
-
Access the computer desktop session via monitor/TV (make sure a keyboard and mouse are attached) or access via VNC remote session
-
Make sure there are search images in media/search folder
-
From the RPI gui desktop open a terminal session then
cd ~/speed-camera
./search-speed.py -
search-speed will open and display Target and Searching opencv windows showing the images being searched. When a MATCH is found the match image will be momentarily displayed for 4 seconds (hard coded in search-speed.py). The terminal window will also text display progress.
-
Use a mouse to rearrange opencv desktop windows for better viewing
You can change search settings by editing the config.py file directly using nano or use the menu driven menubox.sh bash script. The relevant search variables are listed below.
If you get a lot of results for a search, then review the output and try increasing the search_match_value variable eg 0.98 or more. This should reduce the number of results but may also eliminate some positive matches as well. A little bit of trial and error can be used. If testing, it is recommended that you set variable
search_copy_on=False
so you can repeat search without having to recopy image file to media/search folder again and/or delete the specific media/search/subfolder. Once you are happy set search_config.py variable
search_copy_on=True
The results images will then be copied to a media/search subfolder for review.
search_verbose = True # Display basic status information on console
search_log_to_file = False # True = Send logging to file (not implemented yet)
search_logfile_path = 'speed-search.log' # Location of log file when search_log_to_file=True
search_gui_on = False # True = Turn On All desktop GUI openCV windows. False=Don't Show (req'd for SSH) .
search_match_value = 0.97 # Default = 0.97 Accuracy setting for Image Searches 0=Lowest 1=Highest
search_source_images_path = "media/images" # Source images folder
search_copy_on = True # Copy matching image files to search_path subfolder (based on search filename minus ext)
search_dest_path = 'media/search' # Destination for Result images if search_copy_on = True
search_using_csv = True # False= Use glob True= Use csv file for source file names
search_csv_path = 'speed-cam.csv' #
search_data_on_image = True # default=True show match_value on result images
search_match_method = 3 # Default=3 Valid MatchTemplate COMPARE_METHOD Int Values
# 0 = cv2.TM_SQDIFF
# 1 = cv2.TM_SQDIFF_NORMED
# 2 = cv2.TM_CCORR
# 3 = cv2.TM_CCORR_NORMED Default
# 4 = cv2.TM_CCOEFF
# 5 = cv2.TM_CCOEFF_NORMED
# For comparison methods details
# see http://docs.opencv.org/3.1.0/d4/dc6/tutorial_py_template_matching.html
For details on MATCH_METHOD see http://docs.opencv.org/3.1.0/d4/dc6/tutorial_py_template_matching.html
(Note: search-speed.py is still under development)
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