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.
非常重要:如果我删除了第二行(对cvCreateImage的调用),它可以正常工作。
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)
我正在使用opencv 2.3和MacOs 10.8.5, gcc (i686-apple-darwin9-gcc-4.2.1 (gcc) 4.2.1 (Apple Inc. build 5566)
1 个解决方案
#1
1
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.
不验证IplImage *src = cvLoadImage(“/tmp/Name”)。tiff”,CV_LOAD_IMAGE_COLOR);成功了。我假设它找不到文件或解码它或其他东西。一切都是糟糕的工程实践的结果。
$ 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.
我在Mac上工作。
#1
1
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.
不验证IplImage *src = cvLoadImage(“/tmp/Name”)。tiff”,CV_LOAD_IMAGE_COLOR);成功了。我假设它找不到文件或解码它或其他东西。一切都是糟糕的工程实践的结果。
$ 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.
我在Mac上工作。