Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <opencv2/core/core.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <opencv2/objdetect/objdetect.hpp>
- #include <iostream>
- using namespace std;
- using namespace cv;
- const String haarcascade_face = "haarcascade_frontalface_alt2.xml";
- const String window_name_original = "OpenCV Demo Camera Face Detection - Original";
- const String window_name = "OpenCV Demo Camera Face Detection";
- int main(int, char**)
- {
- Mat frame;
- VideoCapture capture;
- CascadeClassifier cascade;
- if(! cascade.load(haarcascade_face))
- {
- cout << "Could not open the Haar Cascade file!" << endl;
- return -1;
- }
- if(! capture.open(0))
- {
- cout << "Could not open or find the camera!" << endl;
- return -1;
- }
- namedWindow(window_name, CV_WINDOW_AUTOSIZE);
- namedWindow(window_name_original, CV_WINDOW_AUTOSIZE);
- for(;;)
- {
- capture >> frame;
- if(! frame.data) break;
- imshow(window_name_original, frame);
- vector<Rect> faces;
- cascade.detectMultiScale(
- frame,
- faces,
- 1.1,
- 3,
- 0,
- Size(20, 20));
- vector<Rect>::const_iterator i;
- for(i = faces.begin(); i != faces.end(); i++)
- {
- rectangle(frame, Point(i->x, i->y), Point(i->x + i->width, i->y + i->height), CV_RGB(255, 0, 0), 2);
- }
- imshow(window_name, frame);
- char c = cvWaitKey(1);
- if(c == 27) break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement