Capturing Individual Color or Depth Stream

Top  Previous  Next

This section addresses capturing individual color or depth streams. For information about capturing synchronized color and depth streams, see Capturing Aligned/Unaligned Color and Depth Samples.

The PXC[M]SenseManager interface implements I/O device configuration and data streaming. You can use the interface in one of the two ways: by procedural calls or by event callbacks.

Capturing Color Samples Using Procedural Calls

Example 21 shows how to capture color samples by procedural calls. The example does the following:

Select a color stream by using the EnableStream function, and then initialize the pipeline by using the Init function.
In the loop, use the AcquireFrame function to wait for a color sample to be ready and then retrieve it through the QuerySample function.
Release the frame for reading next sample using the ReleaseFrame function.
Use the Close  function to clean up.

You can use the filtering functions (such as FilterByDeviceInfo) of the PXC[M]CaptureManager interface to customize the stream selection process, for example, to choose a specific camera. Use the QueryCaptureManager function to retrieve an instance of the PXC[M]CaptureManager interface.

C++ Example 21: Capture Color Samples using the SenseManager and Procedural Calls

// Create a PXCSenseManager instance

PXCSenseManager *sm=PXCSenseManager::CreateInstance();

 

// Select the color stream

sm->EnableStream(PXCCapture::STREAM_TYPE_COLOR,640,480);

 

// Initialize and Stream Samples

sm->Init();

for (;;) {

   // This function blocks until a color sample is ready

   if (sm->AcquireFrame(true)<PXC_STATUS_NO_ERROR) break;

 

   // retrieve the sample

   PXCCapture::Sample *sample=sm->QuerySample();

 

   // work on the image sample->color

   ...

 
   // go fetching the next sample

   sm->ReleaseFrame();

}

 

// Close down

sm->Release();

C# Example 21: Capture Color Samples using the SenseManager and Procedural Calls

// Create a PXCMSenseManager instance

PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

// Select the color stream

sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR,640,480);

 

// Initialize and Stream samples

sm.Init();

for (;;) {

   // This function blocks until a color sample is ready

   if (sm.AcquireFrame(true)<pxcmStatus.PXCM_STATUS_NO_ERROR) break;

 

   // retrieve the sample

   PXCMCapture.Sample sample=sm.QuerySample();

 

   // work on the image sample.color

   ...

 

   // go fetching the next sample

   sm.ReleaseFrame();

}

 

// Close down

sm.Dispose();

Java Example 21: Capture Color Samples using the SenseManager and Procedural Calls

// Create a PXCMSenseManager instance

PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

// Select the color stream

sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_COLOR,640,480);

 

// Initialize and Stream samples

sm.Init();

for (;;) {

   // This function blocks until a color sample is ready

   if (sm.AcquireFrame(true)<pxcmStatus.PXCM_STATUS_NO_ERROR) break;

 

   // retrieve the sample

   PXCMCapture.Sample sample=sm.QuerySample();

 

   // work on the image sample.color

   ...

 

   // go fetching the next sample

   sm.ReleaseFrame();

}

 

// Close down

sm.close();

Capturing Color Samples Using Event Callbacks

Example 23 shows how to capture 60 fps depth samples using the PXC[M]SenseManager interface by event callbacks. The main procedure creates the event handler and calls the LoopFrames function. In the OnNewSample event callback, the application receives the current color image sample.

C++ Example 22: Capture 60FPS Depth Samples using the SenseManager and Event Callbacks

class MyHandler: public PXCSenseManager::Handler {

public:

 

   virtual pxcStatus PXCAPI OnNewSample(pxcUID, PXCCapture::Sample *sample) {

       // work on sample->color

       ...

       // return NO ERROR to continue, or any ERROR to exit the loop

       return PXC_STATUS_NO_ERROR;

   }

};

 

void MainRoutine(void) {

   // Create a SenseManager instance

   PXCSenseManager *sm=PXCSenseManager::CreateInstance();

 

   // Enable depth stream at 320x240x60fps

   sm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH,320,240,60);

 

   // Initialize my event handler

   MyHandler handler;

   sm->Init(&handler)

 

   // Stream depth samples

   sm->StreamFrames(true);

 

   // Clean up

   sm->Close();

   sm->Release();

}

C# Example 22: Capture 60FPS Depth Samples using the SenseManager and Event Calls

pxcmStatus OnNewSample(int mid, PXCMCapture.Sample sample) {

   // work on sample.color

   ...

   // return NO ERROR to continue, or any ERROR to exit the loop

   return pxcmStatus.PXCM_STATUS_NO_ERROR;

}

 

void MainRoutine() {

   // Create a SenseManager instance

   PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

   // Enable depth stream at 320x240x60fps

   sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH,320,240,60);

 

   // Initialize my event handler

   PXCMSenseManager::Handler handler=new PXCMSenseManager.Handler();

   handler.onNewSample=OnNewSample;

   sm.Init(handler);

 

   // Stream depth samples

   sm.StreamFrames(true);

 

   // Clean up

   sm.Dispose();

}

Java Example 22: Capture 60FPS Depth Samples using the SenseManager and Event Calls

class MyHandler implements PXCMSenseManager.Handler {

   public pxcmStatus OnNewSample(int mid, PXCMCapture.Sample sample) {

       // work on sample.color

       ...

       // return NO ERROR to continue, or any ERROR to exit the loop

       return pxcmStatus.PXCM_STATUS_NO_ERROR;

   }

   ...

};

 

void MainRoutine() {

   // Create a SenseManager instance

   PXCMSenseManager sm=PXCMSenseManager.CreateInstance();

 

   // Enable depth stream at 320x240x60fps

   sm.EnableStream(PXCMCapture.StreamType.STREAM_TYPE_DEPTH,320,240,60);

 

   // Initialize my event handler

   MyHandler handler=new MyHandler();

   sm.Init(handler);

 

   // Stream depth samples

   sm.StreamFrames(true);

 

   // Clean up

   sm.close();

}