/etc

tags: photogrammetry
Originally Published: 2015-01-22

Sometimes when processing video for 3D photogrammetry, you want to reduce the number of frames used in order to reduce the processing time or fit within a limit.1 You may also want to reduce the number of blurry frames used, as this can result in noise or errors with some reconstruction processes.

From this Stack Overflow answer on image sharpness I adapted the following Python code:

You can then process all your frame images with e.g.:

parallel --bar --line-buffer -j8 './sharpness.py {}' ::: *.jpg | sort -gr > sharpness.txt

I also wrote a complementary Python script designed to greedily filter this output into a target number of frames (optionally thresholded by a user-supplied cutoff), assuming there’s a single integer in each filename with the frame number and we’d prefer an even distribution of frames:

You can then copy, say, the 500 sharpest frames out of 5,000 with a minimum “sharpness” threshold of 2.0 out to a directory for photogrammetry processing with:

cp -v $(./filterlist.py 500 2.0 < sharpness.txt) sharp/

Footnotes

  1. Autodesk ReCap360, for example, limits you to 50 input images for the free “Preview” mode