Re: [問題] 用xcode寫c++,compile過,run時出現bu …
※ 引述《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
→
10/05 18:56, , 1F
10/05 18:56, 1F
推
10/06 05:37, , 2F
10/06 05:37, 2F
→
10/06 13:12, , 3F
10/06 13:12, 3F
→
10/06 13:13, , 4F
10/06 13:13, 4F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):
MacDev 近期熱門文章
PTT數位生活區 即時熱門文章
10
113