Skip to content

Commit

Permalink
doubled all the stuff for a second camera
Browse files Browse the repository at this point in the history
  • Loading branch information
ben committed Nov 15, 2010
1 parent e4e8e60 commit c96d231
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 59 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -6,7 +6,7 @@
int main( ){

ofAppGlutWindow window;
ofSetupOpenGL(&window, 1024,768, OF_WINDOW); // <-------- setup the GL context
ofSetupOpenGL(&window, 1440,768, OF_WINDOW); // <-------- setup the GL context

// this kicks off the running of my app
// can be OF_WINDOW or OF_FULLSCREEN
Expand Down
119 changes: 74 additions & 45 deletions src/testApp.cpp
Expand Up @@ -4,65 +4,85 @@
//--------------------------------------------------------------
void testApp::setup(){

cam_1.loadMovie("fingers.mov");
cam_1.play();

#ifdef _USE_LIVE_VIDEO
vidGrabber.setVerbose(true);
vidGrabber.initGrabber(320,240);
#else
vidPlayer.loadMovie("fingers.mov");
vidPlayer.play();
#endif
cam_2.loadMovie("fingers.mov");
cam_2.play();

colorImg.allocate(320,240);
grayImage.allocate(320,240);
grayBg.allocate(320,240);
//grayDiff.setUseTexture(false);
grayDiff.allocate(320,240);
colorImg_1.allocate(320,240);
grayImg_1.allocate(320,240);
grayBg_1.allocate(320,240);
grayDiff_1.allocate(320,240);

colorImg_2.allocate(320,240);
grayImg_2.allocate(320,240);
grayBg_2.allocate(320,240);
grayDiff_2.allocate(320,240);

bLearnBakground = true;
threshold = 80;

thread.initAndSleep();
thread_1.initAndSleep();
thread_2.start();
}

//--------------------------------------------------------------
void testApp::update(){
ofBackground(100,100,100);

bool bNewFrame = false;
bool bNewFrame_1 = false;
bool bNewFrame_2 = false;

cam_1.idleMovie();
bNewFrame_1 = cam_1.isFrameNew();

cam_2.idleMovie();
bNewFrame_2 = cam_2.isFrameNew();

if (bNewFrame_1){

colorImg_1.setFromPixels(cam_1.getPixels(), 320,240);

grayImg_1 = colorImg_1;
if (bLearnBakground == true){
grayBg_1 = grayImg_1; // the = sign copys the pixels from grayImage into grayBg (operator overloading)
//##bLearnBakground = false;
}

// take the abs value of the difference between background and incoming and then threshold:
grayDiff_1.absDiff(grayBg_1, grayImg_1);
grayDiff_1.threshold(threshold);

// find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
// also, find holes is set to true so we will get interior contours as well....
//contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); // find holes
thread_1.setImage(grayDiff_1);

#ifdef _USE_LIVE_VIDEO
vidGrabber.grabFrame();
bNewFrame = vidGrabber.isFrameNew();
#else
vidPlayer.idleMovie();
bNewFrame = vidPlayer.isFrameNew();
#endif
blobs_1 = thread_1.getBlobs();

if (bNewFrame){
}

if (bNewFrame_2){

#ifdef _USE_LIVE_VIDEO
colorImg.setFromPixels(vidGrabber.getPixels(), 320,240);
#else
colorImg.setFromPixels(vidPlayer.getPixels(), 320,240);
#endif
colorImg_2.setFromPixels(cam_2.getPixels(), 320,240);

grayImage = colorImg;
grayImg_2 = colorImg_2;
if (bLearnBakground == true){
grayBg = grayImage; // the = sign copys the pixels from grayImage into grayBg (operator overloading)
grayBg_2 = grayImg_2; // the = sign copys the pixels from grayImage into grayBg (operator overloading)
bLearnBakground = false;
}

// take the abs value of the difference between background and incoming and then threshold:
grayDiff.absDiff(grayBg, grayImage);
grayDiff.threshold(threshold);
grayDiff_2.absDiff(grayBg_2, grayImg_2);
grayDiff_2.threshold(threshold);

// find contours which are between the size of 20 pixels and 1/3 the w*h pixels.
// also, find holes is set to true so we will get interior contours as well....
//contourFinder.findContours(grayDiff, 20, (340*240)/3, 10, true); // find holes
thread.setImage(grayDiff);
thread_2.setImage(grayDiff_2);

blobs = thread.getBlobs();
blobs_2 = thread_2.getBlobs();

}

Expand All @@ -73,36 +93,45 @@ void testApp::draw(){

// draw the incoming, the grayscale, the bg and the thresholded difference
ofSetHexColor(0xffffff);
colorImg.draw(20,20);
grayImage.draw(360,20);
grayBg.draw(20,280);
grayDiff.draw(360,280);
colorImg_1.draw(20,20);
grayImg_1.draw(360,20);
grayBg_1.draw(20,280);
grayDiff_1.draw(360,280);

// draw the incoming, the grayscale, the bg and the thresholded difference
ofSetHexColor(0xffffff);
colorImg_2.draw(700,20);
grayImg_2.draw(1040,20);
grayBg_2.draw(700,280);
grayDiff_2.draw(1040,280);

// then draw the contours:

ofFill();
ofSetHexColor(0x333333);
ofRect(360,540,320,240);
ofRect(1040,540,320,240);
ofSetHexColor(0xffffff);

// we could draw the whole contour finder
// contourFinder.draw(360,540);

// or, instead we can draw each blob individually,
// this is how to get access to them:
for (int i = 0; i < blobs.size(); i++){
blobs[i].draw(360,540);
for (int i = 0; i < blobs_1.size(); i++){
blobs_1[i].draw(360,540);
}

for (int i = 0; i < blobs_2.size(); i++){
blobs_2[i].draw(1040,540);
}

// finally, a report:

ofSetHexColor(0xffffff);
char reportStr[1024];
sprintf(reportStr, "bg subtraction and blob detection\npress ' ' to capture bg\nthreshold %i (press: +/-)\nnum blobs found %i, fps: %f", threshold, contourFinder.nBlobs, ofGetFrameRate());
sprintf(reportStr, "bg subtraction and blob detection\npress ' ' to capture bg\nthreshold %i (press: +/-)\nfps: %f", threshold, ofGetFrameRate());
ofDrawBitmapString(reportStr, 20, 600);

cout << thread.isThreadRunning() << endl;

}


Expand All @@ -122,10 +151,10 @@ void testApp::keyPressed (int key){
if (threshold < 0) threshold = 0;
break;
case 't':
thread.beginUpdate();
thread_1.beginUpdate();
break;
case 'z':
thread.pauseUpdate();
thread_1.pauseUpdate();
break;
}
}
Expand Down
20 changes: 7 additions & 13 deletions src/testApp.h
Expand Up @@ -25,26 +25,20 @@ class testApp : public ofBaseApp{
void mouseReleased(int x, int y, int button);
void windowResized(int w, int h);

#ifdef _USE_LIVE_VIDEO
ofVideoGrabber vidGrabber;
#else
ofVideoPlayer vidPlayer;
#endif
ofVideoPlayer cam_1, cam_2;

ofxCvColorImage colorImg;
ofxCvColorImage colorImg_1, colorImg_2;

ofxCvGrayscaleImage grayImage;
ofxCvGrayscaleImage grayBg;
ofxCvGrayscaleImage grayDiff;

ofxCvContourFinder contourFinder;
ofxCvGrayscaleImage grayImg_1, grayImg_2;
ofxCvGrayscaleImage grayBg_1, grayBg_2;
ofxCvGrayscaleImage grayDiff_1, grayDiff_2;

int threshold;
bool bLearnBakground;

SimpleThread thread;
SimpleThread thread_1, thread_2;

vector<ofxCvBlob> blobs;
vector<ofxCvBlob> blobs, blobs_1, blobs_2;


};
Expand Down

0 comments on commit c96d231

Please sign in to comment.