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.
This commit is contained in:
Patrick Snape 2014-12-10 12:14:53 +00:00
parent c0d0adba13
commit 68ae858f27
6 changed files with 55 additions and 32 deletions

View File

@ -21,6 +21,7 @@ add_python_module(dlib
src/cca.cpp
src/sequence_segmenter.cpp
src/svm_struct.cpp
src/image.cpp
src/object_detection.cpp
)

View File

@ -13,6 +13,7 @@ void bind_svm_rank_trainer();
void bind_cca();
void bind_sequence_segmenter();
void bind_svm_struct();
void bind_image_classes();
void bind_object_detection();
@ -32,6 +33,7 @@ BOOST_PYTHON_MODULE(dlib)
bind_cca();
bind_sequence_segmenter();
bind_svm_struct();
bind_image_classes();
bind_object_detection();
}

View File

@ -0,0 +1,39 @@
#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);
}

View File

@ -0,0 +1,11 @@
// 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__

View File

@ -11,15 +11,13 @@
#include <dlib/gui_widgets.h>
#endif
#include "simple_object_detector.h"
#include "indexing.h"
using namespace dlib;
using namespace std;
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(); }
@ -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 (
frontal_face_detector& detector,
object img,
@ -615,14 +595,6 @@ ensures \n\
.def("resize", resize<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);
}
// ----------------------------------------------------------------------------------------

View File

@ -7,6 +7,7 @@
#include <dlib/matrix.h>
#include <boost/python/slice.hpp>
#include <dlib/geometry/vector.h>
#include "indexing.h"
using namespace dlib;
@ -15,9 +16,6 @@ using namespace boost::python;
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)
{
m.set_size(s);