我尝试同时显示一个Viz3d窗口和一个带OpenCV的常规窗口(3.2或3.3,在Ubuntu 16.04上用QT 5编译)。当我这样做时,我的程序退出时会出现分段错误,即当我在常规(imshow)窗口中按下某个键时。这是一个最小的例子:
#include <iostream>
#include <opencv2/viz.hpp>
#include <opencv2/highgui.hpp>
using namespace std;
using namespace cv;
using namespace cv::viz;
int main()
{
Viz3d visualization("Test");
visualization.showWidget("Test object", WCone(1, 0.5, 100));
visualization.setWindowPosition(Point2i(0, 0));
visualization.spinOnce(1, true);
cv::imshow("Test window", Mat(100, 100, CV_8UC1, Scalar(0)));
moveWindow("Test window", 800, 0);
while (!visualization.wasStopped())
{
if (waitKeyEx(1) != -1)
break;
visualization.spinOnce(1, true);
}
return 0;
}
仅使用imshow或仅使用Viz3d窗口可以正常工作。使用两种类型的窗户时是否需要设置任何特殊选项?我在文档中找不到与此相关的任何内容。
这是我在gdb中看到的调用堆栈:
Thread 1 "test" received signal SIGSEGV, Segmentation fault.
__GI___pthread_mutex_lock (mutex=0x0) at ../nptl/pthread_mutex_lock.c:67
67 ../nptl/pthread_mutex_lock.c: No such file or directory.
(gdb) bt
#0 __GI___pthread_mutex_lock (mutex=0x0) at ../nptl/pthread_mutex_lock.c:67
#1 0x00007fffee79be27 in XrmDestroyDatabase () from /usr/lib/x86_64-linux-gnu/libX11.so.6
#2 0x00007fffee50b3bb in ?? () from /usr/lib/x86_64-linux-gnu/libXt.so.6
#3 0x00007fffee50c04a in XtCloseDisplay () from /usr/lib/x86_64-linux-gnu/libXt.so.6
#4 0x00007fffee50c0c1 in ?? () from /usr/lib/x86_64-linux-gnu/libXt.so.6
#5 0x00007fffee50c25c in XtDestroyApplicationContext () from /usr/lib/x86_64-linux-gnu/libXt.so.6
#6 0x00007ffff54a06cd in vtkXRenderWindowInteractor::~vtkXRenderWindowInteractor() () from /usr/lib/x86_64-linux-gnu/libvtkRenderingOpenGL-6.2.so.6.2
#7 0x00007ffff54a06f9 in vtkXRenderWindowInteractor::~vtkXRenderWindowInteractor() () from /usr/lib/x86_64-linux-gnu/libvtkRenderingOpenGL-6.2.so.6.2
#8 0x00007ffff2111409 in vtkObjectBase::UnRegisterInternal(vtkObjectBase*, int) () from /usr/lib/x86_64-linux-gnu/libvtkCommonCore-6.2.so.6.2
#9 0x00007ffff21133a5 in vtkObject::UnRegisterInternal(vtkObjectBase*, int) () from /usr/lib/x86_64-linux-gnu/libvtkCommonCore-6.2.so.6.2
#10 0x00007ffff47004be in vtkRenderWindowInteractor::UnRegister(vtkObjectBase*) () from /usr/lib/x86_64-linux-gnu/libvtkRenderingCore-6.2.so.6.2
#11 0x00007ffff46f81ba in vtkRenderWindow::UnRegister(vtkObjectBase*) () from /usr/lib/x86_64-linux-gnu/libvtkRenderingCore-6.2.so.6.2
---Type <return> to continue, or q <return> to quit---
#12 0x00007ffff7b8e310 in cv::viz::Viz3d::VizImpl::~VizImpl() () from /usr/local/lib/libopencv_viz.so.3.2
#13 0x00007ffff7b8e3f9 in cv::viz::Viz3d::VizImpl::~VizImpl() () from /usr/local/lib/libopencv_viz.so.3.2
#14 0x00007ffff7b846ae in cv::viz::Viz3d::release() () from /usr/local/lib/libopencv_viz.so.3.2
#15 0x00007ffff7bbff0d in cv::viz::VizStorage::removeUnreferenced() () from /usr/local/lib/libopencv_viz.so.3.2
#16 0x00007ffff7b846c5 in cv::viz::Viz3d::release() () from /usr/local/lib/libopencv_viz.so.3.2
#17 0x0000000000402e0f in main () at test.cpp:11