Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by govi627 · Jan 29, 2013 at 11:25 PM · particlessavewebcamtexturelibrarywebcam

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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!

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image govi627 · Jan 31, 2013 at 11:02 PM 0
Share

................

avatar image Julien-Lynge · Jan 31, 2013 at 11:06 PM 0
Share

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

avatar image govi627 · Feb 01, 2013 at 03:13 AM 0
Share

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!

avatar image govi627 · Feb 01, 2013 at 03:26 AM 0
Share

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;
 
 }
avatar image
2

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.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image govi627 · Jan 31, 2013 at 11:01 PM 0
Share

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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges