Ask Your Question
0

Opencv 3.0.0 alpha build error with library opencv_contrib

asked 2014-11-02 04:45:07 -0500

updated 2020-10-24 03:14:16 -0500

I'm developing a project about face recognition.

And i know the library for face recognition is opencv_contrib. And this is my source code.

#include "opencv2/objdetect.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/core.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <iostream>
#include <fstream>
#include <sstream>
#include <stdio.h>
using namespace std;
using namespace cv;

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() {
String face_cascade_name = "face.xml";
String csvPath = "/home/longnhkse60984/csv.ext";
String eye_cascade_name = "haarcascade_eye.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;
String window_name = "Capture - Face detection";
vector<Mat> images;
vector<int> labels;
try {
    read_csv(csvPath, images, labels);
} catch (cv::Exception& e) {
    cerr << "Error opening file \"" << csvPath << "\". Reason: " << e.msg
            << endl;
    // nothing more we can do
    exit(1);
}
int im_width = images[0].cols;
int im_height = images[0].rows;
// Create a FaceRecognizer and train it on the given images:
Ptr<FaceRecognizer> model = createFisherFaceRecognizer();
model->train(images, labels);
//CascadeClassifier haar_cascade;
face_cascade.load(face_cascade_name);
Mat frame = imread("aaa.jpg");
Mat original = frame.clone();
vector<Rect> faces;
Mat frame_gray;

cvtColor(original, frame_gray, COLOR_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);

//-- Detect faces
face_cascade.detectMultiScale(frame_gray, faces, 1.1, 2,
        CASCADE_FIND_BIGGEST_OBJECT | CASCADE_DO_ROUGH_SEARCH,
        Size(30, 30));
Mat face = frame_gray(faces[0]);
Mat face_resized;
resize(face, face_resized, Size(im_width,im_height),1.0,1.0,INTER_CUBIC);
int prediction = model->predict(face_resized);
cout << prediction;
// That's it for learning the Face Recognition model. You now
// need to create the classifier for the task of Face Detection.
// We are going to use the haar cascade you have specified in the
// command line arguments:
//
waitKey(0);
return 0;}

When i build this i have received errors of opencv_contrib. Please help me.

Opencv_contrib Error

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2014-11-02 06:09:18 -0500

berak gravatar image
  • go here
  • take your time with the README.
  • clone/download the contrib repo
  • add the path to it to your cmake settings of the main opencv repo.
  • rebuild your main opencv repo as you did before, starting with cmake.
  • make install will copy all headers/libs/so's to the folder you specified by CMAKE_INSTALL_PREFIX
  • include "opencv2/face.hpp" instead of the old contrib headers, link to opencv_face instead of opencv_contrib
edit flag offensive delete link more

Comments

1

Thanks for your help!

nicknguyen071093 gravatar imagenicknguyen071093 ( 2014-11-08 05:21:45 -0500 )edit

Question Tools

Stats

Asked: 2014-11-02 04:45:07 -0500

Seen: 638 times

Last updated: Nov 02 '14