Invert video to negative

Hello. I’ve been working recently with a Blackmagic capture card thanks to the advise and guidance of some members of this forum and now I’m stuck with a problem. I want to take the video that I’m capturing and invert it when I activate a button from the Gui. I already did something similar before with a webcam by creating first an ofPixels object and allocating to it the video grabber, and then passing it to an ofTexture. I wanted to do something similar but the application crashes because of a segmentation fault.

void ofApp::update(){

    if(cam.update()) {

        //copiar frames a videoPix
        ofPixels& pixels = cam.getColorPixels();

            for(size_t i = 0; i < pixels.size(); i ++){
                videoPix[i] = 255 - pixels[i];


            for (size_t i = 0; i < pixels.size(); i ++){
                videoPix[i] = pixels[i];


void ofApp::draw(){
    ofBackgroundGradient(ofColor::white, ofColor::gray);
    //cam.drawColor(20,(((height/3) *2) - (576/2)),camWidth, camHeight);

    videoTex.draw(20,(((height/3) *2) - (576/2)),camWidth, camHeight);

Any idea?

whats your ofapp.h or where you declare everything? Perhaps there is an out-of-bounds access in videoPix in your update function.

Yes, sorry, here is where I declare the variables:

#pragma once
#include "ofxBlackMagic.h"
#include "ofxGuiExtended.h"
#include "ofMain.h"
#include <iostream>

class RateTimer {
    float lastTick, averagePeriod, smoothing;
    bool secondTick;
    RateTimer() :
    smoothing(.9) {
    void reset() {
        lastTick = 0, averagePeriod = 0, secondTick = false;
    void setSmoothing(float smoothing) {
        this->smoothing = smoothing;
    float getFramerate() {
        return averagePeriod == 0 ? 0 : 1 / averagePeriod;
    void tick() {
        float curTick = ofGetElapsedTimef();
        if(lastTick == 0) {
            secondTick = true;
        } else {
            float curDiff = curTick - lastTick;;
            if(secondTick) {
                averagePeriod = curDiff;
                secondTick = false;
            } else {
                averagePeriod = ofLerp(curDiff, averagePeriod, smoothing);
        lastTick = curTick;

class ofApp : public ofBaseApp{

		void setup();
		void update();
		void draw();
        void exit();

		void keyPressed(int key);
		void keyReleased(int key);
		void mouseMoved(int x, int y );
		void mouseDragged(int x, int y, int button);
		void mousePressed(int x, int y, int button);
		void mouseReleased(int x, int y, int button);
		void mouseEntered(int x, int y);
		void mouseExited(int x, int y);
		void windowResized(int w, int h);
		void dragEvent(ofDragInfo dragInfo);
		void gotMessage(ofMessage msg);
        ofxBlackMagic cam;
        RateTimer timer;

        ofBuffer buffer;

        int width = ofGetWidth();
        int height = ofGetHeight();

        int screenSize = (width, height);

        ofColor color;
        ofImage lastFrame;
        ofVideoGrabber grabber;

        ofPixels prueba;
        string test;


        ofxGui gui;
        int camWidth = 1024;
        int camHeight = 576;

        ofPixels videoPix;
        ofTexture videoTex;

        ofxGuiContainer *containerExample;
        ofxGuiGroup *groupExample;
        ofxGuiPanel *panelExample;

        ofParameterGroup settings;
        ofParameter<void> addOutput;
        ofParameterGroup project, inputFormat, directory;
        ofParameter<string> name, title, path;
        ofParameter<bool> invert, flip;
        ofParameter<int> filmFormat;

        ofxGuiTextField name2;
        ofxGuiPanel *panel1;



Sorry I didnt get back to you! But you can try accessing video pixels with setColor, not with square brakets in line

videoPix[i] = pixels[i];