Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Russel · May 30, 2012 at 09:38 AM · androidioscolorbytearrayqcar

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.

Comment
Add comment · Show 27
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image whydoidoit · May 30, 2012 at 09:59 AM 0
Share

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?

avatar image sooncat · May 30, 2012 at 10:20 AM 0
Share

Is it neccessary to get the Color32? I think the value of byte[] is enough (which you want is a value "0" or "1" )

avatar image Russel · May 30, 2012 at 11:19 AM 0
Share

@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

avatar image whydoidoit · May 30, 2012 at 11:25 AM 0
Share

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.

avatar image Russel · May 30, 2012 at 12:36 PM 0
Share

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

Show more comments

3 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

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.

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · Jun 12, 2012 at 11:38 PM 0
Share

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..

avatar image ina · Jun 13, 2012 at 09:05 AM 0
Share

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);

avatar image ina · Jun 13, 2012 at 09:27 AM 0
Share

Actually, for some reason, I am unable to get byte[] bytes = cameraImage.Pixels; to complete, even after calling WaitForEndOfFrame right before..

avatar image sooncat · Jun 13, 2012 at 10:54 AM 0
Share

Before use texture2d.getPixel() you must set textureImporter.isreadable = true and reload the asset.

avatar image whydoidoit · Jul 18, 2012 at 04:37 PM 1
Share

I've added a link to the decoding article in my answer above

Show more comments
avatar image
3
Wiki

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]); }

Comment
Add comment · Show 8 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · Jun 03, 2012 at 10:15 PM 0
Share

did you get this to work?

avatar image ina · Jun 03, 2012 at 10:25 PM 0
Share

inefficiency way = inefficient way?

avatar image whydoidoit · Jun 07, 2012 at 12:57 PM 0
Share

That's also converting RGB8888 NOT RGB565 - see my routine below if your need RGB565

avatar image sooncat · Jun 13, 2012 at 10:12 AM 0
Share

Sure it works. Any format RGB565/888/444... can be changed in similar way.

And: "inefficiency => inefficient" forgive my poor English.

avatar image whydoidoit · Jun 13, 2012 at 10:37 AM 0
Share

$$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 ?

Show more comments
avatar image
0

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[])

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ina · Jul 10, 2012 at 03:55 AM 0
Share

it seems ReadPixels only works for ARGB32 or RGB24 and not RGBA32 ...

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges