1

New to this, I'm using Spinnaker SDK example for a FLIR (PointGrey) camera. I'm trying to convert the 'convertedImage' for use in a PictureBox in Windows Forms and get an error "Cannot implicitly convert type to 'System.Drawing.Image'. An explicit conversion exists (are you missing a cast?)". Can you give me an idea what I need to do? Thanks!

Tried everything including basic explicit casts.

//Part of Spinnaker SDK example:    
using (IManagedImage convertedImage = 
rawImage.Convert(PixelFormatEnums.Mono8))
{
    String filename = "TriggerQS-CSharp-";
    if (deviceSerialNumber != "")
    {
        filename = filename + deviceSerialNumber + "-";
    }
    Image testImage = convertedImage; 
}
ZF007
  • 3,708
  • 8
  • 29
  • 48
Eric
  • 13
  • 3
  • It probably means `Image testImage = (Image)convertedImage;`. Mind that `testImage` is declared in a `using` block. – Jimi May 12 '19 at 00:49
  • I think that's getting closer. Now I get: Unable to cast object of type 'SpinnakerNET.ManagedImage' to type 'System.Drawing.Image'. Will keep in mind the using block. – Eric May 12 '19 at 01:20

1 Answers1

0

I had the same problem. The Spinnaker type IManagedImage has a property called ManagedData, which is a 1d vector containing all the bytes of your image. If you have colors as in my example below, they are interleaved.

//cv.ManagedData is a one D array of all pixels in all colors

        int nx = 2592;
        int ny = 1944; //7776/3 = 2592  stride, i.e. rgb are interleaved
        byte[,,] data = new byte[ny, nx, 3];

        for (int j = 0; j < ny; j++)
        {
            for (int i = 0; i < nx; i++)
            {
                for (int k = 0; k < 3; k++)
                {
                    data[j,i, k] = cv.ManagedData[j * 3 * nx + 3 * i + k];
                }

            }
        }

        //emgu cv accepts the [,,] byte array
        Image<Bgr, Byte> im0 = new Image<Bgr, Byte>(data); 
roadrunner66
  • 7,772
  • 4
  • 32
  • 38