ofxOpenCv.blob / ofMesh to ofTexture

hello dear of-forum :slight_smile:

i’ve got a small newbie problem here… i’m very new to openframeworks and c++ in general…

the basic program works quite fine already, i’ve got an image slideshow and on top of it there is a ofVideoGrabber instance in combination with ofxOpenCv that acts as a mask.

grayImage = colorImage;
grayImage.brightnessContrast(brightness, contrast);

if (bLearnBakground == true) {
	grayBg = grayImage;	
	saveBg.save(bgFile, OF_IMAGE_QUALITY_BEST);
	bLearnBakground = false;
    // take the abs value of the difference between background and incoming and then threshold:
grayDiff.absDiff(grayBg, grayImage);

pixels = grayDiff.getPixels();

ofPixels lPixels = pixels.getChannel(0);

ofPixels lumPixels = maskPixels.getChannel(0);
ofPixels alpPixels = maskPixels.getChannel(1);

// masking
for (int y = 0; y < camHeight; y++) {
	for (int x = 0; x < camWidth; x++) {

		int idx = (y * camWidth) + x;

		lumPixels[idx] = 0;
		alpPixels[idx] = 255 - lPixels[idx];

// store pixels in maskPixels ofPixels
maskPixels.setChannel(0, lumPixels);
maskPixels.setChannel(1, alpPixels);

// load blurred maskPixels into ofTexture
maskTexture.loadData(maskPixels, GL_LUMINANCE_ALPHA);

but as i only need one big object being masked (and projected onto) i thought it might work better if i would use the blob function of openCv. the problem now is that i dont know how to get the shape of the blob into an ofImage (or even better an ofxGrayscaleImage) that i can handle it the same way (with blurring and masking) as i do in my code.

in this video you can see what it should look like in the end (thats an old video where the object was projected by dia-projectors infront of a black molton background).
and this video shows the stage i am in at the moment. instead of the object you see me infront of my pc… but i think you should see what i mean :wink:

thanks a lot in advance

if you look at the ofxCv example “example-contours-basic” you see how ofxCv::ContourFinder is used.

this addon allows you to get all sorts of data like below, what i found inside ContourFinder.h

		const vector<vector<cv::Point> >& getContours() const;
		const vector<ofPolyline>& getPolylines() const;
		const vector<cv::Rect>& getBoundingRects() const;

so, all you need to do in ofApp.cpp is

    for(int i=0; i< contourFinder.getPolylines().size();i++){
        ofSetColor(30*i, 30*i, 0);