structure

This commit is contained in:
micuat 2020-10-19 17:15:16 +02:00
parent 4aa1d62480
commit bdbd2c76af
2 changed files with 104 additions and 97 deletions

View file

@ -4,13 +4,8 @@
int camWidth = 640;
int camHeight = 480;
//--------------------------------------------------------------
void ofApp::setup()
void ofApp::setupKinect()
{
ofDisableArbTex();
ofSetVerticalSync(false);
//ofSetLogLevel(OF_LOG_VERBOSE);
ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices.";
// Open Kinect.
@ -25,15 +20,6 @@ void ofApp::setup()
}
// Load shader.
// auto shaderSettings = ofShaderSettings();
// shaderSettings.shaderFiles[GL_VERTEX_SHADER] = "shaders/render.vert";
// shaderSettings.shaderFiles[GL_GEOMETRY_SHADER] = "shaders/render.geom";
// shaderSettings.shaderFiles[GL_FRAGMENT_SHADER] = "shaders/render.frag";
// shaderSettings.bindDefaults = true;
// if (shader.setup(shaderSettings))
// {
// ofLogNotice(__FUNCTION__) << "Success loading shader!";
// }
shader.load("shaders/render.vert", "shaders/render.frag", "shaders/render.geom");
// Setup vbo.
@ -42,13 +28,10 @@ void ofApp::setup()
pointSize = 2.0f;
useColorSpace = false;
}
boundShader.allocate(ofGetWidth(), ofGetHeight());
boundShader.load("shaders/bound.frag");
fbos.insert({"ofcam", ofFbo()});
fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGB32F_ARB);
void ofApp::setupThermal()
{
// this must be called before init (otherwise fprintf will tell you so)
// note that high framerates will only function properly if the usb has enough bandwidth
// for example, a ps3 eye cam at 60 fps will only function when it has full USB 2.0 bandwidth available
@ -68,34 +51,118 @@ void ofApp::setup()
// we use a texture because the ofxV4L2 class has no draw method (yet)
// we use GL_LUMINANCE because the ofxV4L2 class supports only grayscale (for now)
v4l2Tex.allocate(camWidth, camHeight, GL_LUMINANCE);
}
void ofApp::setup()
{
ofDisableArbTex();
ofSetVerticalSync(false);
//ofSetLogLevel(OF_LOG_VERBOSE);
setupKinect();
setupThermal();
boundShader.allocate(ofGetWidth(), ofGetHeight());
boundShader.load("shaders/bound.frag");
fbos.insert({"ofcam", ofFbo()});
fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGB32F_ARB);
gradient.load("gradient.png");
}
//--------------------------------------------------------------
void ofApp::exit()
{
kinectDevice.close();
}
//--------------------------------------------------------------
void ofApp::update()
void ofApp::updateThermal()
{
v4l2Cam.grabFrame();
if (v4l2Cam.isNewFrame())
{
// v4l2Tex.loadData(v4l2Cam.getPixels(), camWidth, camHeight, GL_RED);
ofPixels p;
p.allocate(camWidth, camHeight, OF_PIXELS_RGB);
for (int i = 0; i < camHeight * camWidth; i++)
p.setColor(i, v4l2Cam.getPixels()[i]);
v4l2Tex.allocate(p);
// v4l2Tex.setRGToRGBASwizzles(true);
// ofLogError() << v4l2Cam.getPixels();
}
}
//--------------------------------------------------------------
void ofApp::update()
{
updateThermal();
}
void ofApp::drawKinect()
{
ofClear(0);
cam.begin();
ofEnableDepthTest();
// ofDrawAxis(100.0f);
ofPushMatrix();
ofRotateXDeg(180);
shader.begin();
shader.setUniform1f("uSpriteSize", pointSize);
int numPoints;
if (useColorSpace)
{
shader.setUniformTexture("uDepthTex", kinectDevice.getDepthInColorTex(), 1);
shader.setUniformTexture("uWorldTex", kinectDevice.getColorToWorldTex(), 2);
shader.setUniformTexture("uColorTex", kinectDevice.getColorTex(), 3);
shader.setUniformTexture("u_v4l2cam", v4l2Tex, 4);
shader.setUniformTexture("u_gradient", gradient, 5);
shader.setUniform2i("uFrameSize", kinectDevice.getColorTex().getWidth(), kinectDevice.getColorTex().getHeight());
shader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthInColorTex().getWidth(), kinectDevice.getDepthInColorTex().getHeight());
numPoints = kinectDevice.getColorTex().getWidth() * kinectDevice.getColorTex().getHeight();
}
else
{
shader.setUniformTexture("uDepthTex", kinectDevice.getDepthTex(), 1);
shader.setUniformTexture("uWorldTex", kinectDevice.getDepthToWorldTex(), 2);
shader.setUniformTexture("uColorTex", kinectDevice.getColorInDepthTex(), 3);
shader.setUniformTexture("u_v4l2cam", v4l2Tex, 4);
shader.setUniformTexture("u_gradient", gradient, 5);
shader.setUniform2i("uFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight());
shader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight());
numPoints = kinectDevice.getDepthTex().getWidth() * kinectDevice.getDepthTex().getHeight();
}
vbo.drawInstanced(GL_POINTS, 0, 1, numPoints);
shader.end();
ofPopMatrix();
cam.end();
}
void ofApp::drawMain()
{
ofDisableDepthTest();
auto tex = kinectDevice.getDepthTex();
boundShader.setUniformTexture("u_depth", tex);
boundShader.setUniformTexture("u_ofcam", fbos.at("ofcam"));
boundShader.setUniformTexture("u_v4l2cam", v4l2Tex);
boundShader.setUniformTexture("u_gradient", gradient);
boundShader.setUniform1i("u_init", 1);
boundShader.render();
boundShader.setUniform1i("u_init", 0);
for (int i = 0; i < 60; i++)
{
boundShader.render();
}
}
void ofApp::drawDebug()
{
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20);
}
void ofApp::draw()
{
ofBackground(0);
@ -103,72 +170,16 @@ void ofApp::draw()
if (kinectDevice.isStreaming())
{
fbos.at("ofcam").begin();
ofClear(0);
cam.begin();
ofEnableDepthTest();
// ofDrawAxis(100.0f);
ofPushMatrix();
ofRotateXDeg(180);
shader.begin();
shader.setUniform1f("uSpriteSize", pointSize);
int numPoints;
if (useColorSpace)
{
shader.setUniformTexture("uDepthTex", kinectDevice.getDepthInColorTex(), 1);
shader.setUniformTexture("uWorldTex", kinectDevice.getColorToWorldTex(), 2);
shader.setUniformTexture("uColorTex", kinectDevice.getColorTex(), 3);
shader.setUniformTexture("u_v4l2cam", v4l2Tex, 4);
shader.setUniformTexture("u_gradient", gradient, 5);
shader.setUniform2i("uFrameSize", kinectDevice.getColorTex().getWidth(), kinectDevice.getColorTex().getHeight());
shader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthInColorTex().getWidth(), kinectDevice.getDepthInColorTex().getHeight());
numPoints = kinectDevice.getColorTex().getWidth() * kinectDevice.getColorTex().getHeight();
}
else
{
shader.setUniformTexture("uDepthTex", kinectDevice.getDepthTex(), 1);
shader.setUniformTexture("uWorldTex", kinectDevice.getDepthToWorldTex(), 2);
shader.setUniformTexture("uColorTex", kinectDevice.getColorInDepthTex(), 3);
shader.setUniformTexture("u_v4l2cam", v4l2Tex, 4);
shader.setUniformTexture("u_gradient", gradient, 5);
shader.setUniform2i("uFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight());
shader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight());
numPoints = kinectDevice.getDepthTex().getWidth() * kinectDevice.getDepthTex().getHeight();
}
vbo.drawInstanced(GL_POINTS, 0, 1, numPoints);
shader.end();
ofPopMatrix();
cam.end();
drawKinect();
fbos.at("ofcam").end();
ofDisableDepthTest();
auto tex = kinectDevice.getDepthTex();
boundShader.setUniformTexture("u_depth", tex);
boundShader.setUniformTexture("u_ofcam", fbos.at("ofcam"));
boundShader.setUniformTexture("u_v4l2cam", v4l2Tex);
boundShader.setUniformTexture("u_gradient", gradient);
boundShader.setUniform1i("u_init", 1);
boundShader.render();
boundShader.setUniform1i("u_init", 0);
for (int i = 0; i < 60; i++)
{
boundShader.render();
}
drawMain();
boundShader.draw(0, 0);
}
// v4l2Tex.draw(0, 0);
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20);
drawDebug();
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key)
{
if (key == 'w')
@ -185,52 +196,42 @@ void ofApp::keyPressed(int key)
}
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key)
{
}
//--------------------------------------------------------------
void ofApp::mouseMoved(int x, int y)
{
}
//--------------------------------------------------------------
void ofApp::mouseDragged(int x, int y, int button)
{
}
//--------------------------------------------------------------
void ofApp::mousePressed(int x, int y, int button)
{
}
//--------------------------------------------------------------
void ofApp::mouseReleased(int x, int y, int button)
{
}
//--------------------------------------------------------------
void ofApp::mouseEntered(int x, int y)
{
}
//--------------------------------------------------------------
void ofApp::mouseExited(int x, int y)
{
}
//--------------------------------------------------------------
void ofApp::windowResized(int w, int h)
{
}
//--------------------------------------------------------------
void ofApp::gotMessage(ofMessage msg)
{
}
//--------------------------------------------------------------
void ofApp::dragEvent(ofDragInfo dragInfo)
{
}

View file

@ -12,10 +12,16 @@ class ofApp
: public ofBaseApp
{
public:
void setupKinect();
void setupThermal();
void setup();
void exit();
void updateThermal();
void update();
void drawKinect();
void drawMain();
void drawDebug();
void draw();
void keyPressed(int key);