Ask Your Question

Revision history [back]

Segmentation fault

I wish to learn Open-CV for a project When I compile my program i have no error, but when I execute it, I have :

Segmentation fault (core dumped) here is my code

include "opencv2/objdetect.hpp"

include "opencv2/videoio.hpp"

include "opencv2/highgui.hpp"

include "opencv2/imgproc.hpp"

include <opencv2 core="" core.hpp="">

include <iostream>

include <stdio.h>

using namespace std; using namespace cv; 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 ) { Mat image; CommandLineParser parser(argc, argv, "{help h|}" "{face_cascade|haarcascade_frontalface_alt.xml|}"); cout << "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video stream.\n" "You can use Haar or LBP features.\n\n"; parser.printMessage(); face_cascade_name = parser.get<string>("face_cascade"); VideoCapture capture; Mat frame; if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade\n"); return -1; }; image = imread("a3.bmp", CV_LOAD_IMAGE_COLOR);

//check image valid
if(image.empty()){
    cout << "can't open or read image" << endl;
}else{

    //create windows for display
    namedWindow("OpenCV", WINDOW_AUTOSIZE);
    //show imag in it
 detectAndDisplay( image );
    imshow("OpenCV", image);
    //wating user press any key to finish
    waitKey();
}

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 faces face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30) ); 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] ); } //-- Show what you got imshow( window_name, frame ); }

click to hide/show revision 2
None

updated 2019-01-06 02:38:09 -0600

berak gravatar image

Segmentation fault

I wish to learn Open-CV for a project When I compile my program i have no error, but when I execute it, I have :

Segmentation fault (core dumped) here is my code

include "opencv2/objdetect.hpp"

include "opencv2/videoio.hpp"

include "opencv2/highgui.hpp"

include "opencv2/imgproc.hpp"

include <opencv2 core="" core.hpp="">

include <iostream>

include <stdio.h>

#include "opencv2/objdetect.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <opencv2/core/core.hpp>

#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
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 )
{
Mat image;
CommandLineParser parser(argc, argv,
"{help h|}"
"{face_cascade|haarcascade_frontalface_alt.xml|}");
cout << "\nThis program demonstrates using the cv::CascadeClassifier class to detect objects (Face + eyes) in a video stream.\n"
"You can use Haar or LBP features.\n\n";
parser.printMessage();
face_cascade_name = parser.get<string>("face_cascade");
VideoCapture capture;
Mat frame;
if( !face_cascade.load( face_cascade_name ) ){ printf("--(!)Error loading face cascade\n"); return -1; };
image = imread("a3.bmp", CV_LOAD_IMAGE_COLOR);

CV_LOAD_IMAGE_COLOR);
//check image valid
 if(image.empty()){
  cout << "can't open or read image" << endl;
 }else{
  //create windows for display
 namedWindow("OpenCV", WINDOW_AUTOSIZE);
  //show imag in it
 detectAndDisplay( image );
 imshow("OpenCV", image);
  //wating user press any key to finish
 waitKey();
 }
 return 0;

} void detectAndDisplay( Mat frame ) { std::vector<rect> std::vector<Rect> faces; Mat frame_gray; cvtColor( frame, frame_gray, COLOR_BGR2GRAY ); equalizeHist( frame_gray, frame_gray ); //-- Detect faces face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CASCADE_SCALE_IMAGE, Size(30, 30) ); 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] ); } //-- Show what you got imshow( window_name, frame ); }

}