1 #include <visp3/core/vpConfig.h>
3 #include <visp3/gui/vpDisplayGDI.h>
4 #include <visp3/gui/vpDisplayOpenCV.h>
5 #include <visp3/gui/vpDisplayX.h>
6 #include <visp3/detection/vpDetectorFace.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)
15 std::string opt_face_cascade_name =
"./haarcascade_frontalface_alt.xml";
16 unsigned int opt_device = 0;
17 unsigned int opt_scale = 2;
19 for (
int i=0; i<argc; i++) {
20 if (std::string(argv[i]) ==
"--haar")
21 opt_face_cascade_name = std::string(argv[i+1]);
22 else if (std::string(argv[i]) ==
"--device")
23 opt_device = (
unsigned int)atoi(argv[i+1]);
24 else if (std::string(argv[i]) ==
"--scale")
25 opt_scale = (
unsigned int)atoi(argv[i+1]);
26 else if (std::string(argv[i]) ==
"--help") {
27 std::cout <<
"Usage: " << argv[0] <<
" [--haar <haarcascade xml filename>] [--device <camera device>] [--scale <subsampling factor>] [--help]" << std::endl;
35 #if defined(VISP_HAVE_V4L2)
37 std::ostringstream device;
38 device <<
"/dev/video" << opt_device;
42 #elif defined(VISP_HAVE_OPENCV)
43 cv::VideoCapture cap(opt_device);
44 # if (VISP_HAVE_OPENCV_VERSION >= 0x030000)
45 int width = (int)cap.get(cv::CAP_PROP_FRAME_WIDTH);
46 int height = (int)cap.get(cv::CAP_PROP_FRAME_HEIGHT);
47 cap.set(cv::CAP_PROP_FRAME_WIDTH, width/opt_scale);
48 cap.set(cv::CAP_PROP_FRAME_HEIGHT, height/opt_scale);
50 int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);
51 int height = 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);
56 std::cout <<
"Failed to open the camera" << std::endl;
65 #if defined(VISP_HAVE_X11)
67 #elif defined(VISP_HAVE_GDI)
69 #elif defined(VISP_HAVE_OPENCV)
80 #if defined(VISP_HAVE_V4L2)
82 bool face_found = face_detector.
detect(I);
86 bool face_found = face_detector.
detect(frame);
93 std::ostringstream text;
94 text <<
"Found " << face_detector.
getNbObjects() <<
" face(s)";
97 std::vector<vpImagePoint> p = face_detector.
getPolygon(i);
void acquire(vpImage< unsigned char > &I)
static bool getClick(const vpImage< unsigned char > &I, bool blocking=true)
void setCascadeClassifierFile(const std::string &filename)
static void convert(const vpImage< unsigned char > &src, vpImage< vpRGBa > &dest)
Display for windows using GDI (available on any windows 32 platform).
static void displayText(const vpImage< unsigned char > &I, const vpImagePoint &ip, const std::string &s, const vpColor &color)
Use the X11 console to display images on unix-like OS. Thus to enable this class X11 should be instal...
void setDevice(const std::string &devname)
error that can be emited by ViSP classes.
size_t getNbObjects() const
static const vpColor green
static void flush(const vpImage< unsigned char > &I)
VISP_EXPORT double measureTimeMs()
bool detect(const vpImage< unsigned char > &I)
std::vector< std::vector< vpImagePoint > > & getPolygon()
static void display(const vpImage< unsigned char > &I)
The vpDisplayOpenCV allows to display image using the OpenCV library. Thus to enable this class OpenC...
const char * getMessage(void) const
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)
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
Class that is a wrapper over the Video4Linux2 (V4L2) driver.
std::string & getMessage(size_t i)
unsigned int getHeight() const
Defines a rectangle in the plane.
vpRect getBBox(size_t i) const
static void setTitle(const vpImage< unsigned char > &I, const std::string &windowtitle)