Depth to color image registration fails in OpenNI

Problem

I wrote C++ code to read depth and color images from a Primesense camera using OpenNI 2, running on Windows. After initializing OpenNI and opening the Primesense device, I check if depth-to-color image registration mode is supported by calling psense_device.isImageRegistrationModeSupported(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR). This returns openni::STATUS_OK. So, next I set this image registration mode by calling psense_device.setImageRegistrationMode(openni::IMAGE_REGISTRATION_DEPTH_TO_COLOR). However, this fails!

Solution

I could not actually figure out why OpenNI reports that the device supports this mode, but fails setting it. I suspected that maybe the camera needs to see depth and color video streams being created before this mode is set. So, I set this mode as late as possible, after the depth-color streams are opened and configured. That seemed to work!

Tried with: Primesense camera, OpenNI 2, Visual Studio 2013 and Windows 7 Professional 64-bit

Advertisements

2 thoughts on “Depth to color image registration fails in OpenNI

  1. Hi, I am facing problem while registering the color_depth image by Primesense. I had used following snippet.

    def Depth(self):
    self.depth_stream = self.dev.create_depth_stream()
    self.dev.set_image_registration_mode(openni2.c_api.OniImageRegistrationMode.ONI_IMAGE_REGISTRATION_DEPTH_TO_COLOR)
    self.depth_stream.set_video_mode(
    c_api.OniVideoMode(pixelFormat=c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_1_MM, resolutionX=640, resolutionY=480,
    fps=30))
    self.depth_stream.start()
    self.depthFrame = self.depth_stream.read_frame()
    self.depthData = self.depthFrame.get_buffer_as_uint16()
    self.imgDepth = np.frombuffer(self.depthData, dtype=np.uint16)
    self.depthMat = np.reshape(self.imgDepth, (480, 640))
    np.save(“Regi_cam2_depth”, self.depthMat)
    self.depth_stream.stop()

    When I apply above code, the depth values with registration image and without registration image(when I comment self.dev.set_image_registration_mode(openni2.c_api.OniImageRegistrationMode.ONI_IMAGE_REGISTRATION_DEPTH_TO_COLOR) ) is not same. Depth values are scaled down. Some depth values are lost. What is the issue. Kindly advice.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.