Draw inside ofxcvimage ( yep i tried the doc :) )

Hello ,

i’m trying to draw somes simples rectangles inside an ofxCvGrayscaleImage ,
the image is already loaded with a jpeg , but i want to add a white rectangle over it inside the ofxCvGrayscaleImage

I’ve tried the doc , but can’t understand the workflow before being able to do it

( texture / pixel / framebuffer ??? )

Can anyone point me a simple example ?

Thanks !

You should try ofxCv, I’ve had better experience with that addon. You can use the OpenCV api directly and then use the toCv and toOf methods.

See the examples and readme and you should be good to go!

Thanks for your answer , but i would prefer the native solution available on openframework

forget about the CV part :wink:

How can i draw a rectangle inside an ofImage ?

Thanks !

Maybe using an ofFbo?

    // load image
    ofImage img;
    img.load("kenSentMe.gif");

    // create an fbo that matches the image size
    ofFbo fbo;
    fbo.allocate(img.getWidth(), img.getHeight(), GL_RGB);
    
    fbo.begin();
    ofClear(255, 255, 255, 0);
    // draw the image on the fbo
    img.draw(0, 0);
    // decorate your image with stuff
    ofSetColor(255, 0, 0);
    ofDrawRectangle(10, 10, 40, 40);
    fbo.end();

    // transfer the fbo back to the image
    fbo.readToPixels(img.getPixels());
    img.update();