Make dlib.full_object_detection take list of dlib.point or dlib.points.

pull/1704/head
Davis King 6 years ago
parent b4e7e2e7d7
commit ae406bf4c1

@ -68,8 +68,12 @@ std::vector<point> full_obj_det_parts (const full_object_detection& detection)
return parts;
}
std::shared_ptr<full_object_detection> full_obj_det_init(const rectangle& rect, py::list& pyparts)
std::shared_ptr<full_object_detection> full_obj_det_init(const rectangle& rect, const py::object& pyparts_)
{
try
{
auto&& pyparts = pyparts_.cast<py::list>();
const unsigned long num_parts = py::len(pyparts);
std::vector<point> parts;
for (const auto& item : pyparts)
@ -77,6 +81,13 @@ std::shared_ptr<full_object_detection> full_obj_det_init(const rectangle& rect,
return std::make_shared<full_object_detection>(rect, parts);
}
catch (py::cast_error&)
{
// if it's not a py::list it better be a vector<point>.
auto&& parts = pyparts_.cast<const std::vector<point>&>();
return std::make_shared<full_object_detection>(rect, parts);
}
}
// ----------------------------------------------------------------------------------------
@ -163,7 +174,7 @@ void bind_shape_predictors(py::module &m)
.def(py::init(&full_obj_det_init), py::arg("rect"), py::arg("parts"),
"requires \n\
- rect: dlib rectangle \n\
- parts: list of dlib points")
- parts: list of dlib.point, or a dlib.points object.")
.def_property_readonly("rect", &full_obj_det_get_rect, "Bounding box from the underlying detector. Parts can be outside box if appropriate.")
.def_property_readonly("num_parts", &full_obj_det_num_parts, "The number of parts of the object.")
.def("part", &full_obj_det_part, py::arg("idx"), "A single part of the object as a dlib point.")

Loading…
Cancel
Save