From d3006ab3b96328a2bd6293374767f3d128aa5f67 Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 17 Jun 2018 23:17:36 -0400 Subject: [PATCH] Made it so you can call the std::vector version of the object_detector constructor from python. So now you can pack multiple detectors into one object via the python API. --- tools/python/src/object_detection.cpp | 31 +++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tools/python/src/object_detection.cpp b/tools/python/src/object_detection.cpp index 6339a9da8..119585698 100644 --- a/tools/python/src/object_detection.cpp +++ b/tools/python/src/object_detection.cpp @@ -123,6 +123,23 @@ inline void find_candidate_object_locations_py ( // ---------------------------------------------------------------------------------------- +std::shared_ptr merge_simple_object_detectors ( + const py::list& detectors +) +{ + DLIB_CASSERT(len(detectors) > 0); + std::vector temp; + for (auto& d : detectors) + temp.push_back(d.cast().detector); + + simple_object_detector_py result; + result.detector = simple_object_detector(temp); + result.upsampling_amount = detectors[0].cast().upsampling_amount; + return std::make_shared(result); +} + +// ---------------------------------------------------------------------------------------- + void bind_object_detection(py::module& m) { { @@ -385,6 +402,20 @@ ensures \n\ typedef simple_object_detector_py type; py::class_>(m, "simple_object_detector", "This object represents a sliding window histogram-of-oriented-gradients based object detector.") + .def(py::init(&merge_simple_object_detectors), py::arg("detectors"), +"This version of the constructor builds a simple_object_detector from a \n\ +bunch of other simple_object_detectors. It essentially packs them together \n\ +so that when you run the detector it's like calling run_multiple(). Except \n\ +in this case the non-max suppression is applied to them all as a group. So \n\ +unlike run_multiple(), each detector competes in the non-max suppression." + /*! + This version of the constructor builds a simple_object_detector from a + bunch of other simple_object_detectors. It essentially packs them together + so that when you run the detector it's like calling run_multiple(). Except + in this case the non-max suppression is applied to them all as a group. So + unlike run_multiple(), each detector competes in the non-max suppression. + !*/ + ) .def(py::init(&load_object_from_file), "Loads a simple_object_detector from a file that contains the output of the \n\ train_simple_object_detector() routine.")