unmapped v4l2 thermal
This commit is contained in:
parent
ed61bd152f
commit
d0481fa0c6
6 changed files with 88 additions and 35 deletions
|
@ -1,2 +1,3 @@
|
|||
ofxAzureKinect
|
||||
ofxV4L2
|
||||
ofxShader
|
||||
|
|
|
@ -4,6 +4,7 @@ precision mediump float;
|
|||
|
||||
uniform sampler2D u_depth;
|
||||
uniform sampler2D u_ofcam;
|
||||
uniform sampler2D u_v4l2cam;
|
||||
uniform sampler2D u_buffer0;
|
||||
uniform sampler2D u_buffer1;
|
||||
|
||||
|
@ -16,7 +17,7 @@ uniform bool u_init;
|
|||
varying vec2 v_texcoord;
|
||||
|
||||
float depthToSilhouette(float depth) {
|
||||
if(depth < 0.005) return 0;
|
||||
if(depth <= 0.0) return 0;
|
||||
// if(depth > 0.1) return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
@ -97,7 +98,7 @@ void main() {
|
|||
minVal = min(minVal, tmp);
|
||||
}
|
||||
|
||||
if(maxVal - minVal > 0.1) {
|
||||
if(maxVal - minVal > 0.8) {
|
||||
dispColor.rgb = vec3(1);
|
||||
}
|
||||
|
||||
|
@ -105,7 +106,7 @@ void main() {
|
|||
gl_FragColor = vec4(dispColor, 1.0);
|
||||
gl_FragColor += pointCloudColor; // not good
|
||||
|
||||
// gl_FragColor = texture2D(u_depth, st) * 100;
|
||||
// gl_FragColor = texture2D(u_v4l2cam, st/3);
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -5,11 +5,12 @@ precision mediump float;
|
|||
// Custom attributes.
|
||||
|
||||
uniform sampler2D uColorTex; // Sampler for the color registered data
|
||||
uniform sampler2D u_v4l2cam;
|
||||
|
||||
in vec2 gTexCoord;
|
||||
|
||||
void main()
|
||||
{
|
||||
// gl_FragColor = texture2D(uColorTex, gTexCoord);
|
||||
gl_FragColor = vec4(1);
|
||||
gl_FragColor = texture2D(u_v4l2cam, gTexCoord/3);
|
||||
// gl_FragColor = vec4(1);
|
||||
}
|
|
@ -34,6 +34,9 @@ void main()
|
|||
posWorld.x = ray.x * posWorld.z;
|
||||
posWorld.y = ray.y * posWorld.z;
|
||||
|
||||
if(depth < 0.012) vValid = 0;
|
||||
if(depth > 0.04) vValid = 0;
|
||||
|
||||
// Flip X as OpenGL and K4A have different conventions on which direction is positive.
|
||||
posWorld.x *= -1;
|
||||
|
||||
|
|
|
@ -1,9 +1,14 @@
|
|||
#include "ofApp.h"
|
||||
|
||||
// some v4l2 global settings
|
||||
int camWidth = 640;
|
||||
int camHeight = 480;
|
||||
|
||||
//--------------------------------------------------------------
|
||||
void ofApp::setup()
|
||||
{
|
||||
ofDisableArbTex();
|
||||
ofSetVerticalSync(false);
|
||||
//ofSetLogLevel(OF_LOG_VERBOSE);
|
||||
|
||||
ofLogNotice(__FUNCTION__) << "Found " << ofxAzureKinect::Device::getInstalledCount() << " installed devices.";
|
||||
|
@ -35,7 +40,7 @@ void ofApp::setup()
|
|||
std::vector<glm::vec3> verts(1);
|
||||
vbo.setVertexData(verts.data(), verts.size(), GL_STATIC_DRAW);
|
||||
|
||||
pointSize = 1.0f;
|
||||
pointSize = 2.0f;
|
||||
useColorSpace = false;
|
||||
|
||||
boundShader.allocate(ofGetWidth(), ofGetHeight());
|
||||
|
@ -43,6 +48,26 @@ void ofApp::setup()
|
|||
|
||||
fbos.insert({"ofcam", ofFbo()});
|
||||
fbos.at("ofcam").allocate(ofGetWidth(), ofGetHeight(), GL_RGB32F_ARB);
|
||||
|
||||
// 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
|
||||
v4l2Cam.setDesiredFramerate(60);
|
||||
|
||||
// use this to set appropriate device and capture method
|
||||
v4l2Cam.initGrabber("/dev/video2", IO_METHOD_MMAP, camWidth, camHeight);
|
||||
|
||||
// some initial settings
|
||||
int set_gain = 2.0;
|
||||
bool set_autogain = true;
|
||||
|
||||
// rudimentary settings implementation: each settings needs a seperate call to the settings method
|
||||
v4l2Cam.settings(ofxV4L2_AUTOGAIN, set_autogain);
|
||||
v4l2Cam.settings(ofxV4L2_GAIN, set_gain);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
@ -54,6 +79,18 @@ void ofApp::exit()
|
|||
//--------------------------------------------------------------
|
||||
void ofApp::update()
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------
|
||||
|
@ -68,7 +105,7 @@ void ofApp::draw()
|
|||
cam.begin();
|
||||
ofEnableDepthTest();
|
||||
|
||||
ofDrawAxis(100.0f);
|
||||
// ofDrawAxis(100.0f);
|
||||
|
||||
ofPushMatrix();
|
||||
ofRotateXDeg(180);
|
||||
|
@ -83,6 +120,7 @@ void ofApp::draw()
|
|||
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.setUniform2i("uFrameSize", kinectDevice.getColorTex().getWidth(), kinectDevice.getColorTex().getHeight());
|
||||
shader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthInColorTex().getWidth(), kinectDevice.getDepthInColorTex().getHeight());
|
||||
|
||||
|
@ -93,6 +131,7 @@ void ofApp::draw()
|
|||
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.setUniform2i("uFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight());
|
||||
shader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight());
|
||||
|
||||
|
@ -109,14 +148,17 @@ void ofApp::draw()
|
|||
auto tex = kinectDevice.getDepthTex();
|
||||
boundShader.setUniformTexture("u_depth", tex);
|
||||
boundShader.setUniformTexture("u_ofcam", fbos.at("ofcam"));
|
||||
boundShader.setUniformTexture("u_v4l2cam", v4l2Tex);
|
||||
boundShader.setUniform1i("u_init", 1);
|
||||
boundShader.render();
|
||||
boundShader.setUniform1i("u_init", 0);
|
||||
for (int i = 0; i < 60; i++) {
|
||||
for (int i = 0; i < 60; i++)
|
||||
{
|
||||
boundShader.render();
|
||||
}
|
||||
boundShader.draw(0, 0);
|
||||
}
|
||||
// v4l2Tex.draw(0, 0);
|
||||
|
||||
ofDrawBitmapStringHighlight(ofToString(ofGetFrameRate(), 2) + " FPS", 10, 20);
|
||||
}
|
||||
|
@ -124,11 +166,11 @@ void ofApp::draw()
|
|||
//--------------------------------------------------------------
|
||||
void ofApp::keyPressed(int key)
|
||||
{
|
||||
if (key == OF_KEY_UP)
|
||||
if (key == 'w')
|
||||
{
|
||||
pointSize *= 2;
|
||||
}
|
||||
else if (key == OF_KEY_DOWN)
|
||||
else if (key == 's')
|
||||
{
|
||||
pointSize /= 2;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
#include "ofMain.h"
|
||||
|
||||
#include "ofxAzureKinect.h"
|
||||
|
||||
#include "ofxShaderFilter.h"
|
||||
|
||||
#include "ofxV4L2.h"
|
||||
|
||||
class ofApp
|
||||
: public ofBaseApp
|
||||
{
|
||||
|
@ -38,4 +41,6 @@ private:
|
|||
|
||||
float pointSize;
|
||||
bool useColorSpace;
|
||||
ofxV4L2 v4l2Cam;
|
||||
ofTexture v4l2Tex;
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue