- Home /
WebCamTexture, when are you updated?
I want to grab pixels from a webcam texture just as they arrive, but the pixels I receive using GetPixels32 (when didUpdateThisFrame is true) seem to be one frame behind when I compare to the original texture (displayed by GUI.DrawTexture). I've tried to grab the pixels on Update and LateUpdate.
When exactly is the texture updated?
UPDATE#1: When using OnPreCull, OnPreRender or OnPostRender then pixels and texture seem to be in sync. I still get some random time offsets, perhaps because I'm only grabbing pixels when didUpdateThisFrame is true =/
UPDATE#2: Using WatForEndOfFrame in a coroutine does not seem to fix the issue either.
Carl Emil
@CarlEmail Please add further information into the question rather than as an additional comment :)
Answer by whydoidoit · Mar 17, 2014 at 10:05 AM
You want to grab them inside a coroutine that waits for the end of the frame:
IEnumerator Grab() {
yield return new WaitForEndOfFrame();
//Grab pixels here
}
Then when it changes
StartCoroutine(Grab());
Thanks for the proposal. That doesn't seem to help either. I'm still a frame behind =/
I also tried to set the script execution order to execute the script first and last, without any improvement.
Perhaps try a yield return null then yield return new WaitForEndOfFrame?
Answer by Lanre · Mar 17, 2016 at 06:30 PM
If you are going to be running your application on iOS or Android, use NatCam. It provides access to the raw pixel data of the camera, the native buffer (for use with native plugins), and will soon have video recording support. It's worth a gaze and it's blazing fast.
Your answer
Follow this Question
Related Questions
Web Cam Texture on UI Panel 0 Answers
how to track object motion with webcam 0 Answers
wrong Webcam resolution microsoft surface 2 0 Answers
Webcam GetPixels is only returning black 1 Answer
Show a WebCamTexture with alpha 1 Answer