Items with no label
3335 Discussions

Creating the simplest program with RSSDK

MWalz1
Beginner
1,111 Views

Dear Intel® RealSense Community,

One week ago I posted /message/516093# 516093 this here at the forum. But then I noticed, that I should better start with the simplest program which can be created: I am trying to initialize the RSSDK, listing all devices, select the probably best device, capture a single frame and then release everything. Unfortunately, it seems that I do not understand yet how all this is working. So I wrote this console application here:

# include "stdafx.h"

# include

# include

# include "include/streaming.h"

# include "pxcsensemanager.h"

# include "pxccapturemanager.h"

# include "pxccapture.h"

# include "pxcimage.h"

# include

# include

using namespace std;

static const int NPROFILES_MAX = 100;

static const int NDEVICES_MAX = 100;

static const int IDC_STATUS = 10000;

static const int ID_DEVICEX = 21000;

static const int ID_STREAM1X = 22000;

static const int IDXM_DEVICE = 0;

static const int IDXM_MODE = 1;

static const int IDXM_SYNC = 2;

int main()

{

// Create a PXCSession instance

PXCSession *session = PXCSession::CreateInstance();

// Create a PXCSenseManager instance

PXCSenseManager *sm = PXCSenseManager::CreateInstance();

// Create a PXCCaptureManager instance

PXCCaptureManager *cm = sm->QueryCaptureManager();

// Listing all devices to a map

PXCSession::ImplDesc desc_template = {};

desc_template.group = PXCSession::IMPL_GROUP_SENSOR;

desc_template.subgroup = PXCSession::IMPL_SUBGROUP_VIDEO_CAPTURE;

std::map devices;

if (session) {

for (int m = 0, iitem = 0;; m++) {

std::cout << m;

PXCSession::ImplDesc desc_return;

if (session->QueryImpl(&desc_template, m, &desc_return) < PXC_STATUS_NO_ERROR) break;

PXCCapture *capture = 0;

if (session->CreateImpl(&desc_return, &capture) < PXC_STATUS_NO_ERROR) continue;

for (int j = 0;; j++) {

PXCCapture::DeviceInfo dinfo;

if (capture->QueryDeviceInfo(j, &dinfo) < PXC_STATUS_NO_ERROR) break;

int id = ID_DEVICEX + (iitem++)*NDEVICES_MAX + j;

devices[id] = desc_return.iuid;

pxcCHAR devName[128];

memset(devName, 0, 128 * sizeof(pxcCHAR));

}

capture->Release();

}

}

// device is a PXCCapture::Device instance

PXCCapture::Device *device = cm->QueryDevice();

PXCCapture* capture = cm->QueryCapture();

//do something with a captured single frame

//...

//release all sessions

cm->Release();

sm->Release();

session->Release();

return 0;

}

Maybe you could correct my code and put some comments in it? I know I should use the camera in a separated thread, but for simplification I want to keep it as easy as possible.

On my Laptop there are two cameras available: an integrated webcam and the R200. My program should automatically identify the R200 and select it as a source camera. Is this possible?

By the way: As an orientation I used RSSDK Sample "Raw Streams (C++)" which was delivered with the installation.

Thank you a lot for your support!

Best regards,

Martin

------------ EDIT 1 ------------

I think it would be great if my program would provide these features:

  1. list all available devices in console
  2. select a device (user input)
  3. list all available modes
  4. select a mode (user input)
  5. capture a single frame
  6. display this picture or safe it to a file
  7. close the application

https://stackoverflow.com/questions/32174076/how-to-save-an-image-in-intel-realsensevisual-c Here I found a function to safe a picture as a BMP-file. Maybe you can help me on my way to achieve this?

------------ EDIT 2 ------------

Now I am able to capture a simple stream from the R200 camera and save this to a file:

const pxcCHAR *file = L"record.rssdk"; //filename for the record

cm->SetFileName(file, true); //true = record false = playback

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

// Initialize and Record 300 frames

sm->Init();

for (int i = 0; i<300; i++) {

// This function blocks until a color sample is ready

if (sm->AcquireFrame(true)

WriteToConsole("Capture frame...");

// Retrieve the sample

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

// Work on the image sample->color

//...

// Go fetching the next sample

sm->ReleaseFrame();

}

But I still want to select the device and the mode by hand to make sure I understand the complete camera setup. This will make it easier for me to create further applications.

0 Kudos
4 Replies
idata
Employee
202 Views

Hello Martin89,

 

 

Thanks for contacting Intel customer support.

 

 

We are investigating on your question, as soon as we have any information we will let you know.

 

 

Best Regards,

 

Juan N.
0 Kudos
MWalz1
Beginner
202 Views

Hi Juan,

Maybe you could explain to me how this function is working?

PXCCapture::Device *device = cm->QueryDevice();

Because now when I try to query a device for both RGB and Depth, no device is available. Even though I can see the camera in Windows' device tree. So how is it querying its device? And how can I ensure that it will query the R200? Before I was querying Depth stream it worked fine and it selected the R200 automatically.

Thank you a lot!

Best regards,

Martin

------------ EDIT 1 ------------

In case that my source code helps, here it is at my current version:

# include

# include

# include "stdafx.h"

# include

# include

# include

# include "pxcsensemanager.h"

# include "pxccapturemanager.h"

# include "pxccapture.h"

# include "pxcimage.h"

# include

# include

using namespace std;

static const int NPROFILES_MAX = 100;

static const int NDEVICES_MAX = 100;

static const int IDC_STATUS = 10000;

static const int ID_DEVICEX = 21000;

static const int ID_STREAM1X = 22000;

static const int IDXM_DEVICE = 0;

static const int IDXM_MODE = 1;

static const int IDXM_SYNC = 2;

static const int ResColor_X = 0;

static const int ResColor_Y = 0;

static const int ResDepth_X = 0;

static const int ResDepth_Y = 0;

void WriteToConsole(const char *txt)

{

std::cout << string((std::string(txt)) + " \n");

}

int main()

{

// Create a PXCSession instance

PXCSession *session = PXCSession::CreateInstance();

// Create a PXCSenseManager instance

PXCSenseManager *sm = session->CreateSenseManager();

if (sm) {

WriteToConsole("SessionManager created successfully!");

}

else {

WriteToConsole("Intitializing SessionManager failed!");

WriteToConsole("Abort!");

return 0;

}

// Create a PXCCaptureManager instance

PXCCaptureManager *cm = sm->QueryCaptureManager();

if (cm) {

WriteToConsole("CaptureManager created successfully!");

}

else {

WriteToConsole("Intitializing CaptureManager failed!");

WriteToConsole("Abort!");

return 0;

}

WriteToConsole("");

// Query device

PXCCapture::Device *device = cm->QueryDevice();

if (device) {

WriteToConsole("Device queried successfully!");

}

else {

WriteToConsole("Querying Device failed!");

WriteToConsole("Abort!");

return 0;

}

WriteToConsole("");

// Setup coordinate system

PXCSession::CoordinateSystem cs = session->QueryCoordinateSystem();

session->SetCoordinateSystem(PXCSession::COORDINATE_SYSTEM_FRONT_DEFAULT); // Z(camera) = X(robot's world) | X(camera) = Y(robot's world) | Y(camera) = Z(robot's world)

const pxcCHAR *file = L"record.rssdk"; //filename for the record

cm->SetFileName(file, true); //true = record false = playback

// select the color stream of size X*Y and depth stream of size X*Y

sm->EnableStream(PXCCapture::STREAM_TYPE_COLOR, ResColor_X, ResColor_Y);

sm->EnableStream(PXCCapture::STREAM_TYPE_DEPTH, ResDepth_X, ResDepth_Y);

PXCImage::ImageData data_color;

PXCImage::ImageData data_depth;

// Initialize and Record 300 frames

WriteToConsole("Initialize...");

sm->Init();

for (int i = 0; i<300; i++) {

// This function blocks until a color sample is ready

WriteToConsole("Acquire frame...");

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

{

WriteToConsole("Error while acquireing Frame...");

break;

}

// Retrieve the sample

WriteToConsole("Capturing frame...");

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

PXCImage *colorImg = sample->color;

PXCImage *depthImg = sample->depth;

WriteToConsole("Acquire access...");

colorImg->AcquireAccess(PXCImage::ACCESS_READ_WRITE, PXCImage::PIXEL_FORMAT_RGB24, &data_color);

depthImg->AcquireAccess(PXCImage::ACCESS_READ_WRITE, &data_depth);

// render the frame

//if (!renderColor->RenderFrame(colorImg)) break;

//if (!renderDepth->RenderFrame(depthImg)) break;

// Create the PXCProjection instance.

WriteToConsole("Creating projection...");

PXCProjection *projection = device->CreateProjection();

// color and depth image size.

WriteToConsole("Querying Image Info...");

PXCImage::ImageInfo cinfo = colorImg->QueryInfo();

PXCImage::ImageInfo dinfo = depthImg->QueryInfo();

// Calculate the map.

WriteToConsole("Calculating map...");

//PXCPointF32 *uvmap = new PXCPointF32[dinfo.width*dinfo.height];

PXCPoint3DF32 *Camera_XYZmap = new PXCPoint3DF32[dinfo.width*dinfo.height];

PXCPoint3DF32 *World_XYZmap = new PXCPoint3DF32[dinfo.width*dinfo.height];

//projection->QueryUVMap(depthImg, uvmap);

projection->QueryVertices(depthImg, Camera_XYZmap);

projection->ProjectDepthToCamera((dinfo.width*dinfo.height), Camera_XYZmap, World_XYZmap);

// Translate depth points uv[] to color ij[]

/*for (int i = 0; i<(dinfo.width*dinfo...

0 Kudos
MWalz1
Beginner
202 Views

Hello Intel® RealSense Community,

Is there really nobody who knows how the RSSDK is querying a device? Or did I just post a stupid question, because I am not a fulltime software developer? Maybe someone knows a workaround to avoid the "QueryDevice()"-function for my use case?

Best regards,

Martin

0 Kudos
idata
Employee
202 Views

Hello Martin89,

 

 

I apologize for the delay. Through the community we do not check or correct your code. Checking and correcting codes is out of the scope of this community.

 

 

Regarding a sample code or example to assist you with your development it would be recommended for you to check the DF_CameraViewer sample (in the following link) here you will find useful information for your development.

 

 

https://software.intel.com/sites/landingpage/realsense/camera-sdk/v1.1/documentation/html/sample_camera_viewer_cpp.html

 

 

Again I apologize for the delay in answering your question, thanks for your understanding.

 

 

Best Regards,

 

Juan N.
0 Kudos
Reply