Down sample video and re-centre question

I have some questions about offsetting ofGetPixels

I down sampled my video (see top image), copied the pixels into ofPixels and created a dot matrix of circles. Im now getting repeated videos, I only want one and centred in the middle. (see lower image)


   -h
        ofVideoGrabber video;		//Declare the video player object

        ofxCvGrayscaleImage mask;
        ofPixels pixels;


   -cpp
        //put mask into pixels
         pixels = mask.getPixels();

        // draw the matrix
 for (int i =0; i<(ofGetWidth()/spacing); i++) {  
                for (int j = 0; j<(ofGetHeight()/spacing); j++) {
                    int locX = startPos + ( i * spacing);
                    int locY = startPos + ( j * spacing);
                    ofPushMatrix();
                    ofTranslate(locX, locY);
                    ofColor c = pixels.getColor(locX, locY);
                    int brightness = c.getBrightness();
                    float maxSize = spacing/2;
                    float radius = ofMap(brightness, 0, 255, 0, maxSize);
                    ofPushStyle();
                    ofSetColor(0);
                    ofDrawCircle(0, 0, maxSize);
                    ofPopStyle();
                    ofDrawCircle(0, 0, radius);
                    ofPopMatrix();

Any advice on how to do this?
Thanks in advance

Hi @Cuvner,

You are using the size of the screen instead of the size of the image.
Try something like this :

ofApp.cpp::setup(){

    // [...]
    w = bikers.getWidth();
    h = bikers.getHeight();
}
ofApp.cpp::draw(){

    float maxSize = spacing/2;
    for (int i =0; i<(w/spacing); i++) {
        for( int j = 0; j < (h / spacing); j++){
            
            int locX = startPos + ( i * spacing);
            int locY = startPos + ( j * spacing);
            ofPushMatrix();
            ofTranslate(locX, locY);
            ofColor c = bikers.getColor(locX, locY);
            int brightness = c.getBrightness();
            float radius = ofMap(brightness, 0, 255, 0, maxSize);
            ofPushStyle();
            ofSetColor(0);
            ofDrawCircle(0, 0, maxSize);
            ofPopStyle();
            ofPopMatrix();
            
        }
    }

Let me know if this helps,

Best,

P

1 Like

Thanks, yeh that worked!