From d50d8e02682c0dea4ebc15f43337424c7307115f Mon Sep 17 00:00:00 2001 From: Davis King Date: Sun, 17 Jun 2018 21:22:24 -0400 Subject: [PATCH] Made the run_multiple() routine work identically for fhog and simple object detectors. --- tools/python/src/object_detection.cpp | 11 ++++ tools/python/src/simple_object_detector_py.h | 69 +++++++++++--------- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/tools/python/src/object_detection.cpp b/tools/python/src/object_detection.cpp index 340e2f25f..6339a9da8 100644 --- a/tools/python/src/object_detection.cpp +++ b/tools/python/src/object_detection.cpp @@ -409,6 +409,17 @@ ensures \n\ a list of detections.") .def("save", save_simple_object_detector_py, py::arg("detector_output_filename"), "Save a simple_object_detector to the provided path.") .def_readwrite("upsampling_amount", &type::upsampling_amount, "The detector upsamples the image this many times before running.") + .def_static("run_multiple", run_multiple_rect_detectors, py::arg("detectors"), py::arg("image"), py::arg("upsample_num_times")=0, py::arg("adjust_threshold")=0.0, +"requires \n\ + - detectors is a list of detectors. \n\ + - image is a numpy ndarray containing either an 8bit grayscale or RGB \n\ + image. \n\ + - upsample_num_times >= 0 \n\ +ensures \n\ + - This function runs the list of object detectors at once on the input image and returns \n\ + a tuple of (list of detections, list of scores, list of weight_indices). \n\ + - Upsamples the image upsample_num_times before running the basic \n\ + detector.") .def(py::pickle(&getstate, &setstate)); } diff --git a/tools/python/src/simple_object_detector_py.h b/tools/python/src/simple_object_detector_py.h index 0ffef49a6..2d16b06e3 100644 --- a/tools/python/src/simple_object_detector_py.h +++ b/tools/python/src/simple_object_detector_py.h @@ -232,37 +232,6 @@ namespace dlib vector_to_python_list(weight_indices)); } - inline py::tuple run_multiple_rect_detectors ( - py::list& detectors, - py::array img, - const unsigned int upsampling_amount, - const double adjust_threshold) - { - py::tuple t; - - std::vector vector_detectors; - const unsigned long num_detectors = len(detectors); - // Now copy the data into dlib based objects. - for (unsigned long i = 0; i < num_detectors; ++i) - { - vector_detectors.push_back(detectors[i].cast()); - } - - std::vector detection_confidences; - std::vector weight_indices; - std::vector rectangles; - - rectangles = run_detectors_with_upscale1(vector_detectors, img, upsampling_amount, - adjust_threshold, - detection_confidences, weight_indices); - - return py::make_tuple(rectangles, - vector_to_python_list(detection_confidences), - vector_to_python_list(weight_indices)); - } - - - struct simple_object_detector_py { simple_object_detector detector; @@ -285,6 +254,44 @@ namespace dlib }; + + inline py::tuple run_multiple_rect_detectors ( + py::list& detectors, + py::array img, + const unsigned int upsampling_amount, + const double adjust_threshold) + { + py::tuple t; + + std::vector vector_detectors; + const unsigned long num_detectors = len(detectors); + // Now copy the data into dlib based objects. + for (unsigned long i = 0; i < num_detectors; ++i) + { + try + { + vector_detectors.push_back(detectors[i].cast()); + } catch(py::cast_error&) + { + vector_detectors.push_back(detectors[i].cast().detector); + } + } + + std::vector detection_confidences; + std::vector weight_indices; + std::vector rectangles; + + rectangles = run_detectors_with_upscale1(vector_detectors, img, upsampling_amount, + adjust_threshold, + detection_confidences, weight_indices); + + return py::make_tuple(rectangles, + vector_to_python_list(detection_confidences), + vector_to_python_list(weight_indices)); + } + + + } #endif // DLIB_SIMPLE_OBJECT_DETECTOR_PY_H__