Commit 68ae858f authored by Patrick Snape's avatar Patrick Snape

Refactor rgb_pixel out of object detection

Also, move the vectorize template into its own header to
stop having to declare it again in vector.
parent c0d0adba
...@@ -21,6 +21,7 @@ add_python_module(dlib ...@@ -21,6 +21,7 @@ add_python_module(dlib
src/cca.cpp src/cca.cpp
src/sequence_segmenter.cpp src/sequence_segmenter.cpp
src/svm_struct.cpp src/svm_struct.cpp
src/image.cpp
src/object_detection.cpp src/object_detection.cpp
) )
......
...@@ -13,6 +13,7 @@ void bind_svm_rank_trainer(); ...@@ -13,6 +13,7 @@ void bind_svm_rank_trainer();
void bind_cca(); void bind_cca();
void bind_sequence_segmenter(); void bind_sequence_segmenter();
void bind_svm_struct(); void bind_svm_struct();
void bind_image_classes();
void bind_object_detection(); void bind_object_detection();
...@@ -32,6 +33,7 @@ BOOST_PYTHON_MODULE(dlib) ...@@ -32,6 +33,7 @@ BOOST_PYTHON_MODULE(dlib)
bind_cca(); bind_cca();
bind_sequence_segmenter(); bind_sequence_segmenter();
bind_svm_struct(); bind_svm_struct();
bind_image_classes();
bind_object_detection(); bind_object_detection();
} }
#include <dlib/python.h>
#include <boost/python/args.hpp>
#include "dlib/pixel.h"
using namespace dlib;
using namespace std;
using namespace boost::python;
// ----------------------------------------------------------------------------------------
string print_rgb_pixel_str(const rgb_pixel& p)
{
std::ostringstream sout;
sout << "red: "<< (int)p.red
<< ", green: "<< (int)p.green
<< ", blue: "<< (int)p.blue;
return sout.str();
}
string print_rgb_pixel_repr(const rgb_pixel& p)
{
std::ostringstream sout;
sout << "rgb_pixel(" << p.red << "," << p.green << "," << p.blue << ")";
return sout.str();
}
// ----------------------------------------------------------------------------------------
void bind_image_classes()
{
using boost::python::arg;
class_<rgb_pixel>("rgb_pixel")
.def(init<unsigned char,unsigned char,unsigned char>( (arg("red"),arg("green"),arg("blue")) ))
.def("__str__", &print_rgb_pixel_str)
.def("__repr__", &print_rgb_pixel_repr)
.add_property("red", &rgb_pixel::red)
.add_property("green", &rgb_pixel::green)
.add_property("blue", &rgb_pixel::blue);
}
// Copyright (C) 2014 Davis E. King (davis@dlib.net)
// License: Boost Software License See LICENSE.txt for the full license.
#ifndef DLIB_PYTHON_INDEXING_H__
#define DLIB_PYTHON_INDEXING_H__
namespace dlib
{
template <typename T>
void resize(T& v, unsigned long n) { v.resize(n); }
}
#endif // DLIB_PYTHON_INDEXING_H__
...@@ -11,15 +11,13 @@ ...@@ -11,15 +11,13 @@
#include <dlib/gui_widgets.h> #include <dlib/gui_widgets.h>
#endif #endif
#include "simple_object_detector.h" #include "simple_object_detector.h"
#include "indexing.h"
using namespace dlib; using namespace dlib;
using namespace std; using namespace std;
using namespace boost::python; using namespace boost::python;
template <typename T>
void resize(T& v, unsigned long n) { v.resize(n); }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
long left(const rectangle& r) { return r.left(); } long left(const rectangle& r) { return r.left(); }
...@@ -45,24 +43,6 @@ string print_rectangle_repr(const rectangle& r) ...@@ -45,24 +43,6 @@ string print_rectangle_repr(const rectangle& r)
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
string print_rgb_pixel_str(const rgb_pixel& p)
{
std::ostringstream sout;
sout << "red: "<< (int)p.red
<< ", green: "<< (int)p.green
<< ", blue: "<< (int)p.blue;
return sout.str();
}
string print_rgb_pixel_repr(const rgb_pixel& p)
{
std::ostringstream sout;
sout << "rgb_pixel(" << p.red << "," << p.green << "," << p.blue << ")";
return sout.str();
}
// ----------------------------------------------------------------------------------------
std::vector<rectangle> run_detector ( std::vector<rectangle> run_detector (
frontal_face_detector& detector, frontal_face_detector& detector,
object img, object img,
...@@ -615,14 +595,6 @@ ensures \n\ ...@@ -615,14 +595,6 @@ ensures \n\
.def("resize", resize<type>) .def("resize", resize<type>)
.def_pickle(serialize_pickle<type>()); .def_pickle(serialize_pickle<type>());
} }
class_<rgb_pixel>("rgb_pixel")
.def(init<unsigned char,unsigned char,unsigned char>( (arg("red"),arg("green"),arg("blue")) ))
.def("__str__", &print_rgb_pixel_str)
.def("__repr__", &print_rgb_pixel_repr)
.add_property("red", &rgb_pixel::red)
.add_property("green", &rgb_pixel::green)
.add_property("blue", &rgb_pixel::blue);
} }
// ---------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <dlib/matrix.h> #include <dlib/matrix.h>
#include <boost/python/slice.hpp> #include <boost/python/slice.hpp>
#include <dlib/geometry/vector.h> #include <dlib/geometry/vector.h>
#include "indexing.h"
using namespace dlib; using namespace dlib;
...@@ -15,9 +16,6 @@ using namespace boost::python; ...@@ -15,9 +16,6 @@ using namespace boost::python;
typedef matrix<double,0,1> cv; typedef matrix<double,0,1> cv;
template <typename T>
void resize(T& v, unsigned long n) { v.resize(n); }
void cv_set_size(cv& m, long s) void cv_set_size(cv& m, long s)
{ {
m.set_size(s); m.set_size(s);
......
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