Code documentation

The foxmask.py module will evaluate the background based on images located, by default, in the Images directory of the FoxMask repository, and perform a foreground segmentation to identify moving objects. The main routine of the code will iterate through every folders present in the Images directory, and analyze found images. The Images directory is set by a variable define in parameters.py: imagesDir.

Example:

To run this module, simply invoke it from the command line.

$ python2 foxmask.py

The ultimate output of this module is a Results directory, under which resulting masks are copied, as well as images containing moving objects (as the result of the analysis). Tables are also written, one table for each directory analyzed. Each table contains the name of the image, the result (0 or 1) of detection and parameters used during the analysis.

Setup

The following class will do all the preliminary setup required to run the code and clean temporary files and directories. One variable residing in parameters.py can be parametrised: rmmasks, defining if resulting masks should be kept. This could be useful, for example, for visual evaluation of the analysis.

class foxmask.Setup[source]
delmaskresults(folder)[source]

Remove the MasksResults directory. The MasksResults directory is created by the cpp command (calling ForegroundSegmentation), on each run, and resides in the folder being analyzed. If the variable rmmasks (in parameters.py) is set to 1, the directory will be removed after each run. If not, masks will be kept in place.

getfolders()[source]

This function will take as input the imagesDir variable specified in parameters.py and return a list of all folders present in it. This list will then feed the software with all the folders containing images to be analyzed. Each folders are considered as a single analyzed entity.

Returns:
list. A list of all folders in imagesDir.
maketempdir(folder)[source]

Creation of a temporary directory in which all analyzed images will be written. This directory will be created in all folders being analyzed and removed after each run.

Note

For performances issue, the images analyzed are being resized, so this function exist to create a place where to store the resized images. Theses resized images, placed in a temporary folder, will be the one actually analyzed by the software.

Returns:
string. The location of the actual folder being analyzed concatenated with temp1.

Images to analyze and metadata

The following class will gather all images in the folder being analysed, and search in each image metadata for the DateTimeOriginal, which is the time the picture was taken. Based on the latter, groups of images are made.

class foxmask.Getimagesinfos[source]
getimageslist(folder)[source]

Generate a list of all images under folder, which is the actual folder being analyzed. This folder is the actual result of the iteration over the folderslist list. As written, the code will only gather .jpg images.

Note

This function should be rewritten using ignore case, and should be able to gather other images format.

Returns:
list. The list of images under the folder being analyzed.
getimagesmeta(imglist)[source]

Get metadata DateTimeOriginal from every image in imglist and store them into a list. It’s crucial to get the accurate time of creation as it is used by getimpg() to group images that were taken few seconds apart.

Format returned:

>>> datetime.datetime(2014, 8, 6, 16, 5, 55)
Returns:
list. List of datetime objects representing the exact time the image were taken.
getimpg(sortedlisttags)[source]

This will group images based on the differences in time between each shot. It is crucial that the listtags are well sorted by time.

sortimages(imglist, listtags)[source]

Sort images based on their metadata. This function can not be called before getimagesmeta.