diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-03-09 13:19:22 +0000 |
commit | c21c3b0befeb46a51b6bf3758ffa30813bea0ff0 (patch) | |
tree | 9754ff1ca740f6346cf8483ec915d4054bc5da2d /ml/dlib/python_examples/find_candidate_object_locations.py | |
parent | Adding upstream version 1.43.2. (diff) | |
download | netdata-c21c3b0befeb46a51b6bf3758ffa30813bea0ff0.tar.xz netdata-c21c3b0befeb46a51b6bf3758ffa30813bea0ff0.zip |
Adding upstream version 1.44.3.upstream/1.44.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | ml/dlib/python_examples/find_candidate_object_locations.py | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ml/dlib/python_examples/find_candidate_object_locations.py b/ml/dlib/python_examples/find_candidate_object_locations.py new file mode 100755 index 000000000..a5c386425 --- /dev/null +++ b/ml/dlib/python_examples/find_candidate_object_locations.py @@ -0,0 +1,54 @@ +#!/usr/bin/python +# +# This example shows how to use find_candidate_object_locations(). The +# function takes an input image and generates a set of candidate rectangles +# which are expected to bound any objects in the image. +# It is based on the paper: +# Segmentation as Selective Search for Object Recognition by Koen E. A. van de Sande, et al. +# +# Typically, you would use this as part of an object detection pipeline. +# find_candidate_object_locations() nominates boxes that might contain an +# object and you then run some expensive classifier on each one and throw away +# the false alarms. Since find_candidate_object_locations() will only generate +# a few thousand rectangles it is much faster than scanning all possible +# rectangles inside an image. +# +# +# COMPILING/INSTALLING THE DLIB PYTHON INTERFACE +# You can install dlib using the command: +# pip install dlib +# +# Alternatively, if you want to compile dlib yourself then go into the dlib +# root folder and run: +# python setup.py install +# or +# python setup.py install --yes USE_AVX_INSTRUCTIONS +# if you have a CPU that supports AVX instructions, since this makes some +# things run faster. +# +# Compiling dlib should work on any operating system so long as you have +# CMake installed. On Ubuntu, this can be done easily by running the +# command: +# sudo apt-get install cmake +# +# Also note that this example requires scikit-image which can be installed +# via the command: +# pip install scikit-image +# Or downloaded from http://scikit-image.org/download.html. + + + +import dlib +from skimage import io + +image_file = '../examples/faces/2009_004587.jpg' +img = io.imread(image_file) + +# Locations of candidate objects will be saved into rects +rects = [] +dlib.find_candidate_object_locations(img, rects, min_size=500) + +print("number of rectangles found {}".format(len(rects))) +for k, d in enumerate(rects): + print("Detection {}: Left: {} Top: {} Right: {} Bottom: {}".format( + k, d.left(), d.top(), d.right(), d.bottom())) |