Items with no label
3337 Discussions

how to generate pointclouds and draw it in python

tguan
New Contributor I
14,237 Views

# encoding:utf-8import numpy as np

import cv2

import pyrealsense2 as rs

pipeline = rs.pipeline()

config = rs.config()

config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)

config.enable_stream(rs.stream.depth,640, 480, rs.format.z16, 30)

# 深度存储为每像素一个无符号 16 位整数,在摄像机特定单位中线性映射到深度pipeline.start(config)

while True: frames = pipeline.wait_for_frames()

color = frames.get_color_frame()

depth = frames.get_depth_frame()

if (not depth) or (not color): print("Color or Depth not available!")

break

# color color_img = np.asanyarray(color.get_data())

color_img = cv2.cvtColor(color_img, cv2.COLOR_BGR2RGB)

# depth

c = rs.colorizer()

colorized_depth = np.asanyarray(c.colorize(depth).get_data())

# pointclouds I HAVE PROBLEMS HERE??????

pc = rs.pointcloud()

points = pc.calculate(depth)

pc.map_to(color)

app_state.tex.upload(color) ?

draw_pointcloud(app, app_state, points) How to show the pointcloud?

cv2.imshow("color",color_img)

cv2.imshow(<span style="font-weight: inherit; font-style: i...

0 Kudos
1 Solution
Sahira_Intel
Moderator
11,227 Views

Hi guantong

I looked at your code and I think I was able to find what you needed to add to export and show the point cloud. We do have examples included in the SDK relating to point clouds that might be useful to you! Here are the links to those:

Pointclouds in C++ https://github.com/IntelRealSense/librealsense/tree/master/examples/pointcloud librealsense/examples/pointcloud at master · IntelRealSense/librealsense · GitHub

Pointclouds in Python https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/export_ply_example.py librealsense/export_ply_example.py at master · IntelRealSense/librealsense · GitHub

The lines I have added to your code are in red below.

Please let me know if this worked for you!

Regards,

Intel Customer Support

________________________________________________________________________________________________________________________________________________________________________

# encoding:utf-8import numpy as np

import cv2

import pyrealsense2 as rs

pipeline = rs.pipeline()

config = rs.config()

config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)

config.enable_stream(rs.stream.depth,640, 480, rs.format.z16, 30)

# 深度存储为每像素一个无符号 16 位整数,在摄像机特定单位中线性映射到深度pipeline.start(config)

while True:

frames = pipeline.wait_for_frames()

color = frames.get_color_frame()

depth = frames.get_depth_frame()

if (not depth) or (not color):

print("Color or Depth not

break

# color color_img = np.asanyarray(color.get_data())

color_img = cv2.cvtColor(color_img, cv2.COLOR_BGR2RGB)

<p style="font-family: intel-clear, arial, helvetica, 'helvetica neue', ve...

View solution in original post

8 Replies
Sahira_Intel
Moderator
11,228 Views

Hi guantong

I looked at your code and I think I was able to find what you needed to add to export and show the point cloud. We do have examples included in the SDK relating to point clouds that might be useful to you! Here are the links to those:

Pointclouds in C++ https://github.com/IntelRealSense/librealsense/tree/master/examples/pointcloud librealsense/examples/pointcloud at master · IntelRealSense/librealsense · GitHub

Pointclouds in Python https://github.com/IntelRealSense/librealsense/blob/master/wrappers/python/examples/export_ply_example.py librealsense/export_ply_example.py at master · IntelRealSense/librealsense · GitHub

The lines I have added to your code are in red below.

Please let me know if this worked for you!

Regards,

Intel Customer Support

________________________________________________________________________________________________________________________________________________________________________

# encoding:utf-8import numpy as np

import cv2

import pyrealsense2 as rs

pipeline = rs.pipeline()

config = rs.config()

config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)

config.enable_stream(rs.stream.depth,640, 480, rs.format.z16, 30)

# 深度存储为每像素一个无符号 16 位整数,在摄像机特定单位中线性映射到深度pipeline.start(config)

while True:

frames = pipeline.wait_for_frames()

color = frames.get_color_frame()

depth = frames.get_depth_frame()

if (not depth) or (not color):

print("Color or Depth not

break

# color color_img = np.asanyarray(color.get_data())

color_img = cv2.cvtColor(color_img, cv2.COLOR_BGR2RGB)

<p style="font-family: intel-clear, arial, helvetica, 'helvetica neue', ve...
tguan
New Contributor I
11,227 Views
0 Kudos
miself
Beginner
8,764 Views

Hi Sahira_Intel,

I'm trying to read your answer to tguan, but for some reason the code appears to be incomplete. Is there a way to see the entire code?

Thanks in advance.

0 Kudos
MartyG
Honored Contributor III
11,227 Views

I saw that a member of the Intel support team gave a reply earlier.

If you need another suggestion, I recommend this Python tutorial:

https://github.com/dorodnic/binder_test/blob/master/pointcloud.ipynb binder_test/pointcloud.ipynb at master · dorodnic/binder_test · GitHub

tguan
New Contributor I
11,227 Views

So nice you are.

I read the tutorial you send me

i have a question about it :

from pyntcloud.pyntcloud import PyntCloud # open source library for 3D pointcloud visualisation

ModuleNotFoundError: No module named 'pyntcloud'

how was the module'pyntcloud' in python3?

i install it by pip but failed.

thank you very much

MartyG
Honored Contributor III
11,227 Views

The installation instructions for Pyntcloud are here:

http://pyntcloud.readthedocs.io/en/latest/installation.html Installation — pyntcloud 0.0.1 documentation

STEP ONE

Make sure that you have these requirements installed on your computer.

Python 3

numpy

numba

scipy

pandas

STEP TWO

When these requirements are installed, run them with these instructions:

conda env create -n pyntcloud python=3 numpy numba scipy pandas

source activate pyntcloud

STEP THREE

Finally, install Pyntcloud with this instruction:

pip install git+ https://github.com/daavoo/pyntcloud

0 Kudos
tguan
New Contributor I
11,227 Views

sorry,iI failed in running these instructions in step2 and 3

0 Kudos
MartyG
Honored Contributor III
11,227 Views

Ok, I read the instructions again. I believe you only need to use the instructions that you had problems with if you are installing the requirements using a program called miniconda. If you have installed the list of programs yourself, then skip to the final instruction:

pip install git+ https://github.com/daavoo/pyntcloud

0 Kudos
Reply