Topic locked

How to get the camera image on the device

February 27, 2014 - 9:16am #1

I've been testing an app in Unity using the Unity Play webcam feature. An important part of this app (kind of the crucial feature, really) involves using the image from the camera directly, in combination with the AR plugin data.


Unfortunately, this is an area of difference between Unity Play and the built version on the device: the path I used to get the image/texture from the webcam within Unity, instead gives me a big ol' nothing on the device. Even more unfortunately, since that's on the device, I can't simply poke around the heirarchy like I could in the Unity editor to find it in the first place.

So, where is this texture stored on the device? How can I get at it?

How to get the camera image on the device

March 17, 2014 - 7:52am #8

Nice to hear it is working.


How to get the camera image on the device

March 17, 2014 - 6:35am #7


Thank you very much! I got it all working now :D

Only Problem was, that in the editor I had to use GRAYSCALE texture format (as written somewhere in vuforia's docs), but the resulting byte array contains an rgb bitmap anyways :D It even works fast enough, so I don't have to worry about texture pointers - thank you sooooo much :D

How to get the camera image on the device

March 11, 2014 - 2:10am #6

The camera texture on device (Android ro iOS) is generated at OpenGL level and does not expose an actual pixel array to Unity, as the texture is simply bind from OpenGL via a texture ID. So, this approach would work in Play Mode, but not on device.

Concerning the other approach:

Not all devices support RGB565:

some devices support RGB888 but not RGB565,

some other devices support RGB565 but not RGB888;

and some "lucky" devices support both formats.

So, you may need to choose the appropriate format depending on what your device supports.



How to get the camera image on the device

March 10, 2014 - 4:14pm #5


I think I'm stuck at the same point...

I'm using the video background texture access feature to apply shaders to the camera picture and now I need to get a byte array out of it.

I tried several different ways and it always works fine in the editor (getPixels returns an array with size > 1 & I actually can create bitmaps out of it) and never on android (size always 1). I also tried but I think, it doesn't work together with videobackground access (I see a picture but also get "RGB565 image is not available yet")...

Any help would be super nice - just stuck here and everything else is ready to be deployed :D

How to get the camera image on the device

March 3, 2014 - 4:11am #4

Ok, let's take a step back...

Why is it that the Background Texture Access sample does not display this problem and your code does?



How to get the camera image on the device

March 2, 2014 - 2:37pm #3

Working from that example, I've got the thing kind of working. There's one big problem, though: the camera texture it gives me is a smaller square and the rest is filled with black. (See attached screenshot) Only on the device, though. The camera texture received in the editor is correct. And yes, I have confirmed that it's the actual texture that is the source of this black border (It's not that the background rendering plane is offset, for example).

Probably related is that on the device QCARRenderer.Instance.IsVideoBackgroundInfoAvailable() never returns 'true'. Therefore, I've had to use my own numbers for the following function call:

            cameraBackgroundTexture = new Texture2D(640360TextureFormat.RGB565false);

Which number I use seem to have little or no bearing on this bug. I've used 1024x1024, 512x512, and 640x360 (the values I get in the editor), and they all look the same (presumably with differing levels of quality, but I don't really care about that and haven't checked.

Edit: I've also tested it on another device and it has the same problem. That's an iPhone 4 and iPad 4, so just about as different as you can get in terms of specs within iOS. So this is clearly not hardware-related.

One "design of the plugin" sort of side question: Why is it that I can only use the background texture when                 QCARRenderer.Instance.DrawVideoBackground is set to false? Is it just not concievable in the design of this plugin that I might want QCAR to draw the background (since it correctly handles things like aspect ratios and the camera image being drawn), but I also want programmatic access to this texture?

Having this plugin behave so radically differently between the editor and the device is honestly incredibly infuriating. It seems like every hour I've got something working perfectly in the editor, and then find that the way I got it working in the editor is completely incompatible with the plugin on the device and I have to write the whole thing over again. This project was done 5 days ago in the editor, and literally everything I wrote (in the 3 days before that) I've had to rewrite at least once, if not more than once, to get it to work on the device. And even with twice the amount of work I've put in on the device side, I am still lacking features and polish that the editor version has.

Image icon Screenshot 2014.03.02 16.35.52.png681.64 KB

How to get the camera image on the device

February 28, 2014 - 2:31am #2

Study the Background Texture Access sample, as this should demonstrate how to get access to the Camera feed so you can manipulate it.


Topic locked