简体   繁体   中英

“bus error” with a (very) simple opencv program (with Mac Os X)

I know that "bus error" is often due to a programming errosr. But I really can not see such error in a three lines 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;
} 

I compile with the following:

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

Execution gives bus error .

Very important: if I remove the second line (the call to cvCreateImage ), it works with no problems.

I'm 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)

You do not verify if IplImage *src = cvLoadImage("/tmp/Name.tiff", CV_LOAD_IMAGE_COLOR); succeeded. I assume it fails to find file or decode it or whatever else. Everything rest is just consequence 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 Mac.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM