isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.43k stars 2.31k forks source link

Color Inversion in Visualizer.capture_screen_float_buffer() #5197

Open marcelbrucker opened 2 years ago

marcelbrucker commented 2 years ago

Checklist

Describe the issue

I have been trying to take a screenshot from the Open3d Visualizer and then continue with opencv-python. I noticed that the colors are inverted when I use capture_screen_float_buffer(). capture_screen_image() shows the correct colors.

Result of capture_screen_float_buffer(): Screenshot_cv2

Result of capture_screen_image(): Screenshot_Open3D

Steps to reproduce the bug

import open3d as o3d
import numpy as np
import cv2

eagle = o3d.data.EaglePointCloud()
pcd = o3d.io.read_point_cloud(eagle.path)
pcd.paint_uniform_color([1, 0, 0]) # Red

vis = o3d.visualization.Visualizer()
vis.create_window(width=1920, height=1200, visible=False)
vis.add_geometry(pcd)

vis.capture_screen_image('Screenshot_Open3D.png', do_render=True)

image_o3d = vis.capture_screen_float_buffer(do_render=True)
image_cv2 = (255.0 * np.asarray(image_o3d)).astype(np.uint8)
cv2.imwrite('Screenshot_cv2.png', image_cv2)

Error message

No response

Expected behavior

I expect the same color for both image exports using capture_screen_float_buffer() and capture_screen_image(), respectively.

Open3D, Python and System information

- Operating system: Ubuntu 20.04
- Python version: 3.8.10 (default, Mar 15 2022, 12:22:08) \n[GCC 9.4.0]
- Open3D version: output from python: 0.15.2+429c3fa
- System architecture: x86
- Is this a remote workstation?: no
- How did you install Open3D?: pip

Additional information

No response

cppcute-pm commented 2 months ago

I guess it's because that you have to translate the RGB image to BGR image before you use the cv2.imwrite function, the translate function is cv2.cvtColor()