Hi,
I have two ofxCvGrayscaleImages (640 x 480) captured from two webcams. I would like to merged them in a new one with the same height (480) but with double width (1280) in order to pass it to contourFinder. I created a third one and tried to add them and translate them both, but it didn’t work. Do I have to convert the ofxCvGrayscaleImage to ofPixels and them back again to ofxCvGrayscaleImage ir order no merge these two images or is there a better way?
Thanks!
So far a partial solution. I used a FBO to join the two video streams into a ofImage, but i cannot send this to ofxopencv, i need a solution to convert the ofimage into a ofxgrayscale. But i haven’t found yet.
#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
ofBackground(255,255,255);
vidGrabber.setDeviceID(0);
// vidGrabber.setDesiredFrameRate(30);
vidGrabber.initGrabber(640,480);
// vidGrabber.setVerbose(true);
vidGrabber2.setDeviceID(1);
// vidGrabber.setDesiredFrameRate(30);
vidGrabber2.initGrabber(640,480);
fbo.allocate(1280,480,GL_RGBA);
pix.allocate(1280, 480, 4);
}
//--------------------------------------------------------------
void testApp::update(){
vidGrabber.update();
vidGrabber2.update();
}
//--------------------------------------------------------------
void testApp::draw(){
fbo.begin();
vidGrabber.draw(0, 0, 640, 480);
vidGrabber2.draw(640, 0, 640, 480);
fbo.end();
tex = fbo.getTextureReference();
tex.readToPixels(pix);
pix.crop(0, 100, 1260, 100);
img.setFromPixels(pix);
// fbo.draw(0, 0, 1280, 480);
img.draw(0,500);
}
Problem solved:
void testApp::update(){
bool newFrame1 = false;
bool newFrame2 = false;
vidGrabber1.grabFrame();
vidGrabber2.grabFrame();
newFrame1 = vidGrabber1.isFrameNew();
newFrame2 = vidGrabber2.isFrameNew();
if(newFrame1 || newFrame2){
// put the 2 streams on a FBO
fbo.begin();
vidGrabber2.draw(0, 0, 320, 240);
vidGrabber1.draw(320,0,320,240);
fbo.end();
ofTexture tex = fbo.getTextureReference(); // from FBO to Texture
tex.readToPixels(pix); // from texture to pixels
colorImg.setFromPixels(pix); // from pixels to ofxCvImage
colorImg.flagImageChanged(); // update the iplm image
grayImage = colorImg;
grayDiff.absDiff(grayBg, grayImage);
grayDiff.threshold(threshold);
if (learnBackground == true){
if(newFrame1 && newFrame2){
grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading)
learnBackground = false;
}
}
contourFinder.findContours(grayDiff, 20, (640*480)/3, 1, false);
}
}
1 Like
Hey irminsul!
I need to do exactly that! Im trying your code but im having some problems. Can you tell me what did you have on draw()
in your final solution?
Thanks!