I have written some C++ code using OpenCV on a Windows computer, built it and checked that everything works properly.
Now I have cloned the project to a Raspberry Pi and am using Code Blocks on the rPi to build my project. A segmentation fault occurs when I use imread
, copyTo
, clone
.
The exact same code worked on my Windows PC. I've searched to see if there could be problems with the code, but it doesn't seem so. I have installed all the required packages as shown in this tutorial. I have also followed the steps in the post, for setting up CodeBlocks with OpenCV.
My main.cpp contains:
int main(int argc, char* argv[])
{
Mat img;
Mat kernel;
Webcam cam;
//cam.getImage(img);
img = imread("test3.png");
if (!img.size) return 0;
Mat emptyImg(img.rows, img.cols, CV_8UC1, Scalar(0, 0, 0));
Mat contourImg(img.rows, img.cols, img.type(), Scalar(0, 0, 0));
Mat squareImg = emptyImg.clone();
kernel = Mat::ones(3, 3, CV_32F);
Mat processed = img.clone(); // Segmentation fault here
cvtColor(processed, processed, CV_BGR2GRAY);
//GaussianBlur(processed, processed, Size(5,5), 1, 1);
}
edit: I fixed the problem by following the link.