Skip to content

Commit

Permalink
Refactor rgb_pixel out of object detection
Browse files Browse the repository at this point in the history
Also, move the vectorize template into its own header to
stop having to declare it again in vector.
  • Loading branch information
patricksnape committed Dec 10, 2014
1 parent c0d0adb commit 68ae858
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 32 deletions.
1 change: 1 addition & 0 deletions tools/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 2 additions & 0 deletions tools/python/src/dlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();


Expand All @@ -32,6 +33,7 @@ BOOST_PYTHON_MODULE(dlib)
bind_cca();
bind_sequence_segmenter();
bind_svm_struct();
bind_image_classes();
bind_object_detection();
}

39 changes: 39 additions & 0 deletions tools/python/src/image.cpp
Original file line number Diff line number Diff line change
@@ -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);
}
11 changes: 11 additions & 0 deletions tools/python/src/indexing.h
Original file line number Diff line number Diff line change
@@ -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__
30 changes: 1 addition & 29 deletions tools/python/src/object_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand All @@ -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,
Expand Down Expand Up @@ -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);
}

// ----------------------------------------------------------------------------------------
Expand Down
4 changes: 1 addition & 3 deletions tools/python/src/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <dlib/matrix.h>
#include <boost/python/slice.hpp>
#include <dlib/geometry/vector.h>
#include "indexing.h"


using namespace dlib;
Expand All @@ -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);
Expand Down

0 comments on commit 68ae858

Please sign in to comment.