Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

WebCamTexture Data for analysis

Discussion in 'Scripting' started by rpelmegov, May 30, 2020.

  1. rpelmegov

    rpelmegov

    Joined:
    Apr 10, 2018
    Posts:
    4
    Hello. Ask for help. I track a point of light using a web camera and position the 3d object in the appropriate coordinates. The image from the camera is located on the background on Canvas.

    The problem is that Unity first gets the image from the camera and outputs it to the background. And only in the next frame can I make calculations and place a 3d object. It turns out that the calculation of the coordinate is always one frame behind the image on the camera.

    Question. How can I get a picture from the camera in one frame and place a 3D object in the desired coordinates?
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,514
    This is the Unity timing diagram:

    https://docs.unity3d.com/Manual/ExecutionOrder.html

    But it doesn't explicitly say when the webcam is read.

    One possibility is to move your processing to LateUpdate() but that might not help.

    Another possibility is to keep 2 textures and switch between them and only show the previous frame, which should sync up with where you have moved the 3D object because both will be one frame late.