Pixel Delay on a Video

I get massive problems on Delaying Pixels depending on their speed in Windows openframeworks in this Function. Notice that i’ve Paused the Video before working with it.

        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
            inputMovie.setPosition((int)PixelIndexer[x][y]);
            inputMovie.update();
            unsigned char *color = inputMovie.getPixels();
            ofColor currPixColor;
            currPixColor.r = color[x+y*w];
            currPixColor.g = color[x+y*w]+1;
            currPixColor.b = color[x+y*w]+2;
            saveImage.setColor(x+y*w,currPixColor);
            }
        }

you are doing some heavy things inside this for loop:

  • setPosition on a movie is advancing to a certain frame
  • update is updating the pixels of the movie

I don’t know what w x h is but if it was 200 x 200, you’d be doing this 40,000 times inside the for loop. I think this really, really heavy. inputMovie.update() is doing alot, there’s memory moving around, things getting uploaded to the graphics card, etc. It can’t be run 40,000 times (or similar) in realtime.

If you need to access different frames of video at a per pixel level, maybe you can load the whole movie into memory? It will be slow at first to parse out the video to RAM, but then these calculations will be significantly faster and should work in realtime / without delay.

thanks 4 the fast reply. any code tips and suggestions how to do this, it dont have to run in realtime. so what’s the clean solution to this problem ?
My Idea would be to load the Frames of the movie into a vector and then access this vector.
Is this a better solution ?

the easiest might be to make a vector of ofPixels, or something similar. You can also store the data in one large array ( unsigned char pixels[ w * h * nFrames * 3 ]) or in a 2d or 3d array (pixels[nFrames][w*h], pixels[nFrames][w][h]);

I hope that helps!

Found a more elegant solution.

        for(int i = 0; i < currentFrameNumber; i++){
            inputMovie.setPosition(i);
            inputMovie.update();

            for(int y = 0; y < h; y++){
                for(int x = 0; x < w; x++){
                    if(((int)PixelIndexer[x][y] )== i){
                        unsigned char *color = inputMovie.getPixels();
                        ofColor currPixColor;
                        currPixColor.r = color[x+y*w];
                        currPixColor.g = color[x+y*w]+1;
                        currPixColor.b = color[x+y*w]+2;
                        saveImage.setColor(x+y*w,currPixColor);
                    }
                }
            }

        }

Still far away from realtime and still getting errors in the frame-rendering:
May I upload a rendered Frame here ?

sure [quote=“sebastian_schwa, post:5, topic:14412”]
May I upload a rendered Frame here ?
[/quote]

sure! post away…

But

Sorry, new users can not upload images.

sorry this is the default to prevent spam, changed you to basic user…

1 Like

Here we are:

half the image is missing and the pixels color is looking random.

So what this result makes me thinking is that i just jogling references around.
Is this possible ?

maybe this needs to be:

currPixColor.r = color[(x+y*w)*3  + 0];
currPixColor.g = color[(x+y*w)*3 + 1];
currPixColor.b = color[(x+y*w)*3 + 2];

Thanks thats one point I think =)

But with this code I get 3 small images o.o, now i’m confused.

I think this is wrong also:

saveImage.setColor(x+y*w,currPixColor);

should be something like:

saveImage.setColor(x, y, currPixColor);

Thanks that was another point.
But now I get just a still image with this code:

        for(int y = 0; y < h; y++){
            for(int x = 0; x < w; x++){
                PixelIndexer[x][y] += 1;
            }
        }

        int nChannels = inputMovie.getPixelsRef().getNumChannels();
        for(int i = 0; i < inputMovie.getTotalNumFrames(); i++){
            inputMovie.setPosition(i);
            inputMovie.update();

            for(int y = 0; y < h; y++){
                for(int x = 0; x < w; x++){
                    if( ((int)(floor(PixelIndexer[x][y]))) == i){
                        unsigned char *color = inputMovie.getPixels();
                        ofColor currPixColor;
                        currPixColor.r = color[(x+y*w)*nChannels + 0];
                        currPixColor.g = color[(x+y*w)*nChannels + 1];
                        currPixColor.b = color[(x+y*w)*nChannels + 2];
                        saveImage.setColor(x,y,currPixColor);
                    }
                }
            }

        }

even if I increment the PixelIndexer.

this:

unsigned char *color = inputMovie.getPixels();
ofColor currPixColor;
currPixColor.r = color[(x+y*w)*nChannels + 0];
currPixColor.g = color[(x+y*w)*nChannels + 1];
currPixColor.b = color[(x+y*w)*nChannels + 2];
saveImage.setColor(x,y,currPixColor);

can be simplified to:

saveImage.setColor(inputMovie.getPixelsRef().getColor(x,y));

also going to every frame of the movie and then over every pixel for each frame seems unnecessary but not sure what you are trying to do

thanks for that but I really try to copy the diffrent frames of a movie Pixel by Pixel into one Image of the new movie.

that was the wrong spot.

Here we are with the first result:
First Result of the PixelTimeShift-Filer