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

Made it work for iPhone 12 Pro. #2

Merged
merged 2 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 20 additions & 31 deletions ipad_stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import copy
import numpy as np
import open3d as o3d
import cv2
from record3d import Record3DStream
from threading import Event

class DemoApp:
def __init__(self, rot=False):
def __init__(self):
self.event = Event()
self.session = None
self.rot = rot
self.vis = o3d.visualization.Visualizer()
self.vis.create_window()

Expand Down Expand Up @@ -49,49 +49,38 @@ def get_intrinsic_mat_from_coeffs(self, coeffs):
[ 0, coeffs.fy, coeffs.ty],
[ 0, 0, 1]])

def create_point_cloud(self):
depth = self.session.get_depth_frame()
rgb = cv2.resize(self.session.get_rgb_frame(), np.flip(np.shape(depth)))
rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(o3d.geometry.Image(rgb),
o3d.geometry.Image(depth),
convert_rgb_to_intensity=False)
return o3d.geometry.PointCloud.create_from_rgbd_image(rgbd, self.intrinsic)

def start_processing_stream(self):
self.event.wait() # Wait for new frame to arrive
depth = self.session.get_depth_frame()
rgb = self.session.get_rgb_frame()

# get intrinsic parameters
intrinsic_mat = self.get_intrinsic_mat_from_coeffs(self.session.get_intrinsic_mat())
self.rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(o3d.geometry.Image(np.array(rgb)), o3d.geometry.Image(np.array(depth, order="c")), convert_rgb_to_intensity=False)


# setup point clouds
# lidar depth map = 256x192
# intrinsics work well divided by 4 than the given value from record3d
intrinsic = o3d.camera.PinholeCameraIntrinsic(256, 192, intrinsic_mat[0,0]/4, intrinsic_mat[1,1]/4, intrinsic_mat[0,2]/4, intrinsic_mat[1,2]/4)
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
self.rgbd,
intrinsic)
self.pcd = pcd
self.intrinsic = o3d.camera.PinholeCameraIntrinsic(*np.shape(self.session.get_depth_frame()),
intrinsic_mat[0,0]/4,
intrinsic_mat[1,1]/4,
intrinsic_mat[0,2]/4,
intrinsic_mat[1,2]/4)
self.pcd = self.create_point_cloud()
# add geometry
self.vis.add_geometry(self.pcd)

# Loop for point clouds
while True:
self.event.wait() # Wait for new frame to arrive
# Copy the newly arrived RGBD frame
depth = self.session.get_depth_frame()
rgb = self.session.get_rgb_frame()

# store
if self.rot:
self.rgb = np.rot90(rgb)
self.depth = np.rot90(depth)
else:
self.rgb = rgb
self.depth = depth


self.rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(o3d.geometry.Image(np.array(self.rgb)), o3d.geometry.Image(np.array(self.depth, order="c")), convert_rgb_to_intensity=False)

self.event.wait() # Wait for new frame to arrive

# update pointclouds
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
self.rgbd,
intrinsic)
pcd = self.create_point_cloud()
self.pcd.points = pcd.points
self.pcd.colors = pcd.colors

Expand All @@ -104,6 +93,6 @@ def start_processing_stream(self):
self.event.clear()

if __name__ == '__main__':
getter = DemoApp(False)
getter = DemoApp()
getter.connect_to_device(dev_idx=0)
getter.start_processing_stream()
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
open3d
record3d
record3d
opencv-python