Go to the documentation of this file.
12 #include <mrpt/examples_config.h>
36 string myDataDir(MRPT_EXAMPLES_BASE_DIRECTORY +
string(
"detectors_face/"));
38 MRPT_EXAMPLES_BASE_DIRECTORY +
39 string(
"detectors_face/FACE_DETECTION_TEST.INI"));
49 vector<std::vector<uint32_t>>
ignored;
52 #ifdef MRPT_OPENCV_SRC_DIR
66 cout <<
"Close the window to exit." << endl;
72 win3D.setCameraElevationDeg(20);
73 win3D.setCameraZoom(6.0);
74 win3D.setCameraPointingToPoint(2.5, 0, 0);
81 gl_points->setPointSize(4.5);
85 gl_points2->setPointSize(4.5);
88 scene->insert(gl_points);
92 win3D.unlockAccess3DScene();
106 scene2->insert(gl_points2);
125 o = std::dynamic_pointer_cast<CObservation3DRangeScan>(
126 cam->getNextFrame());
142 if (detected.size() > 0)
144 for (
unsigned int i = 0; i < detected.size(); i++)
148 std::dynamic_pointer_cast<CDetectable3D>(detected[i]);
154 face, obj->m_y, obj->m_y + obj->m_height, obj->m_x,
155 obj->m_x + obj->m_width);
164 if (!o->hasConfidenceImage)
172 vector<float> xs, ys, zs;
174 for (
unsigned int j = 0;
176 for (
unsigned int k = 0;
194 gl_points2->loadFromPointsMap(&pntsMap);
201 o->intensityImage.rectangle(
202 obj->m_x, obj->m_y, obj->m_x + obj->m_width,
203 obj->m_y + obj->m_height,
TColor(255, 0, 0));
211 win.showImage(o->intensityImage);
216 win3D.get3DSceneAndLock();
221 gl_points->loadFromPointsMap(&pntsMap);
222 win3D.unlockAccess3DScene();
227 double t = tictac.
Tac();
228 cout <<
"Frame Rate: " <<
counter / t <<
" fps" << endl;
232 std::this_thread::sleep_for(2ms);
235 cout <<
"Fps mean: " << fps.
sum() / fps.
size() << endl;
239 cout <<
"Closing..." << endl;
251 cerr <<
"The user didn't pick any camera. Exiting." << endl;
266 cout <<
"Close the window to exit." << endl;
278 obs = cam->getNextFrame();
292 std::dynamic_pointer_cast<CObservationImage>(obs);
293 for (
unsigned int i = 0; i < detected.size(); i++)
297 std::dynamic_pointer_cast<CDetectable2D>(detected[i]);
299 obj->m_x, obj->m_y, obj->m_x + obj->m_width,
300 obj->m_y + obj->m_height,
TColor(255, 0, 0));
303 win.showImage(o->image);
311 std::dynamic_pointer_cast<CObservationStereoImages>(obs);
313 for (
unsigned int i = 0; i < detected.size(); i++)
317 std::dynamic_pointer_cast<CDetectable2D>(detected[i]);
318 o->imageRight.rectangle(
319 obj->m_x, obj->m_y, obj->m_x + obj->m_width,
320 obj->m_y + obj->m_height,
TColor(255, 0, 0));
323 win.showImage(o->imageRight);
328 double t = tictac.
Tac();
329 cout <<
"Frame Rate: " <<
counter / t <<
" fps" << endl;
332 std::this_thread::sleep_for(2ms);
335 cout <<
"Closing..." << endl;
348 for (
int i = 1; i <
argc; i++)
350 string fileName(
argv[i]);
354 cerr <<
"Cannot load " <<
myDataDir + fileName << endl;
364 cout <<
"Detection time: " << tictac.
Tac() <<
" s" << endl;
366 for (
unsigned int i = 0; i < detected.size(); i++)
370 std::dynamic_pointer_cast<CDetectable2D>(detected[i]);
372 obj->m_x, obj->m_y, obj->m_x + obj->m_width,
373 obj->m_y + obj->m_height,
TColor(255, 0, 0));
384 vector<double> frame_rates;
386 for (
size_t i = 0; i <
rawlogs.size(); i++)
392 cout <<
"Processing Rawlog [" << i + 1 <<
"/" <<
rawlogs.size()
393 <<
"]: " <<
rawlogs[i] << endl;
395 const unsigned int size = rawlog.
size();
401 for (
unsigned int j = 1; j <
size; j++)
406 std::dynamic_pointer_cast<CObservation3DRangeScan>(
417 double t = tictac.
Tac();
418 frame_rates.push_back(
counter / t);
422 std::this_thread::sleep_for(2ms);
425 unsigned int falsePositivesDeleted, realFacesDeleted;
429 cout <<
"False positives deleted: " << falsePositivesDeleted << endl;
430 cout <<
"Real faces delted: " << realFacesDeleted << endl << endl;
433 cout <<
"Mean frame rate: " <<
sum(frame_rates) / frame_rates.size();
440 void mySplit(
const string& str)
444 cstr =
new char[str.size() + 1];
445 strcpy(cstr, str.c_str());
467 int classifierType = cfg.read_int(
"Example",
"classifierType", 0);
469 if (classifierType == 0)
471 "CascadeClassifier",
"cascadeFileName",
473 "/data/haarcascades/haarcascade_frontalface_alt2.xml");
474 else if (classifierType == 1)
476 "CascadeClassifier",
"cascadeFileName",
479 throw std::runtime_error(
"Incorrect cascade classifier type.");
482 cfg.read_bool(
"Example",
"showEachDetectedFace",
false);
483 batchMode = cfg.read_bool(
"Example",
"batchMode",
false);
487 string str = cfg.read_string(
"Example",
"rawlogs",
"noRawlogs");
490 size_t numRawlogs =
rawlogs.size();
494 for (
size_t i = 0; i < numRawlogs; i++)
497 rawlogs[i],
"falsePositives", std::vector<uint32_t>(),
503 rawlogsDir = cfg.read_string(
"Example",
"rawlogsDir",
"");
534 catch (
const std::exception& e)
541 printf(
"Untyped exception!!");
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
std::shared_ptr< CObservation > Ptr
This class stores a rawlog (robotic datasets) in one of two possible formats:
void registerClass(const mrpt::rtti::TRuntimeClassId *pNewClass)
Register a class into the MRPT internal list of "CObject" descendents.
size_t getWidth() const override
Returns the width of the image in pixels.
void init(const mrpt::config::CConfigFileBase &cfg) override
Initialize the object with parameters loaded from the given config source.
static string OPENCV_SRC_DIR
A map of 2D/3D points with individual colours (RGB).
TColourOptions colorScheme
The options employed when inserting laser scans in the map.
void setWindowTitle(const std::string &str) override
Changes the window title.
A high-performance stopwatch, with typical resolution of nanoseconds.
Specific class for face detection.
std::shared_ptr< mrpt::opengl ::CPointCloudColoured > Ptr
std::vector< float > points3D_z
std::shared_ptr< mrpt::obs ::CObservationImage > Ptr
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class.
void setCameraZoom(float zoom)
Changes the camera parameters programmatically.
Contains classes for various device interfaces.
mrpt::opengl::COpenGLScene::Ptr & get3DSceneAndLock()
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introductio...
vector< std::vector< uint32_t > > falsePositives
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
#define ASSERT_(f)
Defines an assertion mechanism.
std::vector< float > points3D_y
Scalar sum() const
Sum of all elements in matrix/vector.
void resize(unsigned int width, unsigned int height) override
Resizes the window, stretching the image to fit into the display area.
This namespace contains representation of robot actions and observations.
void rectangle(int x0, int y0, int x1, int y1, const mrpt::img::TColor color, unsigned int width=1)
Draws a rectangle (an empty rectangle, without filling)
struct mrpt::detectors::CFaceDetection::TOptions m_options
double Tac() noexcept
Stops the stopwatch.
std::shared_ptr< mrpt::detectors ::CDetectable2D > Ptr
void detectObjects(const mrpt::obs::CObservation::Ptr obs, vector_detectable_object &detected)
void TestPrepareDetector()
CCameraSensor::Ptr prepareVideoSourceFromUserSelection()
Show to the user a list of possible camera drivers and creates and open the selected camera.
bool loadFromRawLogFile(const std::string &fileName, bool non_obs_objects_are_legal=false)
Load the contents from a file containing one of these possibilities:
mrpt::img::CImage intensityImage
If hasIntensityImage=true, a color or gray-level intensity image of the same size than "rangeImage".
void setCameraPointingToPoint(float x, float y, float z)
Changes the camera parameters programmatically.
void unlockAccess3DScene()
Unlocks the access to the internal 3D scene.
void setAllPoints(const std::vector< float > &X, const std::vector< float > &Y, const std::vector< float > &Z)
Set all the points at once from vectors with X,Y and Z coordinates.
A range or depth 3D scan measurement, as from a time-of-flight range camera or a structured-light dep...
static Ptr Create(Args &&... args)
static Ptr Create(Args &&... args)
mrpt::gui::CDisplayWindow3D::Ptr win
char * strtok(char *str, const char *strDelimit, char **context) noexcept
An OS-independent method for tokenizing a string.
size_t size() const
Returns the number of actions / observations object in the sequence.
void setCameraElevationDeg(float deg)
Changes the camera parameters programmatically.
std::vector< float > points3D_x
If hasPoints3D=true, the (X,Y,Z) coordinates of the 3D point cloud detected by the camera.
size_t size(const MATRIXLIKE &m, const int dim)
mrpt::img::CImage confidenceImage
If hasConfidenceImage=true, an image with the "confidence" value [range 0-255] as estimated by the ca...
void Tic() noexcept
Starts the stopwatch.
This class creates a window as a graphical user interface (GUI) for displaying images to the user.
Classes for creating GUI windows for 2D and 3D visualization.
A class for storing images as grayscale or RGB bitmaps.
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
std::vector< CDetectableObject::Ptr > vector_detectable_object
std::shared_ptr< mrpt::opengl ::COpenGLScene > Ptr
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
size_t getHeight() const override
Returns the height of the image in pixels.
Used in mrpt::serialization::CArchive.
void loadFromRangeScan(const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose=nullptr) override
See CPointsMap::loadFromRangeScan()
void TestCamera3DFaceDetection(CCameraSensor::Ptr cam)
This class allows loading and storing values and vectors of different types from "....
void getZoneAsObs(CObservation3DRangeScan &obs, const unsigned int &r1, const unsigned int &r2, const unsigned int &c1, const unsigned int &c2)
Extract a ROI of the 3D observation as a new one.
This base provides a set of functions for maths stuff.
void push_back(const T &val)
CFaceDetection faceDetector
Base class that contains common atributes and functions of detectable objects.
std::shared_ptr< CCameraSensor > Ptr
string myInitFile(MRPT_EXAMPLES_BASE_DIRECTORY+string("detectors_face/FACE_DETECTION_TEST.INI"))
vector< std::vector< uint32_t > > ignored
void setCameraAzimuthDeg(float deg)
Changes the camera parameters programmatically.
std::shared_ptr< mrpt::obs ::CObservationStereoImages > Ptr
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
void repaint()
Repaints the window.
CObservation::Ptr getAsObservation(size_t index) const
Returns the i'th element in the sequence, as being an observation, where index=0 is the first object.
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
void debug_returnResults(const std::vector< uint32_t > &falsePositives, const std::vector< uint32_t > &ignore, unsigned int &falsePositivesDeleted, unsigned int &realFacesDeleted)
std::shared_ptr< mrpt::detectors ::CDetectable3D > Ptr
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV).
std::shared_ptr< mrpt::obs ::CObservation3DRangeScan > Ptr
void TestImagesFaceDetection(int argc, char *argv[])
bool showEachDetectedFace
Declares a class derived from "CObservation" that encapsules an image from a camera,...
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
Observation class for either a pair of left+right or left+disparity images from a stereo camera.
void experimental_showMeasurements()
void TestCameraFaceDetection()
void pause(const std::string &msg=std::string("Press any key to continue...")) noexcept
Shows the message "Press any key to continue" (or other custom message) to the current standard outpu...
void mySplit(const string &str)
Page generated by Doxygen 1.8.17 for MRPT 2.0.3 at Fri May 15 15:49:54 UTC 2020 | |