From 9b78932ab1e69c452cc45276db5d9345262a450b Mon Sep 17 00:00:00 2001 From: Jack Culpepper Date: Thu, 12 Mar 2015 07:39:42 +0000 Subject: [PATCH] re-arrange, use vector to facilitate pass back to python --- tools/python/src/object_detection.cpp | 24 ++++++------ tools/python/src/simple_object_detector_py.h | 41 +++++++++++--------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/tools/python/src/object_detection.cpp b/tools/python/src/object_detection.cpp index fac7766bf..0b8d7294c 100644 --- a/tools/python/src/object_detection.cpp +++ b/tools/python/src/object_detection.cpp @@ -350,6 +350,18 @@ object_detector>>.") ensures \n\ - This function runs the object detector on the input image and returns \n\ a list of detections. \n\ + - Upsamples the image upsample_num_times before running the basic \n\ + detector. If you don't know how many times you want to upsample then \n\ + don't provide a value for upsample_num_times and an appropriate \n\ + default will be used.") + .def("run", run_rect_detector, (arg("image"), arg("upsample_num_times")), +"requires \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 object detector 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. If you don't know how many times you want to upsample then \n\ don't provide a value for upsample_num_times and an appropriate \n\ @@ -383,18 +395,6 @@ ensures \n\ ensures \n\ - This function runs the object detector on the input image and returns \n\ a list of detections.") - .def("run", &type::run_detector3, (arg("image"), arg("upsample_num_times")), -"requires \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 object detector 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. If you don't know how many times you want to upsample then \n\ - don't provide a value for upsample_num_times and an appropriate \n\ - default will be used.") .def("save", save_simple_object_detector_py, (arg("detector_output_filename")), "Save a simple_object_detector to the provided path.") .def_pickle(serialize_pickle()); } diff --git a/tools/python/src/simple_object_detector_py.h b/tools/python/src/simple_object_detector_py.h index 276a89db3..556784e4a 100644 --- a/tools/python/src/simple_object_detector_py.h +++ b/tools/python/src/simple_object_detector_py.h @@ -17,7 +17,7 @@ namespace dlib std::vector& rect_detections, std::vector& rectangles, std::vector& detection_confidences, - std::vector& weight_indices + std::vector& weight_indices ) { rectangles.clear(); @@ -37,7 +37,7 @@ namespace dlib boost::python::object img, const unsigned int upsampling_amount, std::vector& detection_confidences, - std::vector& weight_indices + std::vector& weight_indices ) { pyramid_down<2> pyr; @@ -111,6 +111,24 @@ namespace dlib } } + inline boost::python::tuple run_rect_detector ( + dlib::simple_object_detector& detector, + boost::python::object img, + const unsigned int upsampling_amount) + { + boost::python::tuple t; + + std::vector detection_confidences; + std::vector weight_indices; + std::vector rectangles; + + rectangles = run_detector_with_upscale(detector, img, upsampling_amount, + detection_confidences, weight_indices); + + return boost::python::make_tuple(rectangles, + detection_confidences, weight_indices); + } + struct simple_object_detector_py { simple_object_detector detector; @@ -124,7 +142,7 @@ namespace dlib const unsigned int upsampling_amount_) { std::vector detection_confidences; - std::vector weight_indices; + std::vector weight_indices; return run_detector_with_upscale(detector, img, upsampling_amount_, detection_confidences, weight_indices); @@ -133,27 +151,12 @@ namespace dlib std::vector run_detector2 (boost::python::object img) { std::vector detection_confidences; - std::vector weight_indices; + std::vector weight_indices; return run_detector_with_upscale(detector, img, upsampling_amount, detection_confidences, weight_indices); } - boost::python::tuple run_detector3 (boost::python::object img, - const unsigned int upsampling_amount_) - { - boost::python::tuple t; - - std::vector detection_confidences; - std::vector weight_indices; - std::vector rectangles; - - rectangles = run_detector_with_upscale(detector, img, upsampling_amount, - detection_confidences, weight_indices); - - return boost::python::make_tuple(rectangles, - detection_confidences, weight_indices); - } }; }