enthought / mayavi

3D visualization of scientific data in Python
http://docs.enthought.com/mayavi/mayavi/
Other
1.3k stars 285 forks source link

sequences of mlab.show() and plt.show() #1181

Closed hitbuyi closed 1 year ago

hitbuyi commented 1 year ago

mlab.show() and plt.show() are used to display lidar point clound and image respectively, I found plt.show() must put in front of mlab.show() for display both at the same time, if I put mlab.show() in front of plt.show(), the display dialogue box generated by mlab.show() must be closed then the plt.show() beings to display its image. what's problem?

OS: ubuntu20.04 conda: 4.13.0


(pt1121_38) hitbuyi@hitbuyi-Dell-G15-5511:~/PycharmProjects$ pip list opencv-python
Package             Version
------------------- ------------
aiohttp             3.8.3
aiosignal           1.2.0
apptools            5.2.0
async-timeout       4.0.2
attrs               22.1.0
certifi             2022.9.24
charset-normalizer  2.1.1
colored             1.4.3
configobj           5.0.6
cycler              0.11.0
envisage            6.1.0
flatbuffers         2.0
fonttools           4.37.4
frozenlist          1.3.1
graphsurgeon        0.4.5
idna                3.4
importlib-resources 5.10.0
kiwisolver          1.4.4
matplotlib          3.5.0
mayavi              4.8.0
multidict           6.0.2
numpy               1.22.3
onnx                1.11.0
onnx-graphsurgeon   0.3.10
onnxruntime         1.11.0
opencv-python       4.1.2.30
packaging           21.3
Pillow              9.2.0
pip                 22.2.2
polygraphy          0.35.2
pyface              7.4.2
Pygments            2.13.0
pyparsing           3.0.9
PyQt5               5.15.7
PyQt5-Qt5           5.15.2
PyQt5-sip           12.11.0
python-dateutil     2.8.2
requests            2.28.1
scipy               1.9.1
setuptools          63.4.1
setuptools-scm      7.0.5
shiboken2           5.15.2.1
six                 1.16.0
tensorrt            8.0.1.6
tomli               2.0.1
torch               1.12.1+cu113
torchaudio          0.12.1
torchvision         0.13.1+cu113
tqdm                4.64.0
traits              6.4.1
traitsui            7.4.1
typing_extensions   4.2.0
urllib3             1.26.12
vtk                 9.1.0
wheel               0.37.1
wslink              1.8.2
yarl                1.8.1
zipp                3.8.1

and the code is

import os
import PyQt5
dirname = os.path.dirname(PyQt5.__file__)
plugin_path = os.path.join(dirname, 'Qt5','plugins', 'platforms')
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH'] = plugin_path

from mayavi import mlab
import matplotlib.pyplot as plt
import cv2
from kitti_object import kitti_object, show_lidar_with_depth, show_lidar_on_image, \
                         show_image_with_boxes, show_lidar_topview_with_boxes

dataset = kitti_object('./data/object', 'training')
data_idx = 2
objects = dataset.get_label_objects(data_idx)
pc_velo = dataset.get_lidar(data_idx)
calib = dataset.get_calibration(data_idx)
img = dataset.get_image(data_idx)
img_height, img_width, _ = img.shape

fig_3d = mlab.figure(
    figure=None, bgcolor=(0, 0, 0), fgcolor=None, engine=None, size=(1000, 500)
)
show_lidar_with_depth(pc_velo, objects, calib, fig_3d, True, img_width, img_height)
mlab.show()

img_lidar = show_lidar_on_image(pc_velo[:, :3], img, calib, img_width, img_height)
img_lidar = cv2.cvtColor(img_lidar, cv2.COLOR_BGR2RGB)

fig_lidar = plt.figure(figsize=(14, 7))
ax_lidar = fig_lidar.subplots()
ax_lidar.imshow(img_lidar)
plt.show()

img_bbox2d, img_bbox3d = show_image_with_boxes(img, objects, calib)
img_bbox2d = cv2.cvtColor(img_bbox2d, cv2.COLOR_BGR2RGB)
fig_bbox2d = plt.figure(figsize=(14, 7))
ax_bbox2d = fig_bbox2d.subplots()
ax_bbox2d.imshow(img_bbox2d)
plt.show()
prabhuramachandran commented 1 year ago

They each start different mainloops which seems to cause this problem. Also make sure they are using the same Qt backend, matplotlib has many backends. There should be one show at the end each show by itself will start a new mainloop. This is really not a mayavi specific bug though so am closing this.