"bus error" with (very) simple opencv program (with Mac Os X)

I know that "bus error" is often associated with errosr programming. But I really do not see such an error in a three-line program:

int main(int argc, char** argv) { IplImage *src = cvLoadImage("/tmp/Name.tiff", CV_LOAD_IMAGE_COLOR); IplImage* res = cvCreateImage( cvSize( 2, 2), IPL_DEPTH_8U, 3 ); cvSaveImage("/tmp/image.tiff", src); return 0; } 

Compile the following command:

  gcc -I / Library / Frameworks / OpenCV.framework / Versions / A / Headers / usr / local / lib / libopencv_ * test.c 

Execution gives a bus error .

Very important: if I delete the second line (call cvCreateImage ), it works without problems.

I am using opencv 2.3 and MacOs 10.8.5, gcc (i686-apple-darwin9-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5566)

+4
source share
1 answer

You cannot check if IplImage *src = cvLoadImage("/tmp/Name.tiff", CV_LOAD_IMAGE_COLOR); . I assume that he cannot find the file or decode it or something else. Everything else is the result of bad engineering practice.

 $ cat src/bus.cpp #include <opencv2/opencv.hpp> int main(int argc, char** argv) { IplImage *src = cvLoadImage("/tmp/Name.tiff", CV_LOAD_IMAGE_COLOR); if(src==NULL) { printf("There is no /tmp/Name.tiff\n"); exit(1); } IplImage* res = cvCreateImage( cvSize( 2, 2), IPL_DEPTH_8U, 3 ); cvZero(res); cvSaveImage("/tmp/Name.tiff", src); return 0; } $ $ convert ~/ScanImage001.png /tmp/Name.tiff $ ./bus $ 

works for me on a mac.

+1
source

Source: https://habr.com/ru/post/1411095/


All Articles