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";
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 = atoi(argv[i+1]);
24 else if (std::string(argv[i]) ==
"--help") {
25 std::cout <<
"Usage: " << argv[0] <<
" [--haar <haarcascade xml filename>] [--device <camera device>] [--help]" << std::endl;
33 #if defined(VISP_HAVE_V4L2)
35 std::ostringstream device;
36 device <<
"/dev/video" << opt_device;
40 #elif defined(VISP_HAVE_OPENCV)
41 cv::VideoCapture cap(opt_device);
43 std::cout <<
"Failed to open the camera" << std::endl;
52 #if defined(VISP_HAVE_X11)
54 #elif defined(VISP_HAVE_GDI)
56 #elif defined(VISP_HAVE_OPENCV)
67 #if defined(VISP_HAVE_V4L2)
76 bool face_found = face_detector.
detect(I);
79 std::ostringstream text;
80 text <<
"Found " << face_detector.
getNbObjects() <<
" face(s)";
83 std::vector<vpImagePoint> p = face_detector.
getPolygon(i);
const char * getMessage(void)
void acquire(vpImage< unsigned char > &I)
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)
Define the X11 console to display images.
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)
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.
virtual void setTitle(const char *title)=0
virtual void displayRectangle(const vpImagePoint &topLeft, unsigned int width, unsigned int height, const vpColor &color, bool fill=false, unsigned int thickness=1)=0
void setScale(unsigned scale=vpV4l2Grabber::DEFAULT_SCALE)
VISP_EXPORT double measureTimeMs()
Class for the Video4Linux2 video device.
std::string & getMessage(size_t i)
unsigned int getHeight() const
Defines a rectangle in the plane.
virtual bool getClick(bool blocking=true)=0
vpRect getBBox(size_t i) const