Problem with Bitmap in Spider

I have idea with transfer bitmap stream to PC without save as bmp on the device.

GHIElectronics.NETMF.USBHost.USBH_Webcam has only one supported format of streaming

private enum NativeFormat 
{
   YUV2 = 0
}

In spider device i get byte[] and transfer it into PC

var bmpData = bitmap.GetBitmap();

if use Util.BitmapToBMPFile(); we have normal BMP format (Screenshot - 16e50461af047d77b7812dcc9c82b756 - Gyazo), but this is so long operation, i dont want use it on device.

byte[] bmpFile = new byte[bitmap.Width * bitmap.Height * 3 + 54];
Util.BitmapToBMPFile(bmpData, bitmap.Width, bitmap.Height, bmpFile);

When i start decode YUV2 to BMP i have problem, i try many codecs. Can you help me with this problem?

PC decode sample

PC result pictures
Picture.407.YUY2.2.bmp (Screenshot - 434b8416de3ea3baebdd2b16009a5e80 - Gyazo)
Picture.407.YUY2.3.bmp (Screenshot - 752836096701569cd3b7621da45dab49 - Gyazo)
Picture.407.YUY2.4.bmp (Screenshot - fca4eeae9ca20a0f048d7d9a09307b88 - Gyazo)
Picture.407.YUY2.5.bmp (Screenshot - e65aadf55fd590da01da0cbdb2c348ec - Gyazo)

No one can help find right decoder ? 8(

To make sure I understand the question – are you taking a picture in Gadgeteer and want to convert to image on a PC?

If yes – does answer #2 here help?

No.
bitmap.GetBitmap() contains only raw bytes wits YUV2 format data (video format)
it has no header data.

I need decode into one of picture format (Bmp/Jpg/Png)

i already have try decode this byte[] as known format data with this sources:
[ul]Microsoft Learn: Build skills that open doors in your career
[ul]Microsoft Learn: Build skills that open doors in your career
[ul]Microsoft Learn: Build skills that open doors in your career
[ul]Microsoft Learn: Build skills that open doors in your career

How about this?

The USB camera puts out, i believe 16 bit.

Specialy for you


// Test 5
bmp2Data = ImageConvertors.YUV422ToTGB888(yuy2Data, 160, 120);
BMPwriter.Write(fileName + ".6.bmp", bmp2Data, 160, 120);


public static byte[] YUV422ToTGB888(byte[] buffer, int width, int height)
{
	int bufferLenght = width * height * 3;
	var result = new byte[bufferLenght];
	var resultOffset = 0;

	for (int y = 0; y < height; y++)
	{
		var lineOffset = y * 2 * width;
		YUV422ToTGB888_Calc(buffer, lineOffset, result, ref resultOffset, width);
	}

	return result;
}

private static void YUV422ToTGB888_Calc(byte[] buffer, int offset, byte[] result, ref int resOffset, int width)
{
	var w2 = width >> 1;
	var s = offset;
	while (w2-- != 0)
	{
		var C0 = buffer[s++] - 16;
		var D = buffer[s++] - 128;
		var C1 = buffer[s++] - 16;
		var E = buffer[s++] - 128;

		var R0 = YUVtoRGB_Clip((298 * C0 + 409 * E + 128) >> 8);
		var G0 = YUVtoRGB_Clip((298 * C0 - 100 * D - 208 * E + 128) >> 8);
		var B0 = YUVtoRGB_Clip((298 * C0 + 516 * D + 128) >> 8);

		result[resOffset++] = R0;
		result[resOffset++] = G0;
		result[resOffset++] = B0;

		var R1 = YUVtoRGB_Clip((298 * C1 + 409 * E + 128) >> 8);
		var G1 = YUVtoRGB_Clip((298 * C1 - 100 * D - 208 * E + 128) >> 8);
		var B1 = YUVtoRGB_Clip((298 * C1 + 516 * D + 128) >> 8);

		result[resOffset++] = R1;
		result[resOffset++] = G1;
		result[resOffset++] = B1;
	}
}

This is not.

Also try Y’UV420p (and Y’V12 or YV12) to RGB888 conversion


// Test 6 
bmp2Data = ImageConvertors.YUV422ToRGB888(yuy2Data, 160, 120);
BMPwriter.Write(fileName + ".7.bmp", bmp2Data, 160, 120);


		private static void YUV422ToTGB888_Match(byte Y, byte U, byte V, byte[] result, ref int resOffset)
		{
			var C = Y - 16;
			var D = U - 128;
			var E = V - 128;

			var R = YUVtoRGB_Clip((298 * C + 409 * E + 128) >> 8);
			var G = YUVtoRGB_Clip((298 * C - 100 * D - 208 * E + 128) >> 8);
			var B = YUVtoRGB_Clip((298 * C + 516 * D + 128) >> 8);

			result[resOffset++] = R;
			result[resOffset++] = G;
			result[resOffset++] = B;
		}


		public static byte[] YUV422ToRGB888(byte[] buffer, int width, int height)
		{
			int bufferLenght = width * height * 3;
			var result = new byte[bufferLenght];
			var resultOffset = 0;

			int total = width * height;
			for (int y = 0; y < height; y++)
			{
				for (int x = 0; x < width; x++)
				{
					var Y = buffer[y * width + x];
					var U = buffer[(y / 2) * (width / 2) + (x / 2) + total];
					var V = buffer[(y / 2) * (width / 2) + (x / 2) + total + (total / 4)];
					
					YUV422ToTGB888_Match(Y, U, V, result, ref resultOffset);
				}
			}

			return result;
		}

8((((( again miss

There http://www.fourcc.org/yuv.php#YUY2
describe codec YUY2 i write all of this format samples 8(

Have any idea?

Sorry no … I just have worked with the bitmaps in netmf.

If I understand what you ate doing correctly, you need to convert to BMP and then transfer. You can’t use the raw data.

Yes you understand correct, i dont want use conversion to bmp over device, i must decode raw bytes over PC.

i don’t want a hack encoding, i just want to use one standart decoding (if is it).

There is no raw data in NETMF, all you see is “bitmap” data but the ones coming from NETMF are not standard and you will not be able to work with them but the ones w give you are standard BMP. I am not sure why you are doing color conversion as this is way off. There is no color beside RGB on these systems.

USBH_Webcam has output


private enum NativeFormat : byte
{
    YUV2 = 0
}

I just want to use it for transfer data to PC.

Oh I see now. I never tried this and not sure how to handle this color format. But why not get BMP? Why do you need it YUV?

I need 15-20 FPS over PC for realtime fast stream.

YUV is not compressed, only different color format, if I am thinking correctly, so why you need this over BMP? How will this make things faster?

Please read my first post - there samples with different encoders - YUV2, YUYV, and else - i just can’t find the device encoder yet.