Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 SUBOKKIM · Feb 02, 2021 at 11:40 AM · webcam

delay webcam in unity

Please help.. It's just a newbie who is just getting into the unity development. I thought about implementing a webcam and completed it. To get to the stage, we use our webcam to sprinkle hand movements in real time and react in seconds. Delaying was successfulalt text, but no camera rendering keeps popping up.

The error code is

UnassignedReferenceException: The variable renderCamera of DelayedCamera has not been assigned. You probably need to assign the renderCamera variable of the DelayedCamera script in the inspector. DelayedCamera.Awake () (at Assets/Scenes/DelayedCamera.cs:107)

The whole code is

using UnityEngine; using System.Collections;

public class DelayedCamera : MonoBehaviour { public struct Frame { ///

/// The texture representing the frame /// private Texture2D texture;

     /// <summary>
     /// The time (in seconds) the frame has been captured at
     /// </summary>
     private float recordedTime;

     /// <summary>
     /// Captures a new frame using the given render texture
     /// </summary>
     /// <param name="renderTexture">The render texture this frame must be captured from</param>
     public void CaptureFrom( RenderTexture renderTexture )
     {
         RenderTexture.active = renderTexture;

         // Create a new texture if none have been created yet in the given array index
         if ( texture == null )
             texture = new Texture2D( renderTexture.width, renderTexture.height );

         // Save what the camera sees into the texture
         texture.ReadPixels( new Rect( 0, 0, renderTexture.width, renderTexture.height ), 0, 0 );
         texture.Apply();

         recordedTime = Time.time;

         RenderTexture.active = null;
     }

     /// <summary>
     /// Indicates whether the frame has been captured before the given time
     /// </summary>
     /// <param name="time">The time</param>
     /// <returns><c>true</c> if the frame has been captured before the given time, <c>false</c> otherwise</returns>
     public bool CapturedBefore( float time )
     {
         return recordedTime < time;
     }

     /// <summary>
     /// Operator to convert the frame to a texture
     /// </summary>
     /// <param name="frame"></param>
     public static implicit operator Texture2D( Frame frame ) { return frame.texture; }
 }

 /// <summary>
 /// The camera used to capture the frames
 /// </summary>
 [SerializeField]
 private Camera renderCamera;

 /// <summary>
 /// The delay
 /// </summary>
 [SerializeField]
 private float delay = 0.5f;

 /// <summary>
 /// The size of the buffer containing the recorded images
 /// </summary>
 /// <remarks>
 /// Try to keep this value as low as possible according to the delay
 /// </remarks>
 private int bufferSize = 256;

 /// <summary>
 /// The render texture used to record what the camera sees
 /// </summary>
 private RenderTexture renderTexture;

 /// <summary>
 /// The recorded frames
 /// </summary>
 private Frame[] frames;

 /// <summary>
 /// The index of the captured texture
 /// </summary>
 private int capturedFrameIndex;

 /// <summary>
 /// The index of the rendered texture
 /// </summary>
 private int renderedFrameIndex;

 /// <summary>
 /// The frame index
 /// </summary>
 private int frameIndex;

 private void Awake()
 {
     frames = new Frame[bufferSize];

     // Change the depth value from 24 to 16 may improve performances. And try to specify an image format with better compression.
     renderTexture = new RenderTexture( Screen.width, Screen.height, 24 );
     renderCamera.targetTexture = renderTexture;
     StartCoroutine( Render() );
 }

 /// <summary>
 /// Makes the camera render with a delay
 /// </summary>
 /// <returns></returns>
 private IEnumerator Render()
 {
     WaitForEndOfFrame wait = new WaitForEndOfFrame();

     while ( true )
     {
         yield return wait;

         capturedFrameIndex = frameIndex % bufferSize;

         frames[capturedFrameIndex].CaptureFrom( renderTexture );

         // Find the index of the frame to render
         // The foor loop is **voluntary** empty
         for ( ; frames[renderedFrameIndex].CapturedBefore( Time.time - delay ) ; renderedFrameIndex = ( renderedFrameIndex + 1 ) % bufferSize ) ;

         Graphics.Blit( frames[renderedFrameIndex], null as RenderTexture );

         frameIndex++;
     }
 }

}

best regards

data-1.jpg (82.1 kB)
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

0 Replies

· Add your reply
  • Sort: 

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

109 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

using unity string plugin webcam 1 Answer

How to save a snapshot of the WebcamTexture? 3 Answers

WebCamTexture in the Windows Store App Platform. 0 Answers

Is there a way to track finger position using a webcam? 2 Answers

Problem background dropdown webcam 0 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