I am trying to show both the augmented and non-augmented camera feed in my app. I have the augmented feed on one side of the screen and another camera displaying on the other side of the screen. I am trying to get the image created by this example onto a plane so that I can point a camera at it. I attached the script to a plane and added a few lines so that the OnTrackablesUpdated() method looks like this:
void OnTrackablesUpdated() { if (mFormatRegistered) { if (mAccessCameraImage) { Vuforia.Image image = CameraDevice.Instance.GetCameraImage(mPixelFormat); if (image != null) { Debug.Log( "\nImage Format: " + image.PixelFormat + "\nImage Size: " + image.Width + "x" + image.Height + "\nBuffer Size: " + image.BufferWidth + "x" + image.BufferHeight + "\nImage Stride: " + image.Stride + "\n" ); byte[] pixels = image.Pixels; if (pixels != null && pixels.Length > 0) { Debug.Log( "\nImage pixels: " + pixels[0] + ", " + pixels[1] + ", " + pixels[2] + ", ...\n" ); } Texture2D texture = new Texture2D (10, 10); image.CopyToTexture (texture); this.GetComponent<Renderer> ().material.mainTexture = texture; } } } }
The plane still shows all gray. Any ideas what I'm doing wrong? Is there a standard way to display to non-augmented image that is different from what I am doing?
Also, the plane shows up in the augmented image when the target is recognized even though the plane is not a child of the target. I assume this means I am doing something fundamentally wrong. Is there a way to add objects to the scene without them showing up when targets are recognized?
Thank you in advance for any help.
Hello topaz123,
Hello topaz123,
There is a known issue with the CopyToTexture function. The work around for this issue is to immediately after the function, call Texture2D's Apply function.
For example, in your code do this:
That is great, thank you! To
That is great, thank you! To document for anyone having the same problem, it should be texture.Apply(), not image.Apply(). I ended up using GUI.DrawTexture and removed the plane.
That's correct, my apologies.
That's correct, my apologies. I'll update my code block to be accurate.
-Vuforia Support