当使用HoughLinesP时,Qt中的OpenCV崩溃对线向量的释放 [英] OpenCV in Qt crashes on deallocation of vector of lines when using HoughLinesP
问题描述
我已经使用OpenCV 3.0.0了一段时间,最近已经将IDE从Visual Studio 2013切换到Qt Creator 3.4.2。我从源 WITH_QT
重新构建我的OpenCV库。我现在有在运行时有问题,重新分配一个矢量< vec4i方式>仅使用在调试模式下HoughLinesP功能时
I've been using OpenCV 3.0.0 for quite some time now and have recently switched IDEs from Visual Studio 2013 to Qt Creator 3.4.2. I rebuilt my OpenCV libraries from source WITH_QT
checked. I'm now having a problem at runtime with deallocating a vector<vec4i>
when using the HoughLinesP function ONLY in debug mode.
这里是我的代码片段:
Mat source(400,400,CV_8U,Scalar(0));
line(source,Point(20,20),Point(300,300),Scalar(255),10);
{
vector<Vec4i> lines;
HoughLinesP(source, lines, 1, CV_PI/180, 50, 50, 10 );
cout << "lines.size() = " << lines.size() << endl;
cout << "before leaving block" << endl;
}
cout << "after leaving block" << endl;
imshow("source", source);
waitKey();
return 0;
如果我在发布版本中运行,那么一切正常,这是我的输出:
If I run this in release, then everything works fine and this is my output:
lines.size()= 13
在离开块之前
离开块后
lines.size() = 13
before leaving block
after leaving block
< b
However, if I run this in debug, then my program crashes when it reaches the closing block and this is my output:
lines.size()= 18446744073709306522
离开区块之前
lines.size() = 18446744073709306522
before leaving block
如果在调试和我注释掉与HoughLinesP的行,那么没有崩溃,这是我的输出:
If in debug and I comment out the line with HoughLinesP, then there is no crash and this is my output:
lines.size()= 0
离开块之前
离开块后
lines.size() = 0
before leaving block
after leaving block
这是我的.pro文件:
Here is my .pro file:
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = OpenCVProject_x64
TEMPLATE = app
INCLUDEPATH += C:\OpenCV3.0.0\opencv\build\include
win32:CONFIG(release, debug|release) {
LIBS += -LC:\OpenCV3.0.0\opencv\OpenCVLocalBuild_x64\lib\Release \
-lopencv_calib3d300 -lopencv_core300 -lopencv_features2d300 \
-lopencv_flann300 -lopencv_hal300 -lopencv_highgui300 \
-lopencv_imgcodecs300 -lopencv_imgproc300 -lopencv_ml300 \
-lopencv_objdetect300 -lopencv_photo300 -lopencv_shape300 \
-lopencv_stitching300 -lopencv_superres300 -lopencv_ts300 \
-lopencv_video300 -lopencv_videoio300 -lopencv_videostab300
}
win32:CONFIG(debug, debug|release) {
LIBS += -LC:\OpenCV3.0.0\opencv\OpenCVLocalBuild_x64\lib\Debug \
-lopencv_calib3d300d -lopencv_core300d -lopencv_features2d300d \
-lopencv_flann300d -lopencv_hal300d -lopencv_highgui300d \
-lopencv_imgcodecs300d -lopencv_imgproc300d -lopencv_ml300d \
-lopencv_objdetect300d -lopencv_photo300d -lopencv_shape300d \
-lopencv_stitching300d -lopencv_superres300d -lopencv_ts300d \
-lopencv_video300d -lopencv_videoio300d -lopencv_videostab300d
}
SOURCES += main.cpp
请让我知道如果你有什么导致这种崩溃的想法。 / p>
Please let me know if you have ideas on whats causing this crash.
推荐答案
的条件的随后在同一
线后,命令和定义的序列,并在
新行右括号开括号:
Scopes consist of a condition followed by an opening brace on the same line, a sequence of commands and definitions, and a closing brace on a new line:
<condition> {
<command or definition>
...
}
在同一行作为条件强>作用域可以连在一起,以包括一个以上的
的状况,如在下面章节中描述
The opening brace must be written on the same line as the condition. Scopes may be concatenated to include more than one condition, as described in the following sections.
这两个库集都添加到 Debug
和 LIBS
变量> Release build,因为范围开头大括号在条件后写在新行上。
Both library sets are added to the LIBS
variable for Debug
and Release
build, since scope opening braces are written on the new line after conditions.
看起来至少 Visual Studio 12 Win64
和 OpenCV 3.0
之间存在二进制不兼容调试
和发布
库。
It appears that at least for Visual Studio 12 Win64
and OpenCV 3.0
there is binary incompatibility between Debug
and Release
libraries.
如果应用程序构建在 Debug
模式与版本
库崩溃,如果它是内置在版本
模式与调试
库也会崩溃。
If the application is built in the Debug
mode with the Release
libraries it crashes and if it is built in the Release
mode with the Debug
libraries it also crashes.
这篇关于当使用HoughLinesP时,Qt中的OpenCV崩溃对线向量的释放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!