Video grabber crop to image issue

Hello,

i have an issue with the ofPixels::cropTo()
When declaring ofImage, croping and drawing in ofApp::draw() function, it works

 ofImage scanLine;
 scanLine.allocate(1, 720, OF_IMAGE_COLOR);
 video.getPixels().cropTo(scanLine, scanPosition, 0, 1, 720);
 fbo.begin();
 scanLine.draw(colNumber, 0, 1, 720);
 fbo.end();

when trying to split the code like so, it doesn’t work anymore…
Am I doing something wrong ?

//.h
ofImage scanLine;

// setup()
scanLine.allocate(1, 720, OF_IMAGE_COLOR);

// update()
video.update();
video.getPixels().cropTo(scanLine, scanPosition, 0, 1, 720);

// draw()
    fbo.begin();
    scanLine.draw(colNumber, 0, 1, 720);
    fbo.end();

maybe you have to call scanLine.update() after cropTo

hello,

thanks for the suggestion, but no luck

This doesn’t solve your cropTo issue but maybe it would be faster to do this with 2 fbos and masking to avoid the allocation;

class ofApp : public ofBaseApp{
public:
    
    int yCounter;
    ofFbo screenlineFBO;
    ofFbo drawFBO;
    
    
    ofVideoPlayer video;
    
    int scanlineHeight = 1;
    void setup()
    {
        
        video.load("fingers.mov");
        video.play();
        
        screenlineFBO.allocate(video.getWidth(), scanlineHeight);
        screenlineFBO.begin();
        ofClear(255);
        screenlineFBO.end();
        
        drawFBO.allocate(video.getWidth(), video.getHeight());
        
        drawFBO.begin();
        ofClear(255);
        drawFBO.end();
        
        
        
    }
    void update()
    {
        video.update();
        if(video.isFrameNew())
        {
            screenlineFBO.begin();
            //ofClear(255);
            ofPushMatrix();
            ofTranslate(0, yCounter);
            video.draw(0, 0);
            ofPopMatrix();
            screenlineFBO.end();
            
            
            drawFBO.begin();
            screenlineFBO.draw(0, ofRandom(video.getHeight()) );
            drawFBO.end();
            
            if(yCounter+scanlineHeight < video.getHeight())
            {
                yCounter+=scanlineHeight;
            }else
            {
                yCounter = 0;
            }
        }
    }
    void draw()
    {
        
        drawFBO.draw(0, 0);
        video.draw(0, drawFBO.getHeight());
        screenlineFBO.draw(video.getWidth(), drawFBO.getHeight());
        
        ofDrawBitmapStringHighlight(ofToString(yCounter), 20, 20);
        
    }
    
    
};

or use ofTexture::drawSubsection, like:

// draw
video.getTexture().drawSubsection(...)

thanks @jvcleave for the suggestion, i will try it just for testing purpose.

thanks @arturo yes it seems a good and straightforward suggestion, i’ll have a look and see if it works.

For now i ended up doing it in two steps

    scanLine.setFromPixels(...); // get pixels from video
    scanLine.crop(...); // crop image

this is working as expected.

I don’t know why the first solution doesn’t work though. Should it work like that is there anything i did wrong ?