0

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.

Community
  • 1
  • 1
Daniella
  • 1
  • 2
  • Your example code has your `imread` code *commented out*. – Dai Dec 03 '16 at 13:33
  • 1
    The code that you provide seems to run fine for me on Linux, so I can't reproduce the error. However `if (!img.size)` is not a valid way of checking if the image is empty (it will never enter the if statement), a better way is to use `if (img.empty())`. – Morris Franken Dec 03 '16 at 14:08
  • Possible duplicate of [openCV program compile error "libopencv\_core.so.2.4: cannot open shared object file: No such file or directory" in ubuntu 12.04](https://stackoverflow.com/questions/12335848/opencv-program-compile-error-libopencv-core-so-2-4-cannot-open-shared-object-f) – Armali Mar 16 '18 at 10:55

0 Answers0