mirror of https://github.com/davisking/dlib.git
Add an API for the correlation tracker
This aids an API for the correlation based tracker that Davis recently added to Dlib. I've made sure to allow overrides for passing normal rectangles rather than drectangles (which isn't currently supported in the Dlib C++ API). This is mostly because I imagine people might initialize the tracking using something like a bounding box from a detector (e.g. load_frontal_face_detector).
This commit is contained in:
parent
c4cf31a746
commit
e3c3d39ab1
|
@ -21,6 +21,7 @@ set(python_srcs
|
|||
src/rectangles.cpp
|
||||
src/object_detection.cpp
|
||||
src/shape_predictor.cpp
|
||||
src/correlation_tracker.cpp
|
||||
)
|
||||
|
||||
# Only add the GUI module if requested
|
||||
|
|
|
@ -0,0 +1,111 @@
|
|||
// Copyright (C) 2014 Davis E. King (davis@dlib.net)
|
||||
// License: Boost Software License See LICENSE.txt for the full license.
|
||||
|
||||
#include <dlib/python.h>
|
||||
#include <dlib/geometry.h>
|
||||
#include <boost/python/args.hpp>
|
||||
#include <dlib/image_processing.h>
|
||||
|
||||
using namespace dlib;
|
||||
using namespace std;
|
||||
using namespace boost::python;
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
void start_track (
|
||||
correlation_tracker& tracker,
|
||||
object img,
|
||||
const drectangle& bounding_box
|
||||
)
|
||||
{
|
||||
if (is_gray_python_image(img))
|
||||
{
|
||||
tracker.start_track(numpy_gray_image(img), bounding_box);
|
||||
}
|
||||
else if (is_rgb_python_image(img))
|
||||
{
|
||||
tracker.start_track(numpy_rgb_image(img), bounding_box);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw dlib::error("Unsupported image type, must be 8bit gray or RGB image.");
|
||||
}
|
||||
}
|
||||
|
||||
void start_track_rec (
|
||||
correlation_tracker& tracker,
|
||||
object img,
|
||||
const rectangle& bounding_box
|
||||
)
|
||||
{
|
||||
drectangle dbounding_box(bounding_box);
|
||||
start_track(tracker, img, dbounding_box);
|
||||
}
|
||||
|
||||
void update (
|
||||
correlation_tracker& tracker,
|
||||
object img
|
||||
)
|
||||
{
|
||||
if (is_gray_python_image(img))
|
||||
{
|
||||
tracker.update(numpy_gray_image(img));
|
||||
}
|
||||
else if (is_rgb_python_image(img))
|
||||
{
|
||||
tracker.update(numpy_rgb_image(img));
|
||||
}
|
||||
else
|
||||
{
|
||||
throw dlib::error("Unsupported image type, must be 8bit gray or RGB image.");
|
||||
}
|
||||
}
|
||||
|
||||
void update_guess (
|
||||
correlation_tracker& tracker,
|
||||
object img,
|
||||
const drectangle& bounding_box
|
||||
)
|
||||
{
|
||||
if (is_gray_python_image(img))
|
||||
{
|
||||
tracker.update(numpy_gray_image(img), bounding_box);
|
||||
}
|
||||
else if (is_rgb_python_image(img))
|
||||
{
|
||||
tracker.update(numpy_rgb_image(img), bounding_box);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw dlib::error("Unsupported image type, must be 8bit gray or RGB image.");
|
||||
}
|
||||
}
|
||||
|
||||
void update_guess_rec (
|
||||
correlation_tracker& tracker,
|
||||
object img,
|
||||
const rectangle& bounding_box
|
||||
)
|
||||
{
|
||||
drectangle dbounding_box(bounding_box);
|
||||
update_guess(tracker, img, dbounding_box);
|
||||
}
|
||||
|
||||
drectangle get_position (const correlation_tracker& tracker) { return tracker.get_position(); }
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
||||
void bind_correlation_tracker()
|
||||
{
|
||||
using boost::python::arg;
|
||||
{
|
||||
typedef correlation_tracker type;
|
||||
class_<type>("correlation_tracker", "")
|
||||
.def("start_track", &::start_track, (arg("image"), arg("bounding_box")))
|
||||
.def("start_track", &::start_track_rec, (arg("image"), arg("bounding_box")))
|
||||
.def("update", &::update, arg("image"))
|
||||
.def("update", &::update_guess, (arg("image"), arg("guess")))
|
||||
.def("update", &::update_guess_rec, (arg("image"), arg("guess")))
|
||||
.def("get_position", &::get_position);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ void bind_image_classes();
|
|||
void bind_rectangles();
|
||||
void bind_object_detection();
|
||||
void bind_shape_predictors();
|
||||
void bind_correlation_tracker();
|
||||
|
||||
#ifndef DLIB_NO_GUI_SUPPORT
|
||||
void bind_gui();
|
||||
|
@ -42,6 +43,7 @@ BOOST_PYTHON_MODULE(dlib)
|
|||
bind_rectangles();
|
||||
bind_object_detection();
|
||||
bind_shape_predictors();
|
||||
bind_correlation_tracker();
|
||||
#ifndef DLIB_NO_GUI_SUPPORT
|
||||
bind_gui();
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue