2

私は 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;
}
4

1 に答える 1

2

元の画像が画面に表示されているのを見ることができるかどうかを言うのを忘れていました.

関数の戻り値をチェックすることは必須であると人々に伝えるのに飽きることはありません!

この関数IplImage* img = cvLoadImage("images/00000038.jpg");が成功したかどうかをどのように判断できますか? 私が知る限り、あなたが抱えているエラーは、関数cvCanny()が呼び出される前に失敗したことが原因である可能性があります。

とにかく、私は最近cvCanny を使用して円の検出を改善するコードを投稿しました。そのコードをチェックして、何が違うのかを確認できます。

編集

この場合の問題は、cvCanny の入力と出力を 3 チャンネルの画像として渡していることです。ドキュメントを確認してください

void cvCanny(const CvArr* 画像、CvArr* エッジ、二重しきい値 1、二重しきい値 2、int 開口サイズ = 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)

したがって、コードを次のように変更します。

// 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);
于 2011-06-21T14:20:03.973 に答える