One way I suggest to solve your issue loading the cascades is downloading them, putting them in the same directory as your cpp program and hardcoding their filenames into your program.
You can find and downlaod the cascades used in the tutorial here.
Download these and move them into the directory containing your cpp file. Then delete these lines:
CommandLineParser parser( argx, arg,c,
"{help h||}"
"{face_cascade|../../data/haarcascades/haarcascade_frontalface_alt.xml|}"
"{eyes_cascade|../../data/haarcascades/haarcascade_eye_tree_eyeglasses.xml|}");
parser.about("\n this program demonstrates using face and ete detection in a video stream\n");
parser.printMessage();
face_cascade_name=parser.get<String>("face_cascade_name");
eyes_cascade_name=parser.get<String>("eyes_cascade");
And add these lines in their place:
face_cascade_name = "haarcascade_frontalface_default.xml";
eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
You now will no longer need to use command line arguments. You can add the CommandLineParser and need for arguments back (if you want) once you have got your program working with the hard coded filenames.
Your code "old_main.cpp" had several errors. I fixed them, so please carefully look and see the changes. Below is code that should work, provided you download the files and add them to the directory which contains the cpp file.
(P.S. If you are curious how the haar cascades work, you can read the seminal Viola-Jones paper here or a wiki page summarizing/explaining it here. If you are curious about the meaning of (and how to set) the detectMultiScale parameters, there is a nice explanation here).
//old_main.cpp
//https://github.com/ellisa4/ASL-Interpreter/tree/master/src/main/cpp
#include <iostream>
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
using namespace cv;
using namespace std;
void detectAndDisplay(Mat frame);
String face_cascade_name, eyes_cascade_name;
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
String window_name = "Capture - Face detection";
int main(int argc, const char** argv)
{
face_cascade_name = "haarcascade_frontalface_default.xml";
eyes_cascade_name = "haarcascade_eye_tree_eyeglasses.xml";
VideoCapture stream1;
Mat frame;
//Step 1) Load the cascades
if (!face_cascade.load(face_cascade_name))
{
cout << "error loading face cascade" << endl;
return -1;
}
if (!eyes_cascade.load(eyes_cascade_name))
{
cout << "error loading eyes cascade" << endl;
return -1;
}
//Step 2) read in video stream
stream1.open(0);
if (!stream1.isOpened())
{
cout << "can not open camera" << endl;
return -1;
}
while (stream1.read(frame))
{
if (frame.empty())
{
cout << "frame is empty" << endl;
break;
}
//Step 3) Apply the classifier to the frame
detectAndDisplay(frame);
if (waitKey(10) == 27)
{
break;
}
}
return 0;
}
void detectAndDisplay(Mat frame)
{
std::vector<Rect> faces;
Mat frame_gray;
cvtColor(frame, frame_gray, COLOR_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
// Detect the faces
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(60, 60));
for (size_t i = 0; i< faces.size(); ++i)
{
Point center(faces[i].x + faces[i].width / 2, faces[i].y + faces[i].height / 2);
ellipse(frame, center, Size(faces[i].width / 2, faces[i].height / 2), 0, 0, 360, Scalar(255, 0, 255), 4, 8, 0);
Mat faceROI = frame_gray(faces[i]);
std::vector<Rect> eyes;
//in each face, find eye
eyes_cascade.detectMultiScale(faceROI, eyes, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30 ...
(more)