Linear Access to the image data

I am acquiring data from a Camera and following the tutorial provided: Getting Started with CVB.Net, it is trivial.

var device = LoadCameraDriver();
device.Stream.RingBuffer.ChangeCount(NUM_DRIVER_BUFFERS, DeviceUpdateMode.UpdateDeviceImage);
Stream stream = device.Stream;
stream .RingBuffer.LockMode = RingBufferLockMode.On;

stream .Start();
using (StreamImage image = await stream.WaitAsync())
                    {
                        Process(image);
                    }
stream.stop()

However after acquiring the image, I would like to process the image and to access to the image data linearly.

In my previous implementation with the C-style AI I used the method:

cvbbool_t GetLinearAccess  ( IMG  Img,  
  cvbdim_t  Plane,  
  void **  ppBaseAddress,  
  intptr_t *  pXInc,  
  intptr_t *  pYInc  
 ) 

I read the .Net API documentation but I couldn’t find a similar function for this purpose.

This access is available on the ImagePlane, e.g. to access the first plane:

LinearAccessData imageData = image.Planes[0].GetLinearAccess();

This gives you the BasePtr, XInc, and YInc as IntPtrs. This call will throw if linear access is not possible, though. To get around that you can call:

image.Planes[0].TryGetLinearAccess(out LinearAccessData imageData);

This does not throw, but returns false if not possible. You then have to use:

image.Planes[0].Vpat

By the way: if you know the pixel datatype upfront you can also use (for byte pixels):

LinearAccessData<byte> imageData = image.Planes[0].GetLinearAccess<byte>();

Additionally to the base pointer and increments you get an indexer to access the pixel data:

imageData[x, y] = 255 - imageData[x, y];

(This is convenient, but direct pointer access is faster.)

2 Likes