Skip to content

How to Run speed search.py

Claude Pageau edited this page Jul 27, 2017 · 36 revisions

How to Run speed-search.py

Introduction

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.

How To Run

Run from SSH or Terminal Session

  1. Copy one or more speed image(s) from media/images to the default search folder media/search

  2. From SSH or terminal session, Run commands below. speed-search.py will read each /media/search speed image file(s) and perform a search against all images in the media/images folder

    cd ~/rpi-speed-camera
    ./speed-search.py

  3. 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 allowing optimizing the result matches.

  4. Results can be reviewed from a web browser by running webserver.py and accessing link for search/subfolder

Display opencv windows on GUI Desktop

If you want to view Target and Searching image results directly as speed-search.py is running then.

  1. Edit config.py using menubox.sh or nano and set

    cd ~/rpi-speed-camera
    nano 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
  1. Access the RPI desktop session via HDMI monitor/TV (make sure a keyboard and mouse are attached) or access via VNC remote session

  2. Make sure there are search images in media/search folder

  3. From the RPI gui desktop open a terminal session then

    cd ~/rpi-speed-camera
    ./speed-search.py

  4. speed-search 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 speed-search.py). The terminal window will also text display progress.

  5. Use a mouse to rearrange opencv desktop windows for better viewing

How to Change Settings

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_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

copy_results_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 config.py variable

copy_results_on=True

The results images will then be copied to a media/search subfolder for review.

search_value = 0.97           # Default = 0.97 Accuracy setting for Image Searches 0=Lowest .99=Highest
copy_results_on = True        # Copy matching image files to search_path subfolder (based on search filename minus ext)
search_path = 'media/search'  # Copy search match image file(s) into subfolder here if copy_results_on=True.
MATCH_METHOD = 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 other comparison methods

For details on MATCH_METHOD see http://docs.opencv.org/3.1.0/d4/dc6/tutorial_py_template_matching.html

(Note: speed-search.py is still under development)