Raspberry Pi Segmentation Fault Caused by detectMultiScale [closed]
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;
}
In
img
you have aMat
that contains moreMat
s? or what isimg[i]
?img[i] is a .JPG image
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?
@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.
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 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.
And you are sure that the image is read correctly? Start by adding a check there.
@ 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)
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.
@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.