I'm working on a project for school involving C#, Kinect, and Emgu CV. I fairly new to both C# and Emgu CV, so I may be missing something simple. What I am trying to do is use the image from the Kinect as an Emgu CV image for processing, but I keep getting an error. The error that comes up is "TypeInitializationException was unhandled" and "The type initializer for 'Emgu.Cv.CVInvoke' threw an exception."
The code I'm using to get the image from the Kinect is:
using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
{
if (colorFrame != null)
{
byte[] pixels = new byte[colorFrame.PixelDataLength];
colorFrame.CopyPixelDataTo(pixels);
int stride = colorFrame.Width * 4;
BitmapSource color = BitmapImage.Create(colorFrame.Width, colorFrame.Height,96, 96, PixelFormats.Bgr32, null, pixels, stride);
liveFeed.Source = color;
EmguCVProcessing(color);
}
else
{
return;
}
}
I also found some code that I am using to convert the BitmapSource to a Bitmap from: Is there a good way to convert between BitmapSource and Bitmap?
The code that isn't working is as follows:
void EmguCVProcessing(BitmapSource bitmap)
{
Bitmap bmp = GetBitmap(bitmap);
Image<Bgr, Byte> imgLiveFeed = new Image<Bgr, Byte>(bmp);
}
From what I can find, this should convert the Bitmap into an Emgu CV image but for some reason it isn't.
Just some more information:
InnerException: Make sure the file image is a valid managed assembly.
InnerException: Make sure you have supplied a correct file path for the assembly.
My best guess is that the program is using different versions of the .NET Framework, but I am unsure of how to fix this problem.