As shown in the documentation of Open3D, you can use the get_view_control.rotate()
function to rotate the object inside the viewer. But it does not specify the type (degree, radian etc.). If I use a value of around 2100 it looks like a full turn, but after putting those in a loop, it turns out this is not the exact value for turning 360 degrees. Also I don't see it mentioned anywhere in the documentation of Open3D.
I want to capture depth images at different angles for a full 360 degree (x,y,z). This is a piece of my code:
class Viewer:
def __init__(self, on, of, fd): #objectname, objectFile and folderdirectory
self.index = 0
self.objectName = on
self.objectFile = of
self.folderDirectory = fd
self.vis = o3d.visualization.Visualizer()
self.view = o3d.visualization.ViewControl()
self.pcd = o3d.io.read_triangle_mesh(self.folderDirectory + self.objectFile)
def depthFullCapture(self, times):
self.numberOfTimes = times
def captureDepth(vis):
print('Capturing')
self.depth = vis.capture_depth_float_buffer(False)
plt.imsave((self.folderDirectory + 'images/' + self.objectName + '_{:05d}.png'.format(self.index)),np.asarray(self.depth), dpi = 1)
np.savetxt((self.folderDirectory + 'text/' + self.objectName + '_{:05d}.txt'.format(self.index)),self.depth,fmt='%.2f',delimiter=',')
vis.register_animation_callback(rotate)
def rotate(vis):
print('Rotating')
ctr = vis.get_view_control()
if(self.index % 25 == 0):
self.vis.reset_view_point(True)
ctr.rotate(0,((2100/25)*(self.index/25)))
else:
ctr.rotate(84, 0)
ctr.set_zoom(0.75)
self.index += 1
if not (self.index == 625):
vis.register_animation_callback(captureDepth)
else:
vis.register_animation_callback(None)
vis.destroy_window()
self.vis.create_window(width = 200, height = 200)
self.vis.add_geometry(self.pcd)
self.vis.register_animation_callback(captureDepth)
self.vis.run()
So can anyone explain the correct value/type for turning a certain degrees? Or is there another/better way to do this? Thanks in advance! If anything is not clear, please ask :)
The actual answer can be found in the C documentation:
const double open3d::visualization::ViewControl::ROTATION_RADIAN_PER_PIXEL = 0.003
the rotation units are pixels:
x and y are the distances the mouse cursor has moved. xo and yo are the original point coordinate the mouse cursor started to move from. Coordinates are measured in screen coordinates relative to the top-left corner of the window client area.
You were very close.
0.003 [radian/pixel] * (180/pi) [degrees/radian] = 0.1719 [degrees/pixel]
OR
5.8178 [pixels/degree]
Taking
360 [degrees/rotation] * 5.8178 [pixels/degree] = 2094.3951 [pixels/rotation]