Last active
October 20, 2019 21:02
-
-
Save prisonerjohn/515bd4b263b739c294ada300bd7ecdf2 to your computer and use it in GitHub Desktop.
Sensing Machines Spout
This file contains hidden or 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() | |
{ | |
ofSetWindowShape(640, 480); | |
// Set up Spout receivers. | |
receiverGrabber.init("Video Input"); | |
receiverThreshold.init("Threshold Image"); | |
// Set parameters and GUI. | |
recvGrabber.set("Recv Grabber", true); | |
recvThreshold.set("Recv Threshold", false); | |
guiPanel.setup("Spout Recv", "settings.json"); | |
guiPanel.add(recvGrabber); | |
guiPanel.add(recvThreshold); | |
} | |
void ofApp::update() | |
{ | |
if (recvGrabber) | |
{ | |
// Draw grabber. | |
receiverGrabber.receive(texGrabber); | |
} | |
else if (recvThreshold) | |
{ | |
// Draw threshold. | |
receiverThreshold.receive(texThreshold); | |
} | |
} | |
void ofApp::draw() | |
{ | |
if (recvGrabber) | |
{ | |
// Draw grabber. | |
texGrabber.draw(0, 0); | |
} | |
else if (recvThreshold) | |
{ | |
// Draw threshold. | |
texThreshold.draw(0, 0); | |
} | |
guiPanel.draw(); | |
} | |
void ofApp::keyPressed(int key) | |
{ | |
if (key == ' ') | |
{ | |
receiverGrabber.selectSenderPanel(); | |
} | |
} |
This file contains hidden or 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" | |
#include "ofxSpout.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
void keyPressed(int key); | |
ofxSpout::Receiver receiverGrabber; | |
ofxSpout::Receiver receiverThreshold; | |
ofTexture texGrabber; | |
ofTexture texThreshold; | |
ofParameter<bool> recvGrabber; | |
ofParameter<bool> recvThreshold; | |
ofxPanel guiPanel; | |
}; |
This file contains hidden or 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() | |
{ | |
ofSetWindowShape(640, 480); | |
// Start video grabber. | |
grabber.setup(640, 480); | |
// Allocate threshold image (same size as video, single channel). | |
thresholdImg.allocate(640, 480, OF_IMAGE_GRAYSCALE); | |
// Set up Spout senders. | |
senderGrabber.init("Video Input"); | |
senderThreshold.init("Threshold Image"); | |
// Set parameters and GUI. | |
thresholdVal.set("Threshold Val", 127, 0, 255); | |
sendGrabber.set("Send Grabber", true); | |
sendThreshold.set("Send Threshold", true); | |
guiPanel.setup("Spout Send", "settings.json"); | |
guiPanel.add(thresholdVal); | |
guiPanel.add(sendGrabber); | |
guiPanel.add(sendThreshold); | |
} | |
void ofApp::update() | |
{ | |
grabber.update(); | |
if (grabber.isFrameNew()) | |
{ | |
// Threshold video image. | |
// Use references (&) when getting the ofPixels objects to | |
// avoid unnecessary copies. | |
ofPixels& videoPix = grabber.getPixels(); | |
ofPixels& thresholdPix = thresholdImg.getPixels(); | |
for (int row = 0; row < videoPix.getHeight(); row++) | |
{ | |
for (int col = 0; col < videoPix.getWidth(); col++) | |
{ | |
int pixVal = videoPix.getColor(col, row).getBrightness(); | |
if (pixVal < thresholdVal) | |
{ | |
thresholdPix.setColor(col, row, ofColor(0)); | |
} | |
else | |
{ | |
thresholdPix.setColor(col, row, ofColor(255)); | |
} | |
} | |
} | |
thresholdImg.update(); | |
if (sendGrabber) | |
{ | |
// Send grabber texture. | |
senderGrabber.send(grabber.getTexture()); | |
} | |
if (sendThreshold) | |
{ | |
// Send threshold texture. | |
senderThreshold.send(thresholdImg.getTexture()); | |
} | |
} | |
} | |
void ofApp::draw() | |
{ | |
thresholdImg.draw(0, 0); | |
guiPanel.draw(); | |
} |
This file contains hidden or 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" | |
#include "ofxSpout.h" | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
void setup(); | |
void update(); | |
void draw(); | |
ofVideoGrabber grabber; | |
ofImage thresholdImg; | |
ofxSpout::Sender senderGrabber; | |
ofxSpout::Sender senderThreshold; | |
ofParameter<int> thresholdVal; | |
ofParameter<bool> sendGrabber; | |
ofParameter<bool> sendThreshold; | |
ofxPanel guiPanel; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment