18 #include <mrpt/3rdparty/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 111 img = &o.intensityImage;
115 std::this_thread::sleep_for(2ms);
119 vector<Rect> objects;
129 image, objects, m_options.scaleFactor, m_options.minNeighbors,
130 m_options.flags, Size(m_options.minSize, m_options.minSize));
132 unsigned int N = objects.size();
136 for (
unsigned int i = 0; i < N; i++)
138 auto obj = std::make_shared<CDetectable2D>(
139 objects[i].x, objects[i].y, objects[i].height, objects[i].width);
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
virtual ~CCascadeClassifierDetection()
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
#define THROW_EXCEPTION(msg)
cv::Mat & asCvMatRef()
Get a reference to the internal cv::Mat, which can be resized, etc.
A range or depth 3D scan measurement, as from a time-of-flight range camera or a structured-light dep...
CCascadeClassifierDetection()
std::vector< CDetectableObject::Ptr > vector_detectable_object
int read_int(const std::string §ion, const std::string &name, int defaultValue, bool failIfNotFound=false) const
void detectObjects_Impl(const mrpt::obs::CObservation &obs, vector_detectable_object &detected) override
Detect objects in a *CObservation.
This class allows loading and storing values and vectors of different types from a configuration text...
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.
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class...
double read_double(const std::string §ion, const std::string &name, double defaultValue, bool failIfNotFound=false) const
void init(const mrpt::config::CConfigFileBase &cfg) override
Initialize cascade classifier detection.
Declares a class that represents any robot's observation.
A class for storing images as grayscale or RGB bitmaps.