Raspberry Pi Segmentation Fault Caused by detectMultiScale [closed]

asked 2014-08-11 06:32:52 -0600

sgccarey gravatar image

updated 2014-08-11 08:03:39 -0600

I have some code tested and working on my Linux Mint desktop which fails when ran on my RPi type B. Specifically, it is the line:

hog.detectMultiScale(img[i],people,0,Size(4,4),Size(0,0));

That is causing a segmentation fault, the code runs fine when it is removed (although obviously this renders the app useless).

What could be causing this? Is it the memory limitation of the Pi? I've tried running it with very small images, to no avail.

Any help appreciated

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <string>
#include <iostream>
#include <iomanip>
#include <math.h>

using namespace cv;
using namespace std;

#define OUTPUTDETECTIONS

  int main( int argc, char ** argv )
  {
   string aFirstFile = std::string(argv[1]);

   cout << "Test CVHumanTrigger" << aFirstFile << endl;

   Mat img[1];

   img[0] = imread(aFirstFile);

   cv::HOGDescriptor hog;
   vector<cv::Rect> people;

   hog.setSVMDetector(hog.getDefaultPeopleDetector());
   hog.detectMultiScale(img[0],people,0,Size(256,256),Size(0,0));

   cout <<"end test" << endl;

   return 0;
}
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2014-08-12 03:19:01.970871

Comments

In img you have a Mat that contains more Mats? or what is img[i]?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-08-11 07:04:48 -0600 )edit

img[i] is a .JPG image

sgccarey gravatar imagesgccarey ( 2014-08-11 07:14:34 -0600 )edit
1

First guess and probably the right one, you are starting with lower scale 4x4 until window size which is quite a large scale space. Probably your onboard memory of the raspberri pi is not large enough to contain it completely. Can you check the memory footprint of your linux mint implementation?

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-11 07:17:23 -0600 )edit

@steven Thanks for your answer, but I've tried much higher starting values for winStride and still have the same fault. Using ps -aux, the process seems to use about 77MB of memory, which should be within the Pi's capabilities?

I've included some test code above.

sgccarey gravatar imagesgccarey ( 2014-08-11 07:55:50 -0600 )edit

Your application is not finding people on this image, so people is empty, are you trying to access an element of it without verifying if it is empty?

thdrksdfthmn gravatar imagethdrksdfthmn ( 2014-08-11 08:07:55 -0600 )edit

@thdrksdfthmn this is just a stripped down version of the program, it's just to test that particular line. As I said, the full version works absolutely fine on my desktop.

sgccarey gravatar imagesgccarey ( 2014-08-11 08:30:26 -0600 )edit

And you are sure that the image is read correctly? Start by adding a check there.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-11 08:42:51 -0600 )edit

@ Steven yes, the image reads fine. In the full version the image is loaded, modified, scanned for people and then saved as a new file. These all work with the offending line commented out (although no people are detected, obviously)

sgccarey gravatar imagesgccarey ( 2014-08-11 08:47:46 -0600 )edit
1

Found your problem! Your command is wrong, given the sourcecode. It seems you are passing the parameters of the standard cascade classifier detectMultiScale ... I know that HOGDescriptor for CPU is not documented for the moment ... which leads to these situations. Try supplying the correct parameters and it should work.

StevenPuttemans gravatar imageStevenPuttemans ( 2014-08-11 09:57:13 -0600 )edit

@steven I found the problem, it seems that I had multiple versions of the .so files, including some of the older ones. Cleaned them out and the code runs fine now!

Thank you so much for the answers, and your time.

sgccarey gravatar imagesgccarey ( 2014-08-12 03:05:38 -0600 )edit