Hi Scott,
I don't know if this will help, but I got the following pair of methods many moons ago from this forum and they work for me in C#. It converts the image byte array obtained from the RoboRealm API to a bitmap. Perhaps from there you could convert it into the OpenCV format (but I'm not familiar with that). This is in C# but you can probably easily translated it into C++.
--patrick
// This method grabs the image bytes for one frame from RoboRealm
// using the getImage() method and the marker name.
public void getImageBytes(string marker)
{
int width = 1280;
int height = 960;
byte[] imageData = new byte[width * height];
Dimension d = null;
while (d == null)
{
d =RoboRealm.getImage(marker, imageData, width * height);
RoboRealm.waitImage(1);
}
}
// Create RGB24 bitmap from Byte array
public Bitmap BitsToBitmapRGB24(Byte[] bytes, int width, int height)
{
//swap RGB to BGR
Byte tmp;
for (int x = 3; x < bytes.GetLength(0); x += 3)
{
tmp = bytes[(x + 2)];
bytes[x + 2] = bytes[x];
bytes[x] = tmp;
}
if (bytes.GetLength(0) < width * height * 3)
{
return null;
}
Bitmap bmp = new Bitmap(width, height, PixelFormat.Format24bppRgb);
int i;
BitmapData data = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.WriteOnly, bmp.PixelFormat);
if (data.Stride == width * 3)
{
Marshal.Copy(bytes, 0, data.Scan0, width * height * 3);
}
else
{
for (i = 0; i < bmp.Height; i++)
{
IntPtr p = new IntPtr(data.Scan0.ToInt32() + data.Stride * i);
Marshal.Copy(bytes, i * bmp.Width * 3, p, bmp.Width * 3);
}
}
bmp.UnlockBits(data);
return bmp;
}
|
|