Quantcast
Channel: beginners - openFrameworks
Viewing all articles
Browse latest Browse all 4929

Faster way to process a video frame pixel by pixel

$
0
0

@cuinjune wrote:

Hi, I wonder if there’s more efficient way to modify a video frame pixel by pixel than the below example which I copied from videoGrabberExample.

In ofApp.h

    ofVideoPlayer video;
    ofPixels videoInverted;
    ofTexture videoTexture;
    int videoWidth, videoHeight;

In ofApp.cpp

//--------------------------------------------------------------
void ofApp::setup(){
    video.load("fingers.mov");
    video.play();
    videoWidth = video.getWidth();
    videoHeight = video.getHeight();
    videoInverted.allocate(videoWidth, videoHeight, OF_PIXELS_RGB);
    videoTexture.allocate(videoInverted);
}

//--------------------------------------------------------------
void ofApp::update(){
    video.update();
    ofPixels & pixels = video.getPixels();
    for(size_t i = 0; i < pixels.size(); i++){
        //invert the color of the pixel
        videoInverted[i] = 255 - pixels[i];
    }
    //load the inverted pixels
    videoTexture.loadData(videoInverted);
}

//--------------------------------------------------------------
void ofApp::draw(){
    videoTexture.draw(0, 0, videoWidth, videoHeight);
}

Screenshot of the resulting video:


Is there a more efficient method to process a video frame pixel by pixel?

Posts: 4

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 4929

Trending Articles