OpenCV CvSeq 递归元素访问对于大图像失败?
我的开发环境是 Windows 7 上的 Mingw32 位 CMake。(相同的代码在 Linux 上运行良好)
我使用 cvFindContours() 使用 OpenCV 检测轮廓。
我使用递归方法遍历生成的 CvSeq 以按级别访问轮廓,如下所示:
void helperParseCurves(CvSeq* contour, int level) {
//Travel same level contours
if(contour->h_next != NULL) {
helperParseCurves(contour->h_next, level);
}
if(contour->v_next != NULL) {
helperParseCurves(contour->v_next, level+1);
}
//Travel child levels
for(int i=0; i<contour->total; i++){
//Try to access Point data -- Crash here when threshold level 114 ?
//Works when uncommented
CvPoint* p = CV_GET_SEQ_ELEM(CvPoint, contour, i);
}
}
但是应用程序在 CvPoint* p = CV_GET_SEQ_ELEM(CvPoint,contour, i); 行处崩溃 这种情况发生在某些特定的大图像上,并且在 Linux 中运行良好。
我已在 http://dl.dropbox 上传了一个示例程序来演示该场景
。 com/u/17399055/opencv-test.zip
*使用 CMake 下载并编译
*使用示例图像运行代码 - "OCvTest.exe test-img.tif"
*将滑块值更改为 114 左右,应用程序崩溃。
*如果第 #27 行被注释则工作正常。
对此有什么建议吗?
这可能是 OpenCV 的错误吗?
提前致谢。
My development enviroment is Mingw32 bit CMake on Windows 7.(this same code works fine on Linux)
I use cvFindContours() to detect contours using OpenCV.
I use recursive method to traveser the resultant CvSeq to access the contours by level as follows:
void helperParseCurves(CvSeq* contour, int level) {
//Travel same level contours
if(contour->h_next != NULL) {
helperParseCurves(contour->h_next, level);
}
if(contour->v_next != NULL) {
helperParseCurves(contour->v_next, level+1);
}
//Travel child levels
for(int i=0; i<contour->total; i++){
//Try to access Point data -- Crash here when threshold level 114 ?
//Works when uncommented
CvPoint* p = CV_GET_SEQ_ELEM(CvPoint, contour, i);
}
}
But the application crashes at the line CvPoint* p = CV_GET_SEQ_ELEM(CvPoint, contour, i);
This happens to some specific large images and works fine in Linux.
I have uploaded an sample program to demonstrate the scenario at
http://dl.dropbox.com/u/17399055/opencv-test.zip
*download and compile using CMake
*run the code using the sample image -
"OCvTest.exe test-img.tif"
*change the slider value around 114 , application crashes.
*if the line #27 is commented works fine.
Any tips on this ?
Could this be a OpenCV bug ?
thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我意识到这是由于递归函数而发生的。一旦我将其设为迭代函数,一切都工作正常。
现在我知道为什么递归函数不好......之前并没有真正“实际上”理解这一点......
I realized that this happens due to the recursive function.Once I made it an iterative one ,everything worked fine.
Now I know why recursive functions are bad...didnt really "practically" understood that before..