作者Gsus (肉元)
看板MacDev
标题Re: [问题] 用xcode写c++,compile过,run时出现bu …
时间Sun Oct 5 10:14:53 2008
※ 引述《Gsus (肉元)》之铭言:
: ※ 引述《Gsus (肉元)》之铭言:
: : 如题
: : 下面是我的程式码
: : 程式都build过了,没有错误讯息,但是在执行时却出现bus error的讯息
: : 经过测试发现问题出在
: : output = cvCreateImage(cvGetSize(src),src->depth,src->nChannels);
: : 这一行,我找不太出问题出在哪里
: : 请问有高手能狗帮帮忙吗?
: : #include <iostream>
: : #include <OpenCV/cv.h>
: : #include <OpenCV/cxcore.h>
: : #include <OpenCV/highgui.h>
: : using namespace std;
: : void setPixel(IplImage* src,int x,int y,char B);
: : void getPixel(IplImage* src,int x,int y,char* B);
: : int main (int argc, char * const argv[]) {
: : std::cout << "Hello, World!\n";
: : IplImage* src;
: : IplImage* output;
: : src=cvLoadImage("lena.bmp",0);
: : char B;
: : std::cout << "test\n";
: : output = cvCreateImage(cvGetSize(src),src->depth,src->nChannels);
: : }
: : void setPixel(IplImage* src,int x,int y,char B){
: : int index = y*src->widthStep+x*src->nChannels;
: : src->imageData[index] = B;
: : }
: : void getPixel(IplImage* src,int x,int y,char* B){
: : int index = y*src->widthStep+x*src->nChannels;
: : *B = src->imageData[index];
: : }
: 我发现我把
: output = cvCreateImage(cvGetSize(src),src->depth,src->nChannels);
: 改成
: output = cvCreateImage(cvSize(320,240),1,1);
: 就没出错了
: 但是假如我又改成
: output = cvCreateImage(cvSize(src->width,240),1,1);
: 执行时bus error又出现了
: why...
我将cvLoadImage的参数改了一下
把原本的"lena.bmp"改为绝对路径"/Users/Gsus/desktop/test/lena.bmp"
就成功了
所以问出在他的确没有读到image
但是一般直接只写档名就代表在同一个资料夹下面的档案不是吗
有谁有遇过类似的问题吗
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.168.34.69
1F:→ zonble:Xcode 会把程式放在 build/Debug 下吧? 10/05 18:56
2F:推 seruziu:好像档案放到专案里面应该就好了。取得完整路径比较保险。 10/06 05:37
3F:→ Gsus:我发现我把档案放在我的使用者资料夹下面就好了@@ 10/06 13:12
4F:→ Gsus:是要设定working space之类的吗? 10/06 13:13