Extracting video frames in three.js for future reference

Currently, I am utilizing three.js version r73 and have implemented a fragment shader that showcases video frames with code like this:

    gl_FragColor = texture2D( iChannel0,  uv);

My objective is to introduce another uniform (let's call it iChannel1) that stores the video frame displayed at an earlier stage. The plan is to use this for motion capture, edge detection, and similar functions.

Despite my efforts, I have not been successful in achieving this goal.

I believe I need to duplicate the video texture somehow using JavaScript and then assign it to iChannel1, but I am unsure of how to grab a frame.

One option could be capturing the canvas content, but there might be unwanted noise present on the canvas. I specifically require the video frame, not the surrounding canvas. Additionally, going through the canvas capture process seems inefficient. It feels like there should be a straightforward API call to capture the current video frame effectively for creating a texture used by iChannel1.

I explored UniformsUtils as well, but it didn't provide the solution I was seeking either.

Answer №1

After posting my question, I quickly discovered the solution myself. Oops!

For future reference, here is the method I used:

if (timeToCaptureFrame) {
    that.uniforms.iChannel1.value.image = that.uniforms.iChannel0.value.image;
    that.uniforms.iChannel1.value.needsUpdate = true;
}

It's important to note that iChannel1 must be initialized correctly for this approach to work. An example initialization would look like this:

var pathToSubtractionTexture = 'aStillImage.jpg';
(new THREE.TextureLoader()).load(pathToSubtractionTexture, function ( texture ) {
    that.uniforms.iChannel1.value = texture;
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the most efficient method for assigning a JSON array?

let vehicles = [{"x":1,"y":2},{"y":3,"z":5}]; let temporary=[]; [...vehicles].map((item)=>{ temporary.push(item) }) temporary[0]["x"]=3 console.log(vehicles[0]["x"]) // output -> 3`enter code here` How can we prevent the values in the vehicles arra ...

Update in Angular version 1.5.9 regarding $location.hashPrefix causing changes

Previously, the default $location.hashPrefix was an empty string until version 1.5.8 of AngularJS, but it was changed to "!" in version 1.5.9. This modification has caused issues in my codebase where there are instances like <a ng-ref="/Customer#/{{cu ...

AngularJS date formatting fails to properly format dates

{{ map.thedate }} The result is 2014-06-29 16:43:48 Even after using the following code, it still displays the same date as above. {{ map.thedate | date:'medium' }} ...

AngularJS confirmation directive for deleting items

I am currently utilizing this directive for a confirmation prompt when deleting an app. However, regardless of whether I click cancel or yes, the app still gets deleted. <small class="btn" ng-click="delete_app(app.app_id)" ng-show="app.app_id" ng-con ...

Angular 6: TypeError - The function you are trying to use is not recognized as a valid function, even though it should be

I'm currently facing a puzzling issue where I'm encountering the ERROR TypeError: "_this.device.addKeysToObj is not a function". Despite having implemented the function, I can't figure out why it's not functioning properly or callable. ...

When utilizing the built-in filter in Angular 2 ag-grid, the Clear Filter button efficiently removes any text from the filter box without needing to refresh the

When using ag-Grid's default filter feature, I noticed that the clear filter button only clears the text box and does not automatically refresh the column, even when the 'clearButton' and 'applyButton' parameters are set to true. T ...

The MaterialTable component is indicating that there is no property called 'tableData' on the IPerson type

Incorporated an editable attribute to my MaterialTable component. Currently looking for a way to retrieve the index of updated or deleted items within the onRowUpdate and onRowDelete methods. To replicate the issue, refer to this minimal sandbox example: ...

Increasing the Efficiency of Styled Components

It appears to me that there is room for improvement when it comes to checking for props in Styled Components. Consider the following code: ${props => props.white && `color: ${colors.white}`} ${props => props.light && `color: ${c ...

Join the nested object using the delimiter ';'

My objective is to concatenate all values from an object using a semi-colon as separator. This process works perfectly when the object consists of just one level: obj = { name: "one" additionalInfo: "hello" ... }; Object.values(obj).join(&ap ...

Learn the process of uploading an image to Firebase storage from the server side

I'm working on implementing an upload feature that utilizes Firebase storage on the server side. Here is the upload function on the server side: const functions = require("firebase-functions"); const admin = require("firebase-admin&quo ...

Execute javascript whenever the page is being loaded

Within my web application, I've implemented a modal popup with a loading bar to appear during any lengthy commands such as button clicks. While this feature is functioning well, there's an issue with the performance of the in-house web server it& ...

Error encountered when trying to access Proxy Object or Object[] in MobX with TypeScript

In my MobX Store, I have a straightforward structure: import { observable, action, makeObservable } from "mobx" import { BoxShadow, ShadowValues } from "./types" import { boxShadow } from "./constants" interface IStore { ...

Leveraging await with jsmediatags

Is there a way to implement Async/Await with jsmediatags for retrieving id3 tags? I am struggling to make it work, the current response format is cumbersome. {onSuccess:..., onError:...} I am looking for something along the lines of, let tags = await j ...

Ways to decrease the size of this item while maintaining its child components?

Here is an object that I am working with: { "name": "A", "children": [ { "name": "B", "open": false, "registry": true, "children": [ { ...

My three.js program isn't displaying anything on the screen, even though I'm confident that my

Currently, I am delving into the world of three.js with the aim of creating a 3D showroom showcasing a few planets. I have managed to create the moon, but alas, all that greets me upon running my code is a dismal black screen. Here's the code I have p ...

Refreshing Yii Dropdown List After Adding a New Item

Here is the code snippet I am working with: <p> <?php echo $form->labelEx($model,'phone_type'); ?> <span class="field"> <?php echo $form->dropDownList($model,'phone_type', CHtml::listData(PhonesT ...

Is it possible to generate a post automatically every second using an AJAX call, with no user input required?

Want to find the answer? Check out this link: Render a view in rails via AJAX and controller In my Rails application, I have a Post model that automatically creates and saves new posts while deleting old ones every 10 seconds using an AJAX call set withi ...

Parsing error: Unforeseen token encountered. Consider adding a supplementary loader to manage the output of these loaders

Could someone please break down this syntax message?.length === 1 and show me how to convert it into standard JavaScript? https://i.stack.imgur.com/20Ui6.png I am encountering an error when trying to use a Vue.js component that I downloaded from another ...

Determine the originating component in React by identifying the caller

Can you explain how to access the calling component in a React application? function MyCallingComponent() { return <MyReadingComponent/> } function MyReadingComponent() { console.log(callingComponent.state) } ...

Guide on transforming a JSON string into an array of custom objects using the json2typescript NPM module within a TypeScript environment

I am looking to utilize the json2typescript NPM module to convert a JSON string into an array of custom objects. Below is the code I have written. export class CustomObject { constructor(private property1: string, private property2: string, private p ...