如何使用Python一起创建Mayavi图形(mlab.show)和图像窗口(cv2.imshow)?

时间:2018-08-21 22:01:57

标签: mayavi mayavi.mlab

我想用彩色图像一起绘制3D数据,以Mayavi为3D图,以OpenCV(cv2.imshow)为图像。

(实际上,我的真正目标是动画,例如CAMERA图像显示的一个窗口和LIDAR 3D点云显示的一个窗口。在这个问题上,让我们放下动画部分。)

使用以下代码,我可以可视化3D图。

from __future__ import absolute_import, division, print_function
import numpy as np
from mayavi import mlab

fig = mlab.figure(figure=None, bgcolor=(0,0,0), fgcolor=None, engine=None, size=(500, 500))
axes = np.array([[2.,0.,0.,0.], [0.,2.,0.,0.], [0.,0.,2.,0.]],dtype=np.float64)
mlab.plot3d([0, axes[0,0]], [0, axes[0,1]], [0, axes[0,2]], color=(1,0,0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[1,0]], [0, axes[1,1]], [0, axes[1,2]], color=(0,1,0), tube_radius=None, figure=fig)
mlab.plot3d([0, axes[2,0]], [0, axes[2,1]], [0, axes[2,2]], color=(0,0,1), tube_radius=None, figure=fig)

mlab.show()
import pdb; pdb.set_trace()  # <-- Just to keep window open

但是,当我仅添加一行import cv2时,程序将因段错误而失败。

[devbox1:25927] *** Process received signal ***
[devbox1:25927] Signal: Segmentation fault (11)
[devbox1:25927] Signal code: Invalid permissions (2)
[devbox1:25927] Failing at address: 0x7f3c9528efe0
[devbox1:25927] [ 0] /lib/x86_64-linux-gnu/libpthread.so.0(+0x11390)[0x7f3ca118c390]
[devbox1:25927] [ 1] /usr/lib/x86_64-linux-gnu/libQt5Core.so.5(_ZNK11QMetaObject9classNameEv+0x45)[0x7f3c18a56f85]
[devbox1:25927] [ 2] /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x1b677f)[0x7f3c1939d77f]
[devbox1:25927] [ 3] /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5(+0x150ed7)[0x7f3c19337ed7]
[devbox1:25927] [ 4] /lib64/ld-linux-x86-64.so.2(+0x106ba)[0x7f3ca15f56ba]
[devbox1:25927] [ 5] /lib64/ld-linux-x86-64.so.2(+0x107cb)[0x7f3ca15f57cb]
[devbox1:25927] [ 6] /lib64/ld-linux-x86-64.so.2(+0x158e2)[0x7f3ca15fa8e2]
[devbox1:25927] [ 7] /lib64/ld-linux-x86-64.so.2(+0x10564)[0x7f3ca15f5564]
[devbox1:25927] [ 8] /lib64/ld-linux-x86-64.so.2(+0x14da9)[0x7f3ca15f9da9]
[devbox1:25927] [ 9] /lib/x86_64-linux-gnu/libdl.so.2(+0xf09)[0x7f3ca0badf09]
[devbox1:25927] [10] /lib64/ld-linux-x86-64.so.2(+0x10564)[0x7f3ca15f5564]
[devbox1:25927] [11] /lib/x86_64-linux-gnu/libdl.so.2(+0x1571)[0x7f3ca0bae571]
[devbox1:25927] [12] /lib/x86_64-linux-gnu/libdl.so.2(dlopen+0x31)[0x7f3ca0badfa1]
[devbox1:25927] [13] python(_PyImport_GetDynLoadFunc+0xe9)[0x51ad19]
[devbox1:25927] [14] python(_PyImport_LoadDynamicModule+0x54)[0x51a8e4]
[devbox1:25927] [15] python[0x4a4ae1]
[devbox1:25927] [16] python(PyImport_ImportModuleLevel+0x689)[0x4a42c9]
[devbox1:25927] [17] python[0x4a59e4]
[devbox1:25927] [18] python(PyObject_Call+0x3e)[0x4a577e]
[devbox1:25927] [19] python(PyEval_CallObjectWithKeywords+0x30)[0x4c5e10]
[devbox1:25927] [20] python(PyEval_EvalFrameEx+0x28a7)[0x4be6d7]
[devbox1:25927] [21] python(PyEval_EvalCodeEx+0x306)[0x4b9ab6]
[devbox1:25927] [22] python[0x4eb30f]
[devbox1:25927] [23] python(PyRun_FileExFlags+0x82)[0x4e5422]
[devbox1:25927] [24] python(PyRun_SimpleFileExFlags+0x186)[0x4e3cd6]
[devbox1:25927] [25] python(Py_Main+0x612)[0x493ae2]
[devbox1:25927] [26] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f3ca0dd1830]
[devbox1:25927] [27] python(_start+0x29)[0x4933e9]
[devbox1:25927] *** End of error message ***

当然,仅使用“ cv2”(不使用mayavi)可以完美运行。

这是计算机设置问题吗?还是本机禁止的? 我怎样才能在Mayavi窗口中添加一个额外的cv2.imshow窗口?

0 个答案:

没有答案