Commit d50d8e02 authored by Davis King's avatar Davis King

Made the run_multiple() routine work identically for fhog and simple object detectors.

parent 19005f68
......@@ -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<type>, &setstate<type>));
}
......
......@@ -232,6 +232,29 @@ namespace dlib
vector_to_python_list(weight_indices));
}
struct simple_object_detector_py
{
simple_object_detector detector;
unsigned int upsampling_amount;
simple_object_detector_py() {}
simple_object_detector_py(simple_object_detector& _detector, unsigned int _upsampling_amount) :
detector(_detector), upsampling_amount(_upsampling_amount) {}
std::vector<dlib::rectangle> run_detector1 (py::array img,
const unsigned int upsampling_amount_)
{
return run_detector_with_upscale2(detector, img, upsampling_amount_);
}
std::vector<dlib::rectangle> run_detector2 (py::array img)
{
return run_detector_with_upscale2(detector, img, upsampling_amount);
}
};
inline py::tuple run_multiple_rect_detectors (
py::list& detectors,
py::array img,
......@@ -240,12 +263,18 @@ namespace dlib
{
py::tuple t;
std::vector<simple_object_detector > vector_detectors;
std::vector<simple_object_detector> 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<simple_object_detector >());
try
{
vector_detectors.push_back(detectors[i].cast<simple_object_detector>());
} catch(py::cast_error&)
{
vector_detectors.push_back(detectors[i].cast<simple_object_detector_py>().detector);
}
}
std::vector<double> detection_confidences;
......@@ -263,28 +292,6 @@ namespace dlib
struct simple_object_detector_py
{
simple_object_detector detector;
unsigned int upsampling_amount;
simple_object_detector_py() {}
simple_object_detector_py(simple_object_detector& _detector, unsigned int _upsampling_amount) :
detector(_detector), upsampling_amount(_upsampling_amount) {}
std::vector<dlib::rectangle> run_detector1 (py::array img,
const unsigned int upsampling_amount_)
{
return run_detector_with_upscale2(detector, img, upsampling_amount_);
}
std::vector<dlib::rectangle> run_detector2 (py::array img)
{
return run_detector_with_upscale2(detector, img, upsampling_amount);
}
};
}
#endif // DLIB_SIMPLE_OBJECT_DETECTOR_PY_H__
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment