mirror of https://github.com/davisking/dlib.git
Made the run_multiple() routine work identically for fhog and simple object detectors.
This commit is contained in:
parent
19005f68c2
commit
d50d8e0268
|
@ -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,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<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 >());
|
||||
}
|
||||
|
||||
std::vector<double> detection_confidences;
|
||||
std::vector<unsigned long> weight_indices;
|
||||
std::vector<rectangle> 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<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)
|
||||
{
|
||||
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;
|
||||
std::vector<unsigned long> weight_indices;
|
||||
std::vector<rectangle> 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__
|
||||
|
|
Loading…
Reference in New Issue