Hello,
I’m using the LiveTexture plugin for iOS in order to retrieve the camera feed of my device. The code for displaying my camera feed on a plane is the following - it works:
private Texture2D texture;
private GUIText textLog;
// Use this for initialization
void Start () {
texture = LiveTextureBinding.startCameraCapture(false, LTCapturePreset.Size1280x720);
renderer.sharedMaterial.mainTexture = texture;
LiveTextureBinding.setExposureMode(LTExposureMode.Locked);
textLog = GameObject.Find("LogText").GetComponent<GUIText>();
}
I would like to get the pixels of that video feed, I do the following however it doesn’t seem to work as the output value doesn’t change. What is wrong?
void Update (){
Color[] pixels = texture.GetPixels();
float averageLum = 0.0f;
foreach(Color pixel in pixels){
averageLum += (pixel.r * 0.299f) + (pixel.g * 0.587f) + (pixel.b * 0.114f);
}
averageLum /= pixels.Length;
textLog.text = "avg. luminosity: " + averageLum;
}
I also tried to replace texture.GetPixels by the following but it still doesn’t work!
pixels = (renderer.sharedMaterial.mainTexture as Texture2D).GetPixels();
EDIT: Note that if I replace all that LiveTexture thing on my Start with a WebCamTexture and then retrieve the pixels in Update with code below, it is working fine.
pixels = (renderer.material.mainTexture as WebCamTexture).GetPixels();