- Home /
Saving Webcam textures to separate particle system textures.
My project involves snapping pictures of peoples faces from a webcam and attaching them as particles of separate particle systems. I have successfully attached the live webcam to the particle system but I am unsure how to make still frames from the live feed. Should I create a folder outside of Unity that I can store the images, and then call on them for the particle system in Unity? If that makes sense how would I do that with JavaScript?
var captureTexture : WebCamTexture; function Start (){ webcamTexture = new WebCamTexture(); renderer.material.mainTexture = webcamTexture; webcamTexture.Play(); } function Update () { if(Input.GetMouseButtonDown(0)){ webCamSnapper[1] == WebCamTexture; Debug.Log("does it work?"); } }
I'll be happy to provide any more details, thank you for your help!
Joe
Answer by govi627 · Jan 30, 2013 at 06:13 AM
Hey thank you for your reply!
Could I trouble you for some coded examples? I looked at the provided links and saw:
GetPixels (x : int, y : int, blockWidth : int, blockHeight : int) : Color[]
Is this declared globally? What would fill the arguments? Example:
webcamTexture.GetPixels(0,0,?,?);
Are the X and the Y the location of where the block begins? And the 3rd and 4th parameter for how big the block is?
Once I have the pixel data how would I form a new texture with SetPixels?
Your help is very much appreciated!
Please add comments as comments, not answers.
There are several overloads for GetPixels. You can call it without any arguments, e.g. GetPixels().
You can do something like this: texture2.SetPixels(texture1.GetPixels());
Thanks for getting back to me. I am getting an error still with this
webcamTexture = new WebCamTexture();
webcamTexture.Play();
texture3.SetPixels(webcamTexture.GetPixels(0,0, 640,480));
When I run the script it says "cannot get pixels when webcam is not running". When I delete the texture3.SetPixels(webcameTexture.GetPixels(0,0,640,480)); line of code the camera runs fine. What is happening? Do you have a full code that works properly? Sorry I am desperate!
here is the whole code:
var captureTexture : WebCamTexture;
var texture2 : Texture2D;
function Start (){
webcamTexture = new WebCamTexture();
texture3 = new Texture2D(640,480);
webcamTexture.Play();
texture3.SetPixels(webcamTexture.GetPixels(0,0, 640,480));
renderer.material.mainTexture = texture3;
}
Answer by Julien-Lynge · Jan 30, 2013 at 02:58 AM
You don't need to go to the trouble of saving to disk unless you're going to run out of memory, or want the images to be available between runs of your application. You can get the color information of the current frame of webcam data with http://docs.unity3d.com/Documentation/ScriptReference/WebCamTexture.GetPixels.html - you can then use http://docs.unity3d.com/Documentation/ScriptReference/Texture2D.SetPixels.html to write it into a regular old Texture2D, which you can then save in memory and use as you wish.
Could I trouble you for some coded examples Julien? I am unsure about how to correctly use getpixels and setpixels after reading the docs. I thought I came close, but still no luck.
Your answer
Follow this Question
Related Questions
WebCameTexture.Play() Could not connect pins - RenderStream() 5 Answers
webcam Capture from webcam encountered: IndexOutOfRangeException: Array index is out of range 0 Answers
WebCam Texture scaling on iPhoneX 1 Answer
,iOS WebCamera Texture GetPixels() call returns only black colours? 1 Answer
WebCamTexture ERROR - Could not find specified video device 2 Answers