예제 #1
0
DeviceKinect::DeviceKinect (xn::Context& context, const xn::NodeInfo& device_node, const xn::NodeInfo& image_node, const xn::NodeInfo& depth_node, const xn::NodeInfo& ir_node)
: OpenNIDevice (context, device_node, image_node, depth_node, ir_node)
, debayering_method_ (ImageBayerGRBG::EdgeAwareWeighted)
{
  // setup stream modes
  enumAvailableModes ();
  setDepthOutputMode (getDefaultDepthMode ());
  setImageOutputMode (getDefaultImageMode ());
  setIROutputMode (getDefaultIRMode ());

  // device specific initialization
  XnStatus status;

  unique_lock<mutex> image_lock(image_mutex_);
  // set kinect specific format. Thus input = uncompressed Bayer, output = grayscale = bypass = bayer
  status = image_generator_.SetIntProperty ("InputFormat", 6);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("Error setting the image input format to Uncompressed 8-bit BAYER. Reason: %s", xnGetStatusString (status));

  // Grayscale: bypass debayering -> gives us bayer pattern!
  status = image_generator_.SetPixelFormat (XN_PIXEL_FORMAT_GRAYSCALE_8_BIT);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("Failed to set image pixel format to 8bit-grayscale. Reason: %s", xnGetStatusString (status));
  image_lock.unlock ();

  lock_guard<mutex> depth_lock(depth_mutex_);
  // RegistrationType should be 2 (software) for Kinect, 1 (hardware) for PS
  status = depth_generator_.SetIntProperty ("RegistrationType", 2);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("Error setting the registration type. Reason: %s", xnGetStatusString (status));
}
DevicePrimesense::DevicePrimesense (xn::Context& context, const xn::NodeInfo& device_node, const xn::NodeInfo& image_node, const xn::NodeInfo& depth_node, const xn::NodeInfo& ir_node)
: OpenNIDevice (context, device_node, image_node, depth_node, ir_node)
{
  // setup stream modes
  enumAvailableModes ();
  setDepthOutputMode (getDefaultDepthMode ());
  setImageOutputMode (getDefaultImageMode ());
  setIROutputMode (getDefaultIRMode ());

  unique_lock<mutex> image_lock(image_mutex_);
  XnStatus status = image_generator_.SetIntProperty ("InputFormat", 5);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("Error setting the image input format to Uncompressed YUV422. Reason: %s", xnGetStatusString (status));

  status = image_generator_.SetPixelFormat (XN_PIXEL_FORMAT_YUV422);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("Failed to set image pixel format to YUV422. Reason: %s", xnGetStatusString (status));

  image_lock.unlock ();

  lock_guard<mutex> depth_lock(depth_mutex_);
  status = depth_generator_.SetIntProperty ("RegistrationType", 1);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("Error setting the registration type. Reason: %s", xnGetStatusString (status));
}
예제 #3
0
void OpenNIDevice::Init () throw (OpenNIException)
{
  // call virtual function to find available modes specifically for each device type
  this->getAvailableModes ();

  // set Depth resolution here only once... since no other mode for kinect is available -> deactivating setDepthResolution method!
  setDepthOutputMode (getDefaultDepthMode ());
  setImageOutputMode (getDefaultImageMode ());

  XnDouble pixel_size;

  unique_lock<mutex> depth_lock (depth_mutex_);
  XnStatus status = depth_generator_.GetRealProperty ("ZPPS", pixel_size);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("reading the pixel size of IR camera failed. Reason: %s", xnGetStatusString (status));

  XnUInt64 depth_focal_length_SXGA;
  status = depth_generator_.GetIntProperty ("ZPD", depth_focal_length_SXGA);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("reading the focal length of IR camera failed. Reason: %s", xnGetStatusString (status));

  XnDouble baseline;
  status = depth_generator_.GetRealProperty ("LDDIS", baseline);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("reading the baseline failed. Reason: %s", xnGetStatusString (status));

  status = depth_generator_.GetIntProperty ("ShadowValue", shadow_value_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("reading the value for pixels in shadow regions failed. Reason: %s", xnGetStatusString (status));

  status = depth_generator_.GetIntProperty ("NoSampleValue", no_sample_value_);
  if (status != XN_STATUS_OK)
    THROW_OPENNI_EXCEPTION ("reading the value for pixels with no depth estimation failed. Reason: %s", xnGetStatusString (status));

  // baseline from cm -> meters
  baseline_ = (float)(baseline * 0.01);

  //focal length from mm -> pixels (valid for 1280x1024)
  depth_focal_length_SXGA_ = (float)depth_focal_length_SXGA / pixel_size;

  //register callback functions
  depth_generator_.RegisterToNewDataAvailable (OpenNIDevice::NewDepthDataAvailable, this, depth_callback_handle_);
  depth_lock.unlock ();

  lock_guard<mutex> image_lock (image_mutex_);
  image_generator_.RegisterToNewDataAvailable (OpenNIDevice::NewImageDataAvailable, this, image_callback_handle_);
}