-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lots of cleanup. more to do!
- Loading branch information
Showing
12 changed files
with
667 additions
and
528 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ build/ | |
obj/ | ||
*.o | ||
*.app/ | ||
.svn/ | ||
.DS_* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* backgroundSubtractionExample.cpp | ||
* ofxControlPanelDemo | ||
* | ||
* Created by theo on 31/03/2010. | ||
* Copyright 2010 __MyCompanyName__. All rights reserved. | ||
* | ||
*/ | ||
|
||
#include "backgroundSubtractionExample.h" | ||
|
||
#include "backgroundSubtractionExample.h" | ||
|
||
//------------ | ||
void backgroundSubtractionExample::setup(int width, int height){ | ||
|
||
color.allocate(width, height); | ||
gray.allocate(width, height); | ||
thresh.allocate(width, height); | ||
background.allocate(width, height); | ||
|
||
threshAmnt = 29; | ||
numFrames = 0; | ||
} | ||
|
||
//----------- | ||
void backgroundSubtractionExample::update(unsigned char * pixelsIn, int width, int height ){ | ||
color.setFromPixels(pixelsIn, width, height); | ||
|
||
//convert the color image to grayscale | ||
gray = color; | ||
|
||
if( numFrames < 20 ){ | ||
background = gray; | ||
} | ||
|
||
if( mode == BG_ABS ){ | ||
//do absolute diff between the prev frame and current frame | ||
//all pixels that are different will show up as non-black | ||
thresh.absDiff(gray, background); | ||
}else if( mode == BG_GREATER ){ | ||
thresh = gray; | ||
thresh -= background; | ||
}else if( mode == BG_LESS ){ | ||
thresh = background; | ||
thresh -= gray; | ||
} | ||
|
||
//threshold to 0 or 255 value | ||
thresh.threshold(threshAmnt); | ||
|
||
numFrames++; | ||
} | ||
|
||
//----------- | ||
void backgroundSubtractionExample::draw(float x, float y){ | ||
ofSetColor(0xFFFFFF); | ||
gray.draw(x, y); | ||
background.draw(x + gray.width, y); | ||
thresh.draw(x, y + gray.height); | ||
} | ||
|
||
//----------- | ||
void backgroundSubtractionExample::setThreshold(int threshVal){ | ||
threshAmnt = (int)threshVal; | ||
} | ||
|
||
//----------- | ||
void backgroundSubtractionExample::captureBackground(){ | ||
background = gray; | ||
} | ||
|
||
//----------- | ||
void backgroundSubtractionExample::setDifferenceMode(int modeIn){ | ||
mode = (captureMode)modeIn; | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* backgroundSubtractionExample.h | ||
* ofxControlPanelDemo | ||
* | ||
* Created by theo on 31/03/2010. | ||
* Copyright 2010 __MyCompanyName__. All rights reserved. | ||
* | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "ofMain.h" | ||
#include "ofxOpenCv.h" | ||
|
||
typedef enum{ | ||
BG_ABS, | ||
BG_GREATER, | ||
BG_LESS | ||
}captureMode; | ||
|
||
class backgroundSubtractionExample{ | ||
|
||
public: | ||
|
||
//------------ | ||
void setup(int width, int height); | ||
void update(unsigned char * pixelsIn, int width, int height ); | ||
|
||
//----------- | ||
//here we add up all the directions from the | ||
//vector field and average them out to an overall | ||
//direction - this will be quite small so you will want | ||
//to scale it up. | ||
|
||
//----------- | ||
void draw(float x, float y); | ||
|
||
void setThreshold(int threshVal); | ||
void setDifferenceMode(int modeIn); | ||
void captureBackground(); | ||
|
||
ofxCvColorImage color; | ||
ofxCvGrayscaleImage gray; | ||
|
||
ofxCvGrayscaleImage background; | ||
ofxCvGrayscaleImage thresh; | ||
|
||
captureMode mode; | ||
|
||
int numFrames; | ||
float threshAmnt; | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.