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);
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(k, j, 0));
185 xs.push_back(
face.points3D_x[i]);
186 ys.push_back(
face.points3D_y[i]);
187 zs.push_back(
face.points3D_z[i]);
194 gl_points2->loadFromPointsMap(&pntsMap);
201 o->intensityImage.rectangle(
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();
293 for (
unsigned int i = 0; i < detected.size(); i++)
303 win.showImage(o->image);
313 for (
unsigned int i = 0; i < detected.size(); i++)
318 o->imageRight.rectangle(
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++)
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++)
417 double t = tictac.
Tac();
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",
"");
512 int main(
int argc,
char* argv[])
534 catch (
const std::exception& e)
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.
static Ptr Create(Args &&... args)
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.
size_type size() const
Get a 2-vector with [NROWS NCOLS] (as in MATLAB command size(x))
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.
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.
void push_back(const T &val)
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.
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.
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class...
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...
void init(const mrpt::config::CConfigFileBase &cfg) override
Initialize the object with parameters loaded from the given config source.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Scalar sum() const
Sum of all elements in matrix/vector.
CSetOfObjects::Ptr CornerXYZ(float scale=1.0)
Returns three arrows representing a X,Y,Z 3D corner.
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.
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 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)
static Ptr Create(Args &&... args)
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