Get pixels from material displaying camera feed - LiveTexture Plugin

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

Well, i don’t know that “LiveTexture plugin” but it might be possible that the Texture the plugin generates isn’t readable. You can only call GetPixels on textures which are readable. Have you tried using GetPixels and then using SetPixels on a new Texture to see if the data got transferred? I think the Texture2D you got back is just a wrapper for a native texture which probably can’t be read since it doesn’t exist in program memory.

This Blit function worked better than ReadPixels. I’m pretty sure it’s just an abstraction of ReadPixels, fullscreen quad, etc.

Anyway, this is how I took a snapshot of the webcam and copied it to another texture.

// temporary render texture to draw the webcam to
RenderTexture _rt = new RenderTexture(Screen.width, Screen.height, 24);
Texture2D webcamTexture = LiveTextureBinding.startCameraCapture (true, LTCapturePreset.Size640x480);
RenderTexture snapshot = Graphics.Blit(webcamTexture, _rt);