My code is all done thinking that the input Mat is in BGR format, so I am wondering if given an Image object in EmguCV, the property Mat from this object is always a BGR Mat. Otherwise, I would need to use CvtColor to get the BGR representation.
Example code:
byte[] data = GetPngPixelsArray(string); // Byte array in RGB format
Image<Rgb, byte> image = new Image<Rgb, byte>(width, height)
{
Bytes = data
};
CvInvoke.Imshow("image mat", image.Mat);
CvInvoke.WaitKey(0);
The function I am using to get the byte array data:
internal static byte[] GetPngPixelsArray(string filename)
{
byte[] rgbValues = null;
using (var imageIn = Image.FromFile(filename))
using (var bmp = new Bitmap(imageIn))
{
BitmapData bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height),
ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
IntPtr ptr = bmpData.Scan0;
int bytes = Math.Abs(bmpData.Stride) * bmp.Height;
rgbValues = new byte[bytes];
Marshal.Copy(ptr, rgbValues, 0, bytes);
bmp.UnlockBits(bmpData);
}
return rgbValues;
}
In the example code above, the Imshow function is showing the image properly, and as far as I know Imshow always made a representation of the image using the BGR format.
So in fact the image.Mat is in BGR format, but I've checked the EmguCV documentation and haven't found any declaration that this is as I stated.
