Ask Your Question

pedrohenriques's profile - activity

2014-11-24 20:11:39 -0600 asked a question Trouble with running UFaceDetect sample Project

Whenever I debug the UFaceDetect project normally it runs and immediately closes. When I start without debugging, it brings up the cmd window but when I press a button, the window closes. How should I fix this, and how should I go about things after, what do I type for the the face detection to begin? I am new to OpenCV so I do not know much about running things.

2014-11-24 18:54:38 -0600 asked a question OpenCV_VideoIO300d.dll is Missing from your Computer

I attempted to a debug the "ufacedetect.cpp" sample project from the OpenCV 3.0 source folder but it gave me an error saying opencv_videoio300d.dll is missing from this computer. I checked the bin folder and it was right, there is no such .dll file. What do I do?

2014-11-24 18:49:00 -0600 commented question Open Source Code Error: Expected Declaration before '}' token

Which headers do I have to include? I used eigen.hpp and core.hpp

2014-11-23 20:14:06 -0600 asked a question Open Source Code Error: Expected Declaration before '}' token

I am using the source code from this tutorial: http://docs.opencv.org/trunk/modules/contrib/doc/facerec/tutorial/facerec_video_recognition.html and when I try to run the code after fixing a few paths, an error comes up saying there is an "Expected Declaration before'}' token. I looked through the code to find extra brackets but I could not find any. How should I fix this? (Edited Code below)

static void read_csv(const string& filename, vector<Mat>& images, vector<int>& labels, char separator = ';') {
    std::ifstream file(filename.c_str(), ifstream::in);
    if (!file) {
        string error_message = "No valid input file was given, please check the given filename.";
        CV_Error(CV_StsBadArg, error_message);
    }
    string line, path, classlabel;
    while (getline(file, line)) {
        stringstream liness(line);
        getline(liness, path, separator);
        getline(liness, classlabel);
        if(!path.empty() && !classlabel.empty()) {
            images.push_back(imread(path, 0));
            labels.push_back(atoi(classlabel.c_str()));
        }
    }
}

int main(int argc, const char *argv[]) {
    if (argc != 4) {
        cout << "usage: " << argv[0] << " <C:/OpenCV/sources/data/haarcascades/haarcascade_frontalface_alt_tree> <C:/OpenCV/csv.ext> <USB/VID_04F2&PID_B446&MI_00/6&2EB9C0D0&0&0000>" << endl;
        cout << "\t <C:/OpenCV/sources/data/haarcascades/haarcascade_frontalface_alt_tree>" << endl;
        cout << "\t <C:/OpenCV/csv.ext>" << endl;
        cout << "\t <USB/VID_04F2&PID_B446&MI_00/6&2EB9C0D0&0&0000>" << endl;
        exit(1);
    }
    string fn_haar = string(argv[1]);
    string fn_csv = string(argv[2]);
    int deviceId = atoi(argv[3]);
    vector<Mat> images;
    vector<int> labels;

    try {
        read_csv(fn_csv, images, labels);
    } catch (cv::Exception& e) {
        cerr << "Error opening file \"" << fn_csv << "\". Reason: " << e.msg << endl;

        exit(1);
    }

    int im_width = images[0].cols;
    int im_height = images[0].rows;

    Ptr<FaceRecognizer> model = createEigenFaceRecognizer();
    model->train(images, labels);

    CascadeClassifier haar_cascade;
    haar_cascade.load(fn_haar);
    VideoCapture cap(deviceId);
    if(!cap.isOpened()) {
        cerr << "Capture Device ID " << deviceId << "cannot be opened." << endl;
        return -1;
    }
    Mat frame;
    for(;;) {
        cap >> frame;
        Mat original = frame.clone();
        Mat gray;
        cvtColor(original, gray, CV_BGR2GRAY);
        vector< Rect_<int> > faces;
        haar_cascade.detectMultiScale(gray, faces);
        for(int i = 0; i < faces.size(); i++) {
            Rect face_i = faces[i];
            Mat face = gray(face_i);
            Mat face_resized;
            cv::resize(face, face_resized, Size(im_width, im_height), 1.0, 1.0, INTER_CUBIC);
            int prediction = model->predict(face_resized);
            rectangle(original, face_i, CV_RGB(0, 255,0), 1);
            string box_text = format("Prediction = %d", prediction);
            int pos_x = std::max(face_i.tl().x - 10, 0);
            int pos_y = std::max(face_i.tl().y - 10, 0);
            putText(original, box_text, Point(pos_x, pos_y), FONT_HERSHEY_PLAIN, 1.0, CV_RGB(0,255,0), 2.0);
        }
        imshow("face_recognizer", original);
        char key = (char) waitKey(20);
        if(key == 27)
            break;
    }
    return 0;
}