19 #include <mrpt/otherlibs/do_opencv_includes.h> 26 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM>=0x200 30 #define CASCADE (reinterpret_cast<CascadeClassifier*>(m_cascade)) 31 #define CASCADE_CONST (reinterpret_cast<const CascadeClassifier*>(m_cascade)) 40 #if !MRPT_HAS_OPENCV || MRPT_OPENCV_VERSION_NUM<0x200 41 THROW_EXCEPTION(
"CCascadeClassifierDetection class requires MRPT built against OpenCV >=2.0")
51 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM>=0x200 62 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM>=0x200 64 m_options.cascadeFileName = config.
read_string(
"CascadeClassifier",
"cascadeFilename",
"");
65 m_options.scaleFactor = config.
read_double(
"DetectionOptions",
"scaleFactor",1.1);
66 m_options.minNeighbors = config.
read_int(
"DetectionOptions",
"minNeighbors",3);
67 m_options.flags = config.
read_int(
"DetectionOptions",
"flags",0);
68 m_options.minSize = config.
read_int(
"DetectionOptions",
"minSize",30);
70 m_cascade =
new CascadeClassifier();
73 CASCADE->load( m_options.cascadeFileName );
77 throw std::runtime_error(
"Incorrect cascade file.");
87 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM>=0x200 112 vector<Rect> objects;
118 const IplImage *
image = img_gray.
getAs<IplImage>();
121 CASCADE->detectMultiScale( cv::cvarrToMat(
image), objects, m_options.scaleFactor,
122 m_options.minNeighbors, m_options.flags,
123 Size(m_options.minSize,m_options.minSize) );
125 unsigned int N = objects.size();
129 for (
unsigned int i = 0; i < N; i++ )
131 CDetectable2DPtr
obj =
134 detected.push_back((CDetectableObjectPtr)
obj);
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
mrpt::utils::CImage imageLeft
Image from the left camera (this image will be ALWAYS present)
virtual ~CCascadeClassifierDetection()
A class for storing images as grayscale or RGB bitmaps.
#define THROW_EXCEPTION(msg)
std::vector< CDetectableObjectPtr > vector_detectable_object
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
virtual void detectObjects_Impl(const mrpt::obs::CObservation *obs, vector_detectable_object &detected)
Detect objects in a *CObservation.
GLenum GLsizei GLenum GLenum const GLvoid * image
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
CCascadeClassifierDetection()
GLsizei GLsizei GLuint * obj
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers.
This class allows loading and storing values and vectors of different types from a configuration text...
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
This namespace contains representation of robot actions and observations.
virtual void init(const mrpt::utils::CConfigFileBase &cfg)
Initialize cascade classifier detection.
Declares a class that represents any robot's observation.
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
mrpt::utils::CImage image
The image captured by the camera, that is, the main piece of information of this observation.
mrpt::utils::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage"...
GLenum GLsizei GLsizei height