看板 MacDev 關於我們 聯絡資訊
※ 引述《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
zonble:Xcode 會把程式放在 build/Debug 下吧? 10/05 18:56
seruziu:好像檔案放到專案裡面應該就好了。取得完整路徑比較保險。 10/06 05:37
Gsus:我發現我把檔案放在我的使用者資料夾下面就好了@@ 10/06 13:12
Gsus:是要設定working space之類的嗎? 10/06 13:13