Items with no label
3335 Discussions

Multicam in C# -- processing the frameset

SChop3
Novice
2,223 Views

Hello, I'm looking at processing the data from multiple cameras in C# and I have a few questions with regards to the appropriate way of processing the dataset.

With a single camera

When there's only a single camera connected, I use the Pipeline class to get a frameset

pipeline = new Pipeline();

cfg = new Config();

PipelineProfile profile = pipeline.Start(cfg);

frames = pipeline.WaitForFrames();

depthframe = frames.DepthFrame;

colourframe = frames.ColorFrame;

To align the colour frame to the depth camera I use the Align class on the resulting frameset

FrameSet colourindepth = align.Process(frames);

With multiple cameras

Using code snippets from the examples, for multiple cameras I'm using a different approach. (Code simplified for brevity)

using (var ctx = new Context())

 

{

 

DeviceList cameras = ctx.QueryDevices();

// For now, going to loop through the cameras

 

foreach (Device camera in cameras)

 

{

FrameQueue depthqueue = new FrameQueue();

FrameQueue colourqueue = new FrameQueue();

SensorList sensors = camera.QuerySensors();

Sensor depthsensor = sensors[0];

 

var depth_profile = depthsensor.VideoStreamProfiles.First();

 

Sensor coloursensor = sensors[1];

 

var colour_profile = coloursensor.VideoStreamProfiles.First();

 

//Start sensors

 

depthsensor.Open(depth_profile);

 

depthsensor.Start(depthqueue);

coloursensor.Open(colour_profile);

 

coloursensor.Start(colourqueue);

 

// Receive frames

 

 

Frame colourframe = colourqueue.WaitForFrame();

 

Frame depthframe = depthqueue.WaitForFrame();

}

}

Questions

However, in this case I only fetch a single 'Frame' object at a time. How do I align the colourframe to depth?

I've tried to use the .waitforframeset method but it doesn't seem to be supported for this method. Also, the Align class requires a Frameset object?!

How do I get a frameset in this instance? Should I be using a pipeline to get the frames? Do I pass the handle to the camera when constructing a new pipeline?

Any help would be greatly appreciated

0 Kudos
1 Solution
SChop3
Novice
1,170 Views

Hello all,

I've worked on this looking for a workaround and have found that the key is to stick with the pipeline method. The configuration class allows you to create a custom pipeline based on a camera's serial number

I'm still starting with the camera context as before but this time I'm using a pipeline with a specified camera

  1. using (var ctx = new Context())
  2. {
  3. DeviceList cameras = ctx.QueryDevices();
  4. // For now, going to loop through the cameras
  5. foreach (Device camera in cameras)
  6. {
  7. cfg = new Config();
  8. cfg.Enabledevice(camera.Info[CameraInfo.SerialNumber])
  9. PipelineProfile profile = pipeline.Start(cfg);
  10. }

Then, when you use that profile object to wait for frames, it will wait for frames from the specified device and give you a frameset you can use in an Align object.

If anyone else is using C# for multicam I'd reccomend this approach.

Apologies if the code is slightly wrong, it's from memory.

View solution in original post

2 Replies
SChop3
Novice
1,171 Views

Hello all,

I've worked on this looking for a workaround and have found that the key is to stick with the pipeline method. The configuration class allows you to create a custom pipeline based on a camera's serial number

I'm still starting with the camera context as before but this time I'm using a pipeline with a specified camera

  1. using (var ctx = new Context())
  2. {
  3. DeviceList cameras = ctx.QueryDevices();
  4. // For now, going to loop through the cameras
  5. foreach (Device camera in cameras)
  6. {
  7. cfg = new Config();
  8. cfg.Enabledevice(camera.Info[CameraInfo.SerialNumber])
  9. PipelineProfile profile = pipeline.Start(cfg);
  10. }

Then, when you use that profile object to wait for frames, it will wait for frames from the specified device and give you a frameset you can use in an Align object.

If anyone else is using C# for multicam I'd reccomend this approach.

Apologies if the code is slightly wrong, it's from memory.

MartyG
Honored Contributor III
1,170 Views

Thanks so much for sharing your results with the community, Wiredchop! C# resources are always especially welcome.

0 Kudos
Reply