1 #include <visp3/core/vpConfig.h>
3 #include <visp3/detection/vpDetectorFace.h>
4 #include <visp3/gui/vpDisplayGDI.h>
5 #include <visp3/gui/vpDisplayOpenCV.h>
6 #include <visp3/gui/vpDisplayX.h>
7 #ifdef VISP_HAVE_MODULE_SENSOR
8 #include <visp3/sensor/vpV4l2Grabber.h>
11 int main(
int argc,
const char *argv[])
13 #if (VISP_HAVE_OPENCV_VERSION >= 0x020200) && defined(VISP_HAVE_OPENCV_OBJDETECT)
15 std::string opt_face_cascade_name =
"./haarcascade_frontalface_alt.xml";
16 unsigned int opt_device = 0;
17 unsigned int opt_scale = 2;
20 for (
int i = 0; i < argc; i++) {
21 if (std::string(argv[i]) ==
"--haar")
22 opt_face_cascade_name = std::string(argv[i + 1]);
23 else if (std::string(argv[i]) ==
"--device")
24 opt_device = (
unsigned int)atoi(argv[i + 1]);
25 else if (std::string(argv[i]) ==
"--scale")
26 opt_scale = (
unsigned int)atoi(argv[i + 1]);
27 else if (std::string(argv[i]) ==
"--help") {
28 std::cout <<
"Usage: " << argv[0]
29 <<
" [--haar <haarcascade xml filename>] [--device <camera "
30 "device>] [--scale <subsampling factor>] [--help]"
39 #if defined(VISP_HAVE_V4L2)
41 std::ostringstream device;
42 device <<
"/dev/video" << opt_device;
47 #elif defined(VISP_HAVE_OPENCV)
48 cv::VideoCapture cap(opt_device);
49 #if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
50 int width = (int)cap.get(cv::CAP_PROP_FRAME_WIDTH);
51 int height = (int)cap.get(cv::CAP_PROP_FRAME_HEIGHT);
52 cap.set(cv::CAP_PROP_FRAME_WIDTH, width / opt_scale);
53 cap.set(cv::CAP_PROP_FRAME_HEIGHT, height / opt_scale);
55 int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
56 int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT);
57 cap.set(CV_CAP_PROP_FRAME_WIDTH, width / opt_scale);
58 cap.set(CV_CAP_PROP_FRAME_HEIGHT, height / opt_scale);
60 if (!cap.isOpened()) {
61 std::cout <<
"Failed to open the camera" << std::endl;
70 #if defined(VISP_HAVE_X11)
72 #elif defined(VISP_HAVE_GDI)
74 #elif defined(VISP_HAVE_OPENCV)
79 vpDetectorFace face_detector;
80 face_detector.setCascadeClassifierFile(opt_face_cascade_name);
85 #if defined(VISP_HAVE_V4L2)
87 bool face_found = face_detector.detect(I);
91 bool face_found = face_detector.detect(frame);
98 std::ostringstream text;
99 text <<
"Found " << face_detector.getNbObjects() <<
" face(s)";
101 for (
size_t i = 0; i < face_detector.getNbObjects(); i++) {
102 vpRect bbox = face_detector.getBBox(i);
105 "Message: \"" + face_detector.getMessage(i) +
"\"",
vpColor::red);
static const vpColor green
Display for windows using GDI (available on any windows 32 platform).
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
static void display(const vpImage< unsigned char > &I)
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)
static void flush(const vpImage< unsigned char > &I)
static void displayRectangle(const vpImage< unsigned char > &I, const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
error that can be emited by ViSP classes.
const char * getMessage() const
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
unsigned int getHeight() const
Defines a rectangle in the plane.
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
void setDevice(const std::string &devname)
void acquire(vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()