- Home /
Pixel Byte-Array to Color32-Array (Combine ZXing with Vuforia)
Maybe someone can help me. I need a Color32[] Array by calling GetPixels32(). Here is a good solution for an QR-Code Reader with webcam. How to decode QR code using Unity3D
Vuforia can unfortunately only give a byte array with...
Image.PIXEL_FORMAT mPixelFormat = Image.PIXEL_FORMAT.RGB565;
Image cameraImage = CameraDevice.Instance.GetCameraImage(mPixelFormat);
byte[] pixels = cameraImage.Pixels;
Does anyone have any idea how I can make a Pixel byte array to an Color32 array? Here is my question in the Vuforia Forum.
Maybe anyone have any other solutions for QR-Code decoding in Unity for Android and iOS. I would be very grateful for your help.
Hey, I really need to do this too, just haven't got round to it yet - I will post one shortly. I'm using a library to read QR codes alongside Vurforia, but I want barcodes too so I'm switching to ZXing.
By the way - I've had experience with QR Codes mixed with frame markers - are you intending to do something like that?
Is it neccessary to get the Color32? I think the value of byte[] is enough (which you want is a value "0" or "1" )
@whydoidoit Yes, I would like to read QR-codes in Unity with Vuforia. A best from the same video stream as Vuforia. In a pinch with a separate video stream for the QR-code reader. The best way is decoding at runtime, but a picture decoding is also good.
Have you an example for me? $$anonymous$$y email: Oliver-Ebert@web.de
I'm just using a QR code reader plug in at the moment - I'm switching to using ZXing because I want bar codes too. It's on my list for the next week or so. I found a website where someone had done it the other day - and I'm damned if I can remember where I stored the link. I wrote you a 565 to color32 converter in the answer below.
I've tried out QR codes embedded in frame markers - and that is fine, given enough spacing, but your problem is that the QR code decoders are looking for a relatively flat on image - so you get the frame marker quickly (at an angle) and then the QR is hard to get lined up.
Which QR-Code Plugin do you use? Antares QR Code? can you send me a code snippet?
Perhaps you mean? https://gist.github.com/2493916
Answer by whydoidoit · May 30, 2012 at 10:18 AM
Right here you go:
public Color32[] GetColorArray(byte[] rgb565Data)
{
if (rgb565Data.Length % 1 != 0)
throw new Exception("Must have an even length");
var colors = new Color32[rgb565Data.Length / 2];
for (var i = 0; i < rgb565Data.Length; i+=2)
{
colors[i / 2] = new Color32((byte)(rgb565Data[i] & 0xF8),
(byte)(((rgb565Data[i] & 7) << 5) | ((rgb565Data[i + 1] & 0xE0) >> 3)),
(byte)((rgb565Data[i + 1] & 0x1F) << 3),
(byte)1);
}
return colors;
}
Please see here for an article on using Vuforia and ZXing to decode barcodes and QR codes in a Unity game.
Hi $$anonymous$$ike: Actually, I tried c = GetColorArray (bytes); for (qrCam in the unity package linked above) two weeks ago but was not able to get it to return anything that zxing could read..
hmm I guess my main question is how do you fetch the byte array from the QCAR/vuforia camera input? is this the right way, or is there another way to fetch the bytes? byte[] bytes = tex.EncodeToPNG(); // tex is a screenshot c = GetColorArray (bytes);
Actually, for some reason, I am unable to get byte[] bytes = cameraImage.Pixels; to complete, even after calling WaitForEndOfFrame right before..
Before use texture2d.getPixel() you must set textureImporter.isreadable = true and reload the asset.
I've added a link to the decoding article in my answer above
Answer by sooncat · May 30, 2012 at 10:11 AM
Sorry to minunderstood the question.Pleas See Answers below by @whydoidoit
An inefficient way to change byte[] formated as RGB8888 to color[]: Color32[] temp = new Color32[pixels.Length/4]; for (int i = 0; i < pixels.Length / 4;i++ ) { temp[i] = new Color32(pixels[i * 4 + 2], pixels[i * 4 + 1], pixels[i * 4], pixels[i * 4 + 3]); }
That's also converting RGB8888 NOT RGB565 - see my routine below if your need RGB565
Sure it works. Any format RGB565/888/444... can be changed in similar way.
And: "inefficiency => inefficient" forgive my poor English.
$$anonymous$$y point is that you need to do the byte manipulation per my answer below to convert packed 565. But maybe you are suggesting that the pixels call automatically changes that ?
Answer by saschandroid · Jun 28, 2012 at 08:44 AM
If you just want to get a picture from the (vuforia-)videostream as Texture2D (to read via GetPixels32()) you can simply take a screenshot:
Texture2D screenshot = new Texture2D(Screen.width, Screen.height, TextureFormat.RGBA32, false);
screenshot.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);
screenshot.Apply();
Color32[] color = screenshot.GetPixels32();
PS: I don't know if it's fast enough (or slower than converting byte[] to Color32[])
it seems ReadPixels only works for ARGB32 or RGB24 and not RGBA32 ...
Your answer
Follow this Question
Related Questions
qcar unity project for android and ios 1 Answer
Transparent Detail on mobile 0 Answers
Huge iOS Build 1 Answer
Error while iOS compiling 0 Answers
Which mobile devices do not support stencil buffers? 1 Answer