Getting Started with CVB.Net

Loading Image Stream Sources (Console)

Previously we have seen how to load and save single images with :cvb::

In Common Vision Blox we mostly deal with cameras which send a stream of images. So let’s have a look how to do this (with an AVI video for starters):

  1. Add namespaces (we only need Stemmer.Cvb.dll):

    using Stemmer.Cvb;
    using Stemmer.Cvb.Driver; // for IndexedStream
    using Stemmer.Cvb.Utilities; // for SystemInfo
    
  2. We use a tutorial video:

    var aviPath = Path.Combine
    (
      SystemInfo.InstallPath, 
      "Tutorial", 
      "Foundation", 
      "Videos", 
      "Cycling (xvid).avi" 
    );
    

    We get the :cvb: directory from CVB’s SystemInfo (which also contains defaults and license information).

  3. Stream sources are Devices:

    Device videoDevice = DeviceFactory.Open(aviPath);
    

    (everything that provides an image stream is a Device: vin-driver, avi and emu)

  4. And these have Streams and DeviceImages:

    IndexedStream stream = videoDevice.Stream as IndexedStream;
    DeviceImage deviceImage = videoDevice.DeviceImage;
    

With these objects we can print out some very basic information:

Console.WriteLine("Video:");
Console.WriteLine("  Resolution:  " + deviceImage.Size);
Console.WriteLine("  Color model: " + deviceImage.ColorModel);
Console.WriteLine("  Frames:      " + stream.ImageCount);

If we execute this, we get:

Video:
  Resolution:  [1024; 576]
  Color model: RGBGuess
  Frames:      300

We take a look into acquisition later on.

Quick Overview of the Types

Stream vs IndexedStream

The IndexedStream is a special kind of Stream. A Stream is a possibly endless stream of Images (e.g. from a camera). An IndexedStream is a finite stream with an ImageCount. To access this special property we needed to downcast the Stream into an IndexedStream via as. Both video-streams and emu-streams are indexed.

ColorModel and Planes

Perhaps you wondered about ColorModel.RGBGuess. :cvb: Images only know ImagePlanes. A Mono8 image would have one plane with a DataType DataTypes.Int8BppUnsigned (8 bit per pixel unsigned integer – or byte for short :slight_smile:). An RGB8 image on the other hand would have three planes with a byte DataType each.

This information is not enough to really determine the color model: YUV or HSV images also have three planes. When :cvb: was conceived 20 years ago, the Windows Bitmap was widely used and it only worked with monochrome or RGB images (even the indexed images resulted in RGB images). Thus we assumed three planes being RGB. (A lot of our algorithms actually do not care about the color model or even work on only one ImagePlane.)

If you use Stemmer.Cvb.Foundation.ConvertColorSpace methods, you get the actual ColorModel from the resulting images.

Image vs DeviceImage

A DeviceImage is a very special kind of Image. Normally the pixel buffer stays the same for a given Image. A DeviceImage on the other hand represents the latest image from a Device. The object stays the same, but the pixel buffer changes. Thus you should be careful when using these images when you process their image data – especially in multi-threaded environments. For display purposes on the other hand these images are perfect.

But the pixel buffer does not change randomly: only if you call one of the Stream.Wait or Stream.GetSnapshot methods. Acquisition will be handled later in more detail.

2 Likes