2011-06-21 16 views
1

私はOpenCVブックで例をしようとしていますが、私はcvCannyに関する部分に行きました。私はそれを使用しようとしていますが、私はまた、この質問に似た別のポストを見てきましたが、私が得たとして、それは私のために助けにはならなかったOpenCV cvCannyメモリ例外

Unhandled exception at 0x75d8b760 in Image_Transform.exe: Microsoft C++ exception: cv::Exception at memory location 0x0011e7a4..

のメモリ例外エラーを取得しておきます毎回同じエラー。どんな助けも大歓迎であり、関数のソースコードは以下にあります。

void example2_4(IplImage* img) 
{ 
// Create windows to show input and ouput images 
cvNamedWindow("Example 2-4 IN", CV_WINDOW_AUTOSIZE); 
cvNamedWindow("Example 2-4 OUT", CV_WINDOW_AUTOSIZE); 

// Display out input image 
cvShowImage("Example 2-4 IN", img); 

// Create an image to hold our modified input image 
IplImage* out = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 3); 

// Do some smoothing 
//cvSmooth(img, out, CV_GAUSSIAN, 3, 3); 

// Do some Edge detection 
cvCanny(img, out, 10, 20, 3); 

// Show the results 
cvShowImage("Example 2-4 OUT", out); 

// Release the memory used by the transformed image 
cvReleaseImage(&out); 

// Wait for user to hit a key then clean up the windows 
cvWaitKey(0); 
cvDestroyWindow("Example 2-4 IN"); 
cvDestroyWindow("Example 2-4 OUT"); 
} 

int main() 
{ 
// Load in an image 
IplImage* img = cvLoadImage("images/00000038.jpg"); 

// Run the transform 
example2_4(img); 

// clean the image from memory 
cvReleaseImage(&img); 

return 0; 
} 
+0

? – karlphillip

+0

私はOpenCV 2.20を使用しています – Seb

答えて

1

元の画像が画面に表示されているかどうかを忘れていますか?

機能の復帰をチェックする必要があるということを人々に伝えるのは、決して疲れません!

は、この関数が成功したかどうどのように伝えることができ、IplImage* img = cvLoadImage("images/00000038.jpg");考えてみましょうか?私が知る限り、あなたが持っているエラーは、cvCanny()が呼び出される前に失敗した関数からのものかもしれません。

とにかく、私は最近code that uses cvCanny to improve circle detectionを掲載しました。あなたはそのコードをチェックし、あなたが何をしているのかを見ることができます。

EDIT

この場合、あなたの問題は、それが唯一のシングルチャンネル画像を取るとき、あなたは3チャンネルの画像としてcvCanny入力と出力に渡しているということです。 Check the docs

無効cvCanny(のconst CvArr *画像、CvArr *エッジ、ダブルTHRESHOLD1、ダブルthreshold2に、int型aperture_size = 3)

Implements the Canny algorithm for edge detection. 
Parameters: 

    * image – Single-channel input image 
    * edges – Single-channel image to store the edges found by the function 
    * threshold1 – The first threshold 
    * threshold2 – The second threshold 
    * aperture_size – Aperture parameter for the Sobel operator (see Sobel) 

ので、変更あなたのコードに:

あなたがOpenCVののバージョンを使用しているところで、
// Create an image to hold our modified input image 
IplImage* out = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); 

// Do some smoothing 
//cvSmooth(img, out, CV_GAUSSIAN, 3, 3); 

IplImage* gray = cvCreateImage(cvGetSize(img), IPL_DEPTH_8U, 1); 
cvCvtColor(img, gray, CV_BGR2GRAY); 

// Do some Edge detection 
cvCanny(gray, out, 10, 20, 3); 
+0

申し訳ありません。私は2つのウィンドウが表示されていると私はcvCannyをコメントする場合、私は画面上の元の画像を取得します。 – Seb

+0

答えが更新されました。問題は修正されました。 – karlphillip

+0

それはトリックでした。助けてくれてありがとう。 – Seb