Last active
September 28, 2020 20:25
-
-
Save prisonerjohn/249987b76ba66d33b5ecf1f2d9d904ad to your computer and use it in GitHub Desktop.
Sensing Machines Computer Vision
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
#include "ofMain.h" | |
#include "ofApp.h" | |
int main() | |
{ | |
ofSetupOpenGL(1280, 720, OF_WINDOW); | |
ofRunApp(new ofApp()); | |
} |
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
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(1280, 720); | |
resultImg.allocate(1280, 720, OF_IMAGE_COLOR); | |
captureBackground.set("Capture BG", true); | |
hueThreshold.set("Hue Thresh", 180, 0, 360); | |
satThreshold.set("Sat Thresh", 127, 0, 255); | |
briThreshold.set("Bri Thresh", 127, 0, 255); | |
guiPanel.setup("BG Subtraction"); | |
guiPanel.add(captureBackground); | |
guiPanel.add(hueThreshold); | |
guiPanel.add(satThreshold); | |
guiPanel.add(briThreshold); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
ofPixels& grabberPix = grabber.getPixels(); | |
if (captureBackground) | |
{ | |
backgroundImg.setFromPixels(grabber.getPixels()); | |
captureBackground = false; | |
} | |
ofPixels& resultPix = resultImg .getPixels(); | |
for (int y = 0; y < grabberPix.getHeight(); y++) | |
{ | |
for (int x = 0; x < grabberPix.getWidth(); x++) | |
{ | |
ofColor grabColor = grabberPix.getColor(x, y); | |
ofColor bgColor = backgroundImg.getColor(x, y); | |
if (abs(grabColor.getHueAngle() - bgColor.getHueAngle()) > hueThreshold || | |
abs(grabColor.getSaturation() - bgColor.getSaturation()) > satThreshold || | |
abs(grabColor.getBrightness() - bgColor.getBrightness()) > briThreshold) | |
{ | |
resultPix.setColor(x, y, grabColor); | |
} | |
else | |
{ | |
resultPix.setColor(x, y, ofColor(0)); | |
} | |
} | |
} | |
resultImg.update(); | |
} | |
void ofApp::draw() | |
{ | |
resultImg.draw(0, 0, ofGetWidth(), ofGetHeight()); | |
guiPanel.draw(); | |
} |
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
#pragma once | |
#include "ofMain.h" | |
#include "ofxGui.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofVideoGrabber grabber; | |
ofImage backgroundImg; | |
ofImage resultImg; | |
ofParameter<bool> captureBackground; | |
ofParameter<int> hueThreshold; | |
ofParameter<int> satThreshold; | |
ofParameter<int> briThreshold; | |
ofxPanel guiPanel; | |
}; |
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
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(1280, 720); | |
resultImg.allocate(1280, 720, OF_IMAGE_COLOR); | |
captureBackground.set("Capture BG", true); | |
colorThreshold.set("Color Thresh", 120, 0, 255); | |
guiPanel.setup("BG Subtraction"); | |
guiPanel.add(captureBackground); | |
guiPanel.add(colorThreshold); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
ofPixels& grabberPix = grabber.getPixels(); | |
if (captureBackground) | |
{ | |
backgroundImg.setFromPixels(grabber.getPixels()); | |
captureBackground = false; | |
} | |
ofPixels& resultPix = resultImg .getPixels(); | |
for (int y = 0; y < grabberPix.getHeight(); y++) | |
{ | |
for (int x = 0; x < grabberPix.getWidth(); x++) | |
{ | |
ofColor grabColor = grabberPix.getColor(x, y); | |
ofColor bgColor = backgroundImg.getColor(x, y); | |
if (abs(grabColor.r - bgColor.r) > colorThreshold || | |
abs(grabColor.g - bgColor.g) > colorThreshold || | |
abs(grabColor.b - bgColor.b) > colorThreshold) | |
{ | |
resultPix.setColor(x, y, grabColor); | |
} | |
else | |
{ | |
resultPix.setColor(x, y, ofColor(0)); | |
} | |
} | |
} | |
resultImg.update(); | |
} | |
void ofApp::draw() | |
{ | |
resultImg.draw(0, 0, ofGetWidth(), ofGetHeight()); | |
guiPanel.draw(); | |
} |
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
#pragma once | |
#include "ofMain.h" | |
#include "ofxGui.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofVideoGrabber grabber; | |
ofImage backgroundImg; | |
ofImage resultImg; | |
ofParameter<bool> captureBackground; | |
ofParameter<int> colorThreshold; | |
ofxPanel guiPanel; | |
}; |
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
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(1280, 720); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
} | |
void ofApp::draw() | |
{ | |
grabber.draw(0, 0, ofGetWidth(), ofGetHeight()); | |
} |
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
#pragma once | |
#include "ofMain.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofVideoGrabber grabber; | |
}; |
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
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(1280, 720); | |
resultImg.allocate(1280, 720, OF_IMAGE_COLOR); | |
brightnessThreshold.set("Bri Thresh", 120, 0, 255); | |
guiPanel.setup("Threshold"); | |
guiPanel.add(brightnessThreshold); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
ofPixels& grabberPix = grabber.getPixels(); | |
ofPixels& resultPix = resultImg .getPixels(); | |
for (int y = 0; y < grabberPix.getHeight(); y++) | |
{ | |
for (int x = 0; x < grabberPix.getWidth(); x++) | |
{ | |
ofColor pixColor = grabberPix.getColor(x, y); | |
if (pixColor.getBrightness() > brightnessThreshold) | |
{ | |
resultPix.setColor(x, y, ofColor(255)); | |
} | |
else | |
{ | |
resultPix.setColor(x, y, ofColor(0)); | |
} | |
} | |
} | |
resultImg.update(); | |
} | |
void ofApp::draw() | |
{ | |
resultImg.draw(0, 0, ofGetWidth(), ofGetHeight()); | |
guiPanel.draw(); | |
} |
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
#pragma once | |
#include "ofMain.h" | |
#include "ofxGui.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofVideoGrabber grabber; | |
ofImage resultImg; | |
ofParameter<int> brightnessThreshold; | |
ofxPanel guiPanel; | |
}; |
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
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(1280, 720); | |
resultImg.allocate(1280, 720, OF_IMAGE_COLOR); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
ofPixels grabberPix = grabber.getPixels(); | |
ofPixels resultPix = resultImg .getPixels(); | |
for (int y = 0; y < grabberPix.getHeight(); y++) | |
{ | |
for (int x = 0; x < grabberPix.getWidth(); x++) | |
{ | |
ofColor pixColor = grabberPix.getColor(x, y); | |
resultPix.setColor(x, y, pixColor); | |
} | |
} | |
} | |
void ofApp::draw() | |
{ | |
resultImg.draw(0, 0, ofGetWidth(), ofGetHeight()); | |
} |
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
#pragma once | |
#include "ofMain.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofVideoGrabber grabber; | |
ofImage resultImg; | |
}; |
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
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(1280, 720); | |
resultImg.allocate(1280, 720, OF_IMAGE_COLOR); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
ofPixels& grabberPix = grabber.getPixels(); | |
ofPixels& resultPix = resultImg .getPixels(); | |
for (int y = 0; y < grabberPix.getHeight(); y++) | |
{ | |
for (int x = 0; x < grabberPix.getWidth(); x++) | |
{ | |
ofColor pixColor = grabberPix.getColor(x, y); | |
resultPix.setColor(x, y, pixColor); | |
} | |
} | |
resultImg.update(); | |
} | |
void ofApp::draw() | |
{ | |
resultImg.draw(0, 0, ofGetWidth(), ofGetHeight()); | |
} |
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
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(1280, 720); | |
resultImg.allocate(1280, 720, OF_IMAGE_COLOR); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
brightnessThreshold = ofMap(mouseX, 0, ofGetWidth(), 255, 0); | |
ofPixels& grabberPix = grabber.getPixels(); | |
ofPixels& resultPix = resultImg.getPixels(); | |
for (int y = 0; y < grabberPix.getHeight(); y++) | |
{ | |
for (int x = 0; x < grabberPix.getWidth(); x++) | |
{ | |
ofColor pixColor = grabberPix.getColor(x, y); | |
if (pixColor.getBrightness() > brightnessThreshold) | |
{ | |
resultPix.setColor(x, y, ofColor(255)); | |
} | |
else | |
{ | |
resultPix.setColor(x, y, ofColor(0)); | |
} | |
} | |
} | |
resultImg.update(); | |
} | |
void ofApp::draw() | |
{ | |
resultImg.draw(0, 0, ofGetWidth(), ofGetHeight()); | |
} | |
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
#pragma once | |
#include "ofMain.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofVideoGrabber grabber; | |
ofImage resultImg; | |
int brightnessThreshold; | |
}; |
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
#include "ofApp.h" | |
void ofApp::setup() | |
{ | |
grabber.setup(1280, 720); | |
resultImg.allocate(1280, 720, OF_IMAGE_COLOR); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
int brightnessThreshold = 128; | |
ofPixels& grabberPix = grabber.getPixels(); | |
ofPixels& resultPix = resultImg .getPixels(); | |
for (int y = 0; y < grabberPix.getHeight(); y++) | |
{ | |
for (int x = 0; x < grabberPix.getWidth(); x++) | |
{ | |
ofColor pixColor = grabberPix.getColor(x, y); | |
if (pixColor.getBrightness() > brightnessThreshold) | |
{ | |
resultPix.setColor(x, y, ofColor(255)); | |
} | |
else | |
{ | |
resultPix.setColor(x, y, ofColor(0)); | |
} | |
} | |
} | |
resultImg.update(); | |
} | |
void ofApp::draw() | |
{ | |
resultImg.draw(0, 0, ofGetWidth(), ofGetHeight()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Elie! On line 28 of
ofApp-bgRgb.cpp
, there's an extra space afterresultImg
Best,
BB