0

我想使用 C API 在 OpenCV 中分别在不同窗口中显示多个图像。以下是我的代码,我在其中执行了一个 for 循环以多次显示相同的图像,直到循环旋转。谁能告诉我为什么我的代码在只显示第一张图片后就崩溃了?以下是我的循环代码:

for(x = 0; x <= 5;x++)
{ 

     IplImage* dst = cvCreateImage(cvSize(src->width, src->height), src->depth, 3);
     IplImage* dstRGB[3];

     for (int i = 0; i < 3; i++)
     {
         rgb[i] = cvCreateImage(cvSize(src->width, src->height), src->depth, 1);
         dstRGB[i] = cvCreateImage(cvSize(src->width, src->height), src->depth, 1);
     }

     cvSplit(src, rgb[0], rgb[1], rgb[2], NULL);

     for (int i = 0; i < 3; i++)
     {
         cvFilter2D(rgb[i], dstRGB[i], rgb2);
     }

     cvReleaseMat(&rgb2);
     cvMerge(dstRGB[0], dstRGB[1], dstRGB[2], NULL, dst);

     cvNamedWindow("dst", 1);
     cvShowImage("dst", dst);

     //cvSaveImage("output.png", dst); 

     cvReleaseImage(&dst);

     for (int i = 0; i < 3; i++)
     {
         cvReleaseImage(&rgb[i]);
         cvReleaseImage(&dstRGB[i]);
     }

     cvWaitKey(0);
     } // for loop ends

     cvReleaseImage(&src);

     cvDestroyWindow(argv[5]);
     cvDestroyWindow("dst");

以下是显示第一张图片后显示的错误

   OpenCV Error: Assertion failed (anchor.inside(Rect(0, 0, ksize.width, ksize.height))) in normalizeAnchor, file /home/Documents/opencv-2.4.5/release/modules/imgproc/precomp.hpp, line 90 terminate called after throwing an instance of 'cv::Exception' what():  /home/ocuments/opencv-2.4.5/release/modules/imgproc/precomp.hpp:90: error: (-215) anchor.inside(Rect(0, 0, ksize.width, ksize.height)) in function normalizeAnchor Aborted (core dumped)
4

1 回答 1

1

你可能想开始修复你的主循环

for(x = 0; x = 5;x++)

可能进入

for(x = 0; x != 5; x++)

事实上,它是一个无限循环

于 2013-07-24T12:53:37.053 回答