c++ - openCV face detection opencv_core2410d.pdb error -
i trying out face detection using opencv
, pretty new opencv
.
here's code:
#include <opencv2/core/core.hpp> #include <opencv2/contrib/contrib.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <opencv2/objdetect/objdetect.hpp> #include <iostream> #include <fstream> #include <sstream> using namespace cv; using namespace std; 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 given, please check 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[]) { string fn_haar = "haarcascade_frontalface_alt2.xml"; string fn_csv = "reader.txt"; int deviceid = 0; // these vectors hold images , corresponding labels: 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; // nothing more can exit(1); } int im_width = images[0].cols; int im_height = images[0].rows; ptr<facerecognizer> model = createfisherfacerecognizer(); model->train(images, labels); cascadeclassifier haar_cascade; haar_cascade.load(fn_haar); videocapture cap(deviceid); if (!cap.isopened()) { cerr << "capture device id " << deviceid << "cannot opened." << endl; return -1; } mat frame; while (true) { cap >> frame; mat original = frame.clone(); mat gray; cvtcolor(original, gray, cv_bgr2gray); vector< rect_<int> > faces; haar_cascade.detectmultiscale(gray, faces); (int = 0; < 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); } namedwindow("face_recognizer", 1); imshow("face_recognizer", original); char key = (char)waitkey(20); if (key == 27) break; } return 0; }
and here's reader.txt file
c:\users\hitanshu dhawan\documents\visual studio 2013\projects\consoleapplication21\consoleapplication21\obama\obama1.jpg;0 c:\users\hitanshu dhawan\documents\visual studio 2013\projects\consoleapplication21\consoleapplication21\obama\obama2.jpg;0
now, problem code not working , shows error "exception @ memory location" , "integer division zero" , "opencv_core2410d.pdb not loaded"...
i've tried many ways such adding different lib in linker > input
. i've checked microsoft symbol servers. .xml
, .csv
files copied application folder!
here screenshots:
Comments
Post a Comment