Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Two Dimensional Data Protocols for python wrapper (vtx & tex) #2154

Merged
merged 1 commit into from
Aug 27, 2018
Merged

Adding Two Dimensional Data Protocols for python wrapper (vtx & tex) #2154

merged 1 commit into from
Aug 27, 2018

Conversation

baptiste-mnh
Copy link
Contributor

Relating to this issue :
https://github.com/erleben/pySoRo#adding-two-dimensional-data-protocols

I add two function in the python wrapper to get the vertices and textures coordinate compatible with open3d to do real time visualisation.

The 2 new functions

points.get_vertices_2d()
points.get_texture_coordinates_2d()

The code to test :

import pyrealsense2 as rs
import numpy as np
from open3d import *


# Create a pipeline
pipeline = rs.pipeline()

# Create a config and configure the pipeline to stream
#  different resolutions of color and depth streams
config = rs.config()
config.enable_stream(rs.stream.depth, 640, 480, rs.format.z16, 30)
config.enable_stream(rs.stream.color, 640, 480, rs.format.rgb8, 30)

# Start streaming
profile = pipeline.start(config)


# Streaming loop
try:
    vis = Visualizer()
    vis.create_window("Test")
    pcd = PointCloud()
    while True:
        vis.add_geometry(pcd)
        pcd.clear()
        # Get frameset of color and depth
        frames = pipeline.wait_for_frames()
        color = frames.get_color_frame()
        depth = frames.get_depth_frame()
        if not color or not depth:
            continue
        pc = rs.pointcloud()
        pc.map_to(color)
        points = pc.calculate(depth)
        vtx = np.asanyarray(points.get_vertices_2d())
        pcd.points = Vector3dVector(vtx)
        vis.update_geometry()
        vis.poll_events()
        vis.update_renderer()
finally:
    pipeline.stop()

@dorodnic
Copy link
Contributor

Hi @baptiste-mnh
At glance looks very cool, thank you for contributing!

@dorodnic dorodnic requested a review from lramati July 26, 2018 15:33
Copy link
Contributor

@lramati lramati left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pull request's logic is great, but there's a couple small things that could add some more polish.

BufData( void *ptr // Raw pointer
, size_t count // Number of points
, size_t dim // The number of floats inside a point
) : BufData( ptr, sizeof(float), "@f", 2, std::vector<size_t> { count, dim }, std::vector<size_t> { sizeof(float)*dim, sizeof(float) }) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this wasn't hard coded to floats.
It should be enough to add the std::string &format and size_t size parameters from the above overload and use them instead of "@f" and sizeof(float) respectively.

@@ -397,6 +401,23 @@ PYBIND11_MODULE(NAME, m) {
py::class_<rs2::points, rs2::frame> points(m, "points");
points.def(py::init<>())
.def(py::init<rs2::frame>())
.def("get_vertices_2d", [](rs2::points& self) -> BufData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be cleaner to have a single get_vertices function that takes an int parameter requesting the number of dimensions of the output than get_vertices and get_vertices_2d.
This function should default to 1 dimension on no input to remain backwards compatible.

);

}, py::keep_alive<0, 1>())
.def("get_texture_coordinates_2d", [](rs2::points& self) -> BufData
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as on get_vertices_2d

@baptiste-mnh
Copy link
Contributor Author

Thanks!
So how do you call it when you want in in 2D?

@lramati
Copy link
Contributor

lramati commented Aug 8, 2018

Whatever you think looks most pythonic. get_vertices(2) or get_vertices(dims=2) seem like reasonable choices.

@baptiste-mnh
Copy link
Contributor Author

Yes I approve this choice!

@dorodnic
Copy link
Contributor

This PR should get auto-merged once we make this weeks release and merge development into master

@dorodnic dorodnic merged commit c50e819 into IntelRealSense:master Aug 27, 2018
gwen2018 pushed a commit to gwen2018/librealsense that referenced this pull request Jul 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants