Created
October 2, 2017 16:53
-
-
Save kidapu/4dfe901a6fa7b5bdb9d8a988f188e40b to your computer and use it in GitHub Desktop.
brightneess
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" | |
// lib | |
#include "ofxGui.h" | |
#include "ofxKinectV2.h" | |
#include "format.h" | |
class Const | |
{ | |
public: | |
// layout | |
const static int WIDTH = 1920; | |
const static int HEIGHT = 1080; | |
const static int DEPTH_WIDTH = 512; | |
const static int DEPTH_HEIGHT = 424; | |
const static int COLOR_WIDTH = 1920; | |
const static int COLOR_HEIGHT = 1080; | |
const static int W_MARGIN = 20; | |
const static int H_MARGIN = 20; | |
constexpr static float DEPTH_SCALE = 1.0; | |
constexpr static float COLOR_SCALE = 0.3; | |
}; | |
class ofApp : public ofBaseApp | |
{ | |
public: | |
ofxKinectV2 * _kinect; | |
ofTexture _texRGB; | |
ofShader _brightnessShader; | |
ofxPanel _gui; | |
ofParameter <float> _brightness; | |
void setup() | |
{ | |
// env | |
ofBackground(30, 30, 30); | |
// kinect | |
ofxKinectV2 tmp; | |
vector <ofxKinectV2::KinectDeviceInfo> deviceList = tmp.getDeviceList(); | |
_kinect = new ofxKinectV2(); | |
_kinect->open(deviceList[0].serial); | |
// gui | |
_gui.setup("", "settings.xml", 10, 10); | |
_gui.add( _brightness.set("brightness", 0.0,0.0,1.0)); | |
// shader | |
setupShader(); | |
} | |
void setupShader() | |
{ | |
string brightnessShader = R"( | |
uniform float Brightness; | |
uniform sampler2DRect tex; | |
void main() | |
{ | |
vec4 col = texture2DRect(tex, gl_TexCoord[0].xy); | |
col.r = clamp(col.r - Brightness, 0.0, 1.0); | |
col.g = clamp(col.g - Brightness, 0.0, 1.0); | |
col.b = clamp(col.b - Brightness, 0.0, 1.0); | |
gl_FragColor = vec4(col.r, col.g, col.b, 1.0); | |
} | |
)"; | |
_brightnessShader.setupShaderFromSource(GL_FRAGMENT_SHADER, brightnessShader); | |
_brightnessShader.linkProgram(); | |
} | |
void update() | |
{ | |
static int updatecount = 0; | |
_kinect->update(); | |
if( _kinect->isFrameNew() ) | |
{ | |
_texRGB.loadData( _kinect->getRgbPixels() ); | |
// save | |
ofPixels pixels; | |
_texRGB.readToPixels(pixels); | |
// img | |
if(updatecount % 3 == 0) | |
{ | |
ofImage img; | |
img.setFromPixels(pixels); | |
int milli = ofGetElapsedTimeMillis(); | |
string filename = fmt::format("kinect/file_{0:08}.jpg",milli) ; | |
img.save(filename); | |
} | |
updatecount++; | |
} | |
} | |
void draw() | |
{ | |
// env | |
ofClear(100); | |
ofSetColor(255); | |
// RGB | |
// _texRGB.draw(0, 0, Const::COLOR_WIDTH, Const::COLOR_HEIGHT); | |
// shader | |
_brightnessShader.begin(); | |
{ | |
_brightnessShader.setUniform1f("Brightness", _brightness); | |
_texRGB.draw(0, 0, Const::COLOR_WIDTH, Const::COLOR_HEIGHT); | |
} | |
_brightnessShader.end(); | |
// fps | |
stringstream ss; | |
ss << "framerate: " << ofToString(ofGetFrameRate(), 0); | |
ofDrawBitmapString(ss.str(), 10, 20); | |
// gui | |
ofSetColor(255); | |
_gui.draw(); | |
} | |
// void keyPressed(int key); | |
// void keyReleased(int key); | |
// void mouseMoved(int x, int y ); | |
// void mouseDragged(int x, int y, int button); | |
// void mousePressed(int x, int y, int button); | |
// void mouseReleased(int x, int y, int button); | |
// void mouseEntered(int x, int y); | |
// void mouseExited(int x, int y); | |
// void windowResized(int w, int h); | |
// void dragEvent(ofDragInfo dragInfo); | |
// void gotMessage(ofMessage msg); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment