I am working with C# and MonoDevelop, and wish to use certain hue values from the web camera feed as user input. To be exact; I have an 16x16 grid, and want to check for the colors red, green, blue and yellow in each of the squares of the grid, this corresponding to such colored blocks that the user will place in front of the camera in these positions. So far I have been successful in adding the camera-feed to a WebCamTexture, but I need a way of accessing the hue values in certain coordinates of it. Any ideas, and the more specific the better, are welcome.
Update:
I have tried using the WebCamTexture.GetPixel to access the pixel values, using the code below:
using UnityEngine; using System.Collections; public class CamTexture : MonoBehaviour { // Use this for initialization void Start () { WebCamTexture webcam = new WebCamTexture(); renderer.material.mainTexture = webcam; webcam.Play(); Debug.Log (webcam.GetPixel(100,100)); } // Update is called once per frame void Update () { } void OnGUI () { } }
But it seems like it is impossible to activate the WebCamTexture anywhere outside of the Start() function, while the GetPixel() function cannot access the webcam texture from outside of the same function it is created in; meaning that I cannot access the pixel values at regular intervals, such as events from the Update() or OnGUI(). As always, any help appreciated.