18 #include <mrpt/otherlibs/do_opencv_includes.h> 27 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM >= 0x200 31 #define CASCADE (reinterpret_cast<CascadeClassifier*>(m_cascade)) 32 #define CASCADE_CONST (reinterpret_cast<const CascadeClassifier*>(m_cascade)) 41 #if !MRPT_HAS_OPENCV || MRPT_OPENCV_VERSION_NUM < 0x200 43 "CCascadeClassifierDetection class requires MRPT built against OpenCV " 54 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM >= 0x200 66 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM >= 0x200 68 m_options.cascadeFileName =
69 config.
read_string(
"CascadeClassifier",
"cascadeFilename",
"");
70 m_options.scaleFactor =
71 config.
read_double(
"DetectionOptions",
"scaleFactor", 1.1);
72 m_options.minNeighbors =
73 config.
read_int(
"DetectionOptions",
"minNeighbors", 3);
74 m_options.flags = config.
read_int(
"DetectionOptions",
"flags", 0);
75 m_options.minSize = config.
read_int(
"DetectionOptions",
"minSize", 30);
77 m_cascade =
new CascadeClassifier();
80 CASCADE->load(m_options.cascadeFileName);
83 if (
CASCADE->empty())
throw std::runtime_error(
"Incorrect cascade file.");
94 #if MRPT_HAS_OPENCV && MRPT_OPENCV_VERSION_NUM >= 0x200 117 std::this_thread::sleep_for(2ms);
121 vector<Rect> objects;
127 const IplImage*
image = img_gray.
getAs<IplImage>();
131 cv::cvarrToMat(
image), objects, m_options.scaleFactor,
132 m_options.minNeighbors, m_options.flags,
133 Size(m_options.minSize, m_options.minSize));
135 unsigned int N = objects.size();
139 for (
unsigned int i = 0; i < N; i++)
143 objects[i].
x, objects[i].
y, objects[i].
height,
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)
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.
std::shared_ptr< CDetectable2D > Ptr
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
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.
std::vector< CDetectableObject::Ptr > vector_detectable_object
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.
std::shared_ptr< CDetectableObject > Ptr
mrpt::utils::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage"...
GLenum GLsizei GLsizei height