Raytrix Light Field SDK  v3.1
Logo
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties Events Groups Pages
Retrieve Images from a Raytrix Camera

Contents

Before Capturing Camera Images

Before you can actually start capturing images from a Raytrix light field camera you have to make sure that the Camera is initialized and prepared correctly. To achieve this goal we recommend to follow the instructions of the chapter: Camera Source. Furthermore you can consult the section: Using the Rayrix Light Field API.

Assuming we have prepared, opened and bound the Raytrix camera we can start the capturing process. The Raytrix Light Field API allows three different triggering modes:


Retrieve Camera Images

The way to retrieve images from a Raytrix light field camera depends on whether you are using managed or unmanaged c++.

Either way we recommend to work with the camera image callback that comes with the Ratrix Light Field API. Nevertheless the programmer has to ensure thread safeness, particularly with regard to GUI interactions. The following image demonstrates the problematic:

BasicRetrieveImage.png
Basic Application with Camera Interaction

There are several ways to implement the interactions between a Raytrix light field camera and a custom application. In this page we are going to introduce two approaches. The first one is an event-based camera communication while the second one shows a more direct communication.

See also
Event-Based Camera Communication
Direct Camera Communications

Event-Based Camera Communication

The event-based camera communication shows the most modular approach. This approach needs you to start an independent worker-thread that literally waits on an event to operate. The events can be set by different sources, whereby the camera callback is the one we are most interested in. A great advantage of this implementation is that the GUI thread is encapsulated from the actual image processing, which allows the GUI to be, simultaneously to the worker-thread, responsive. For example the GUI can display the process of the process that is done in the background. The following image illustrates the event-based camera communication:

EventBasedRetrieveImage.png
Event-Based Camera Communication

A simpler way to implement the camera communication would be a direct interaction of camera callback and image processing.

See also
Direct Camera Communications

Direct Camera Communications

This approach is not as sophisticated as the Event-Based Camera Communication as it blocks the GUI during the image processing. At this implementation a worker-thread is not required since its task is taken on by the GUI thread. As a consequence all user interaction with the GUI are blocked at the time of processing the image. In more detail the difference between the event-based and the direct camera communication is that the image callback does not set an event that an image is available but invokes the processing in the GUI thread directly. The following code example shows the basic idea of the direct camera communication:

Example Code Snippets for Retrieving Camera Images

void main(int argc, char* argv[]){
// Register the callback function in the API which is called when a new image is available
.
.
.
}
// The Raytrix light field camera signaled that an image is present
// At this point the programmer must ensure thread safeness
void ImageCallback(unsigned int uCamIdx, void* pvContext){
// Copy the image into the bound API image
.
.
.
}
// A Handle to ensure basic thread safeness
System::Threading::EventWaitHandle^ m_evGrabInProcess;
// Delegate for the image callback
delegate void DisplayImageHandler();
int main(int, char*[], char*[]) {
// Attach API event handler
// A Handle to ensure basic thread safeness
m_evGrabInProcess = gcnew System::Threading::EventWaitHandle(false, System::Threading::EventResetMode::ManualReset);
.
.
.
return 0;
}
// The Raytrix light field camera signaled that an image is present
// At this point the programmer must ensure thread safeness
System::Void ImageCallback(unsigned int uCamIdx)
{
try
{
// We have to take precautions that the thread of our custom program is not flooded with too many BeginInvokes, thus we only allow one
if (!m_evGrabInProcess->WaitOne(0))
{
// Signalize that a grab is in progress
m_evGrabInProcess->Set();
// Invoke the image processing
BeginInvoke(gcnew DisplayImageHandler(this, &DisplayTexture), nullptr);
}
}
catch (Rx::Net::RxApiException^ xEx)
{
// Handle exception
}
}
.
.
.
System::Void DisplayTexture()
{
try
{
// Copy the image into the bound API image
.
.
.
// Reset the handle to allow a new image to be processed
m_evGrabInProcess->Reset();
}
catch (Rx::Net::RxApiException^ xEx)
{
// Handle exception
}
}
// Delegate for the image callback
delegate void DisplayImageHandler();
// A Handle to ensure basic thread safeness
System.Threading.EventWaitHandle m_evGrabInProcess;
// main function
static void Main(string[] args)
{
// A Handle to ensure basic thread safeness
m_evGrabInProcess = new System.Threading.EventWaitHandle(false, System.Threading.EventResetMode.ManualReset);
// Attach API event handler
Rx.Net.ApiLF.CamImageAvailable += new Rx.Net.ApiLF.CamImageAvailableHandler(ImageCallback);
.
.
.
}
// The Raytrix light field camera signaled that an image is present. At this point the programmer must ensure thread
// safeness. In this example we used a basic method to process the images coming from the camera. When an image callback is handled
// an event is set that shows that currently a grab is in progress. This makes sure that one image at a time is processed.
// If no image is processed the NewImage function is invoked which processes the image in the GUI thread.
public void ImageCallback(uint uCamIdx)
{
try
{
// We have to take precautions that the thread of our custom program is not flooded with too many BeginInvokes, thus we only allow one
if (!m_evGrabInProcess.WaitOne(0))
{
// Signalize that a grab is in progress
m_evGrabInProcess.Set();
// Invoke the image processing
BeginInvoke(new DisplayImageHandler(NewImage));
}
}
catch (Rx.Net.RxException xEx)
{
//Handle exception
}
}
.
.
.
// If a new image should be processed, it must be verified that no one else is currently in the critical section. If we can enter
// the critical section it must be ensured that the camera has not been stopped. If the camera is not stopped we can retrieve the camera
// image and process it.
public void NewImage()
{
try
{
// Wait until it is safe to enter.
mMutex.WaitOne();
// Copy the image into the bound API image
.
.
.
// We leave the critical section so we can release the mutex
mMutex.ReleaseMutex();
// The image has been processed -> so we can reset the event
m_evGrabInProcess.Reset();
}
catch (Rx.Net.RxException xEx)
{
//Handle exception
}
}