Quantcast
Viewing latest article 10
Browse Latest Browse All 53

Face Detection Error OpenCV 3.1.0

I am trying to get started in opneCv and get learning but am running into problems in regards to face detection the code I have should detect faces I believe my linkages are fine can someone please help me understand what I'm doing wrong? full code in both main.cpp and project.pro file is provided below **App Output:** *starting /Users/admin/Desktop/build-Origin-Desktop_Qt_5_6_0_clang_64bit-Debug/Origin.app/Contents/MacOS/Origin... OpenCV Error: Assertion failed (!empty()) in detectMultiScale, file /Users/admin/Desktop/opencv-3.1.0/modules/objdetect/src/cascadedetect.cpp, line 1639 Cleaned up camera. Unable to initiate camera /Users/admin/Desktop/build-Origin-Desktop_Qt_5_6_0_clang_64bit-Debug/Origin.app/Contents/MacOS/Origin exited with code 0* **Compile Output:** *10:46:41: Running steps for project Origin... 10:46:41: Configuration unchanged, skipping qmake step. 10:46:41: Starting: "/usr/bin/make" /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -c -pipe -stdlib=libc++ -g -std=gnu++11 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wall -W -fPIC -DQT_QML_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../Origin -I. -I/usr/local/include -I../../Qt/5.6/clang_64/lib/QtWidgets.framework/Headers -I../../Qt/5.6/clang_64/lib/QtGui.framework/Headers -I../../Qt/5.6/clang_64/lib/QtCore.framework/Headers -I. -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/OpenGL.framework/Headers -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/System/Library/Frameworks/AGL.framework/Headers -I. -I../../Qt/5.6/clang_64/mkspecs/macx-clang -F/Users/admin/Qt/5.6/clang_64/lib -o main.o ../Origin/main.cpp /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -headerpad_max_install_names -stdlib=libc++ -Wl,-syslibroot,/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -mmacosx-version-min=10.7 -Wl,-rpath,/Users/travishaycock/Qt/5.6/clang_64/lib -o Origin.app/Contents/MacOS/Origin main.o mainwindow.o moc_mainwindow.o -F/Users/admin/Qt/5.6/clang_64/lib -L/usr/local/lib -lopencv_core -lopencv_highgui -lopencv_videoio -lopencv_imgproc -lopencv_objdetect -framework QtWidgets -framework QtGui -framework QtCore -framework OpenGL -framework AGL 10:46:43: The process "/usr/bin/make" exited normally. 10:46:43: Elapsed time: 00:02.* **Main.cpp File** #include "mainwindow.h" #include #include #include #include #include #include #include #include #include #include using namespace cv; using namespace std; CascadeClassifier face_cascade, eyes_cascade; String window_name = "Face Detection"; /** * Detects faces */ void detectFaces(Mat frame) { std::vector faces; Mat frame_gray; cvtColor(frame, frame_gray, COLOR_BGR2GRAY); // Convert to gray scale equalizeHist(frame_gray, frame_gray); // Equalize histogram // Detect faces face_cascade.detectMultiScale(frame_gray, faces, 1.1, 3, 0|CASCADE_SCALE_IMAGE, Size(30, 30)); // Iterate over all of the faces for(size_t i = 0; i < faces.size(); i++) { // Find center of faces Point center(faces[i].x + faces[i].width/2, faces[i].y + faces[i].height/2); Mat face = frame_gray(faces[i]); std::vector eyes; // Try to detect eyes, inside each face eyes_cascade.detectMultiScale(face, eyes, 1.1, 2, 0 |CASCADE_SCALE_IMAGE, Size(30, 30) ); // Check to see if eyes inside of face, if so, draw ellipse around face if(eyes.size() > 0) ellipse(frame, center, Size(faces[i].width/2, faces[i].height/2), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 ); } imshow( window_name, frame ); } int main(int argc, char *argv[]){ QApplication a(argc, argv); MainWindow w; // cam code try{ VideoCapture cap(0); // Open default camera Mat frame; // Load preconstructed classifier face_cascade.load("haarcascade_frontalface_alt.xml"); while(cap.read(frame)) { detectFaces(frame); // Call function to detect faces if( waitKey(30) >= 0) // Pause key break; } return 0; }catch(Exception ex){ std::cout << "Unable to initiate camera" << std::endl; } //end cam code w.show(); return a.exec(); } **Project.Pro File** QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Origin TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp LIBS += \ -L/usr/local/lib \ -lopencv_core \ -lopencv_highgui \ -lopencv_videoio \ -lopencv_imgproc \ -lopencv_objdetect INCLUDEPATH += \ /usr/local/include HEADERS += mainwindow.h FORMS += mainwindow.ui

Viewing latest article 10
Browse Latest Browse All 53

Trending Articles