我希望在OpenCV中使用C API分别在不同的窗口中显示多个图像。以下是我的代码,我已经做了一个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)
答案 0 :(得分:1)
您可能想要开始修复主循环
for(x = 0; x = 5;x++)
可能进入
for(x = 0; x != 5; x++)
实际上,这是一个无限循环