text
stringlengths 0
2.2M
|
---|
// ----------------------------------------------------------------------------------------
|
full_object_detection run_predictor (
|
shape_predictor& predictor,
|
py::array img,
|
const rectangle& box
|
)
|
{
|
if (is_image<unsigned char>(img))
|
{
|
return predictor(numpy_image<unsigned char>(img), box);
|
}
|
else if (is_image<rgb_pixel>(img))
|
{
|
return predictor(numpy_image<rgb_pixel>(img), box);
|
}
|
else
|
{
|
throw dlib::error("Unsupported image type, must be 8bit gray or RGB image.");
|
}
|
}
|
void save_shape_predictor(const shape_predictor& predictor, const std::string& predictor_output_filename)
|
{
|
std::ofstream fout(predictor_output_filename.c_str(), std::ios::binary);
|
serialize(predictor, fout);
|
}
|
// ----------------------------------------------------------------------------------------
|
rectangle full_obj_det_get_rect (const full_object_detection& detection)
|
{ return detection.get_rect(); }
|
unsigned long full_obj_det_num_parts (const full_object_detection& detection)
|
{ return detection.num_parts(); }
|
point full_obj_det_part (const full_object_detection& detection, const unsigned long idx)
|
{
|
if (idx >= detection.num_parts())
|
{
|
PyErr_SetString(PyExc_IndexError, "Index out of range");
|
throw py::error_already_set();
|
}
|
return detection.part(idx);
|
}
|
std::vector<point> full_obj_det_parts (const full_object_detection& detection)
|
{
|
const unsigned long num_parts = detection.num_parts();
|
std::vector<point> parts(num_parts);
|
for (unsigned long j = 0; j < num_parts; ++j)
|
parts[j] = detection.part(j);
|
return parts;
|
}
|
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)
|
parts.push_back(item.cast<point>());
|
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);
|
}
|
}
|
// ----------------------------------------------------------------------------------------
|
inline shape_predictor train_shape_predictor_on_images_py (
|
const py::list& pyimages,
|
const py::list& pydetections,
|
const shape_predictor_training_options& options
|
)
|
{
|
const unsigned long num_images = py::len(pyimages);
|
if (num_images != py::len(pydetections))
|
throw dlib::error("The length of the detections list must match the length of the images list.");
|
std::vector<std::vector<full_object_detection> > detections(num_images);
|
dlib::array<numpy_image<unsigned char>> images(num_images);
|
images_and_nested_params_to_dlib(pyimages, pydetections, images, detections);
|
return train_shape_predictor_on_images(images, detections, options);
|
}
|
inline double test_shape_predictor_with_images_py (
|
const py::list& pyimages,
|
const py::list& pydetections,
|
const py::list& pyscales,
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.