21 #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);
80 mrpt::make_aligned_shared<mrpt::opengl::CPointCloudColoured>();
81 gl_points->setPointSize(4.5);
84 mrpt::make_aligned_shared<mrpt::opengl::CPointCloudColoured>();
85 gl_points2->setPointSize(4.5);
88 scene->insert(gl_points);
89 scene->insert(mrpt::make_aligned_shared<mrpt::opengl::CGridPlaneXY>());
92 win3D.unlockAccess3DScene();
106 scene2->insert(gl_points2);
107 scene2->insert(mrpt::make_aligned_shared<mrpt::opengl::CGridPlaneXY>());
126 cam->getNextFrame());
142 if (detected.size() > 0)
144 for (
unsigned int i = 0; i < detected.size(); i++)
156 win2.showImage(
face.intensityImage);
164 if (!o->hasConfidenceImage)
172 vector<float> xs, ys, zs;
174 for (
unsigned int j = 0;
175 j <
face.confidenceImage.getHeight(); j++)
176 for (
unsigned int k = 0;
177 k <
face.confidenceImage.getWidth();
181 *(
face.confidenceImage.get_unsafe(
186 xs.push_back(
face.points3D_x[i]);
187 ys.push_back(
face.points3D_y[i]);
188 zs.push_back(
face.points3D_z[i]);
195 gl_points2->loadFromPointsMap(&pntsMap);
202 o->intensityImage.rectangle(
212 win.showImage(o->intensityImage);
217 win3D.get3DSceneAndLock();
222 gl_points->loadFromPointsMap(&pntsMap);
223 win3D.unlockAccess3DScene();
228 double t = tictac.
Tac();
229 cout <<
"Frame Rate: " <<
counter /
t <<
" fps" << endl;
233 std::this_thread::sleep_for(2ms);
236 cout <<
"Fps mean: " << fps.sumAll() / fps.size() << endl;
240 cout <<
"Closing..." << endl;
252 cerr <<
"The user didn't pick any camera. Exiting." << endl;
267 cout <<
"Close the window to exit." << endl;
279 obs = cam->getNextFrame();
294 for (
unsigned int i = 0; i < detected.size(); i++)
304 win.showImage(o->image);
314 for (
unsigned int i = 0; i < detected.size(); i++)
319 o->imageRight.rectangle(
324 win.showImage(o->imageRight);
329 double t = tictac.
Tac();
330 cout <<
"Frame Rate: " <<
counter /
t <<
" fps" << endl;
333 std::this_thread::sleep_for(2ms);
336 cout <<
"Closing..." << endl;
349 for (
int i = 1; i < argc; i++)
351 string fileName(argv[i]);
355 cerr <<
"Cannot load " <<
myDataDir + fileName << endl;
365 cout <<
"Detection time: " << tictac.
Tac() <<
" s" << endl;
367 for (
unsigned int i = 0; i < detected.size(); i++)
385 vector<double> frame_rates;
387 for (
size_t i = 0; i <
rawlogs.size(); i++)
393 cout <<
"Processing Rawlog [" << i + 1 <<
"/" <<
rawlogs.size()
394 <<
"]: " <<
rawlogs[i] << endl;
396 const unsigned int size = rawlog.
size();
402 for (
unsigned int j = 1; j <
size; j++)
418 double t = tictac.
Tac();
423 std::this_thread::sleep_for(2ms);
426 unsigned int falsePositivesDeleted, realFacesDeleted;
430 cout <<
"False positives deleted: " << falsePositivesDeleted << endl;
431 cout <<
"Real faces delted: " << realFacesDeleted << endl << endl;
434 cout <<
"Mean frame rate: " <<
sum(frame_rates) / frame_rates.size();
441 void mySplit(
const string& str)
445 cstr =
new char[str.size() + 1];
446 strcpy(cstr, str.c_str());
468 int classifierType = cfg.read_int(
"Example",
"classifierType", 0);
470 if (classifierType == 0)
472 "CascadeClassifier",
"cascadeFileName",
474 "/data/haarcascades/haarcascade_frontalface_alt2.xml");
475 else if (classifierType == 1)
477 "CascadeClassifier",
"cascadeFileName",
480 throw std::runtime_error(
"Incorrect cascade classifier type.");
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",
"");
512 int main(
int argc,
char* argv[])
534 catch (std::exception& e)
536 std::cout <<
"MRPT exception caught: " << e.what() << std::endl;
541 printf(
"Untyped exception!!");
double Tac() noexcept
Stops the stopwatch.
void unlockAccess3DScene()
Unlocks the access to the internal 3D scene.
static string OPENCV_SRC_DIR
Declares a class derived from "CObservation" that encapsules an image from a camera, whose relative pose to robot is also stored.
void debug_returnResults(const std::vector< uint32_t > &falsePositives, const std::vector< uint32_t > &ignore, unsigned int &falsePositivesDeleted, unsigned int &realFacesDeleted)
CCameraSensor::Ptr prepareVideoSourceFromUserSelection()
Show to the user a list of possible camera drivers and creates and open the selected camera...
void setWindowTitle(const std::string &str) override
Changes the window title.
mrpt::opengl::COpenGLScene::Ptr & get3DSceneAndLock()
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introductio...
void resize(unsigned int width, unsigned int height) override
Resizes the window, stretching the image to fit into the display area.
void setCameraPointingToPoint(float x, float y, float z)
Changes the camera parameters programmatically.
This class allows loading and storing values and vectors of different types from ".ini" files easily.
This file implements several operations that operate element-wise on individual or pairs of container...
A high-performance stopwatch, with typical resolution of nanoseconds.
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.
Column vector, like Eigen::MatrixX*, but automatically initialized to zeros since construction...
Contains classes for various device interfaces.
std::vector< CDetectableObject::Ptr > vector_detectable_object
GLsizei GLsizei GLuint * obj
TColourOptions colorScheme
The options employed when inserting laser scans in the map.
vector< std::vector< uint32_t > > falsePositives
#define ASSERT_(f)
Defines an assertion mechanism.
bool loadFromRawLogFile(const std::string &fileName, bool non_obs_objects_are_legal=false)
Load the contents from a file containing one of these possibilities:
This base provides a set of functions for maths stuff.
#define CLASS_ID(T)
Access to runtime class ID for a defined class name.
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...
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.
This class creates a window as a graphical user interface (GUI) for displaying images to the user...
char * strtok(char *str, const char *strDelimit, char **context) noexcept
An OS-independent method for tokenizing a string.
CONTAINER::Scalar sum(const CONTAINER &v)
Computes the sum of all the elements.
virtual void init(const mrpt::config::CConfigFileBase &cfg)
Initialize the object with parameters loaded from the given config source.
Observation class for either a pair of left+right or left+disparity images from a stereo camera...
This class stores a rawlog (robotic datasets) in one of two possible formats:
This namespace contains representation of robot actions and observations.
void TestPrepareDetector()
Specific class for face detection.
A map of 2D/3D points with individual colours (RGB).
mrpt::gui::CDisplayWindow3D::Ptr win
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...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
virtual void loadFromRangeScan(const mrpt::obs::CObservation2DRangeScan &rangeScan, const mrpt::poses::CPose3D *robotPose=nullptr) override
See CPointsMap::loadFromRangeScan()
void experimental_showMeasurements()
void setCameraZoom(float zoom)
Changes the camera parameters programmatically.
void registerClass(const mrpt::rtti::TRuntimeClassId *pNewClass)
Register a class into the MRPT internal list of "CObject" descendents.
Classes for creating GUI windows for 2D and 3D visualization.
vector< std::vector< uint32_t > > ignored
void TestCamera3DFaceDetection(CCameraSensor::Ptr cam)
void Tic() noexcept
Starts the stopwatch.
void repaint()
Repaints the window.
char * strcpy(char *dest, size_t destSize, const char *source) noexcept
An OS-independent version of strcpy.
CFaceDetection faceDetector
void TestImagesFaceDetection(int argc, char *argv[])
string myInitFile(MRPT_EXAMPLES_BASE_DIRECTORY+string("detectors_face/FACE_DETECTION_TEST.INI"))
size_t size() const
Returns the number of actions / observations object in the sequence.
void detectObjects(const mrpt::obs::CObservation::Ptr obs, vector_detectable_object &detected)
struct mrpt::detectors::CFaceDetection::TOptions m_options
Base class that contains common atributes and functions of detectable objects.
void TestCameraFaceDetection()
void mySplit(const string &str)
void setCameraAzimuthDeg(float deg)
Changes the camera parameters programmatically.
GLenum GLuint GLint GLenum face
A class for storing images as grayscale or RGB bitmaps.
Used in mrpt::serialization::CArchive.
void setCameraElevationDeg(float deg)
Changes the camera parameters programmatically.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
bool showEachDetectedFace