mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
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:
parent
c0d0adba13
commit
68ae858f27
@ -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
|
||||
)
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
39
tools/python/src/image.cpp
Normal file
39
tools/python/src/image.cpp
Normal 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);
|
||||
}
|
11
tools/python/src/indexing.h
Normal file
11
tools/python/src/indexing.h
Normal 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__
|
@ -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);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------------------
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user