dummy point; do thermo 3d calc in update

This commit is contained in:
micuat 2020-10-26 11:45:54 +01:00
parent 700fdfdff1
commit 2dadffb8af
5 changed files with 61 additions and 45 deletions

View file

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ZONE_B>
<XY>-208, -257</XY>
<scale>2</scale>
<XY>-195.918, -220.408</XY>
<scale>1.869</scale>
<device>video3</device>
</ZONE_B>

View file

@ -7,6 +7,9 @@ uniform sampler2DRect u_world;
uniform sampler2DRect u_v4l2cam;
uniform sampler2DRect imageTexture;
uniform vec3 uHottest0;
uniform vec3 uHottest1;
in vec2 texCoordVarying;
in float vTemperature;
in float vAge;

View file

@ -19,8 +19,8 @@ uniform float elapsed;
uniform vec3 uHottest0;
uniform vec3 uHottest1;
uniform vec3 uColdest0;
uniform vec3 uColdest1;
uniform vec3 uHottest3d0;
uniform vec3 uHottest3d1;
in vec2 texCoordVarying;
@ -163,20 +163,14 @@ void main()
if(age < 0.001) { // targetting
target.w = 0;
if(random3(pos).x > pow(length(texCoordVarying.st - uHottest0.st)/5,16*16)+0) {
vec2 h = uHottest1.st;
vec4 hray = texture(u_world, h);
float hdepth = -depth * 65535.0;
if(hdepth == 0) hdepth = -0.01 * 65535.0;
vec3 H = vec3(hray.xy * hdepth, hdepth);
vec3 H = uHottest3d0;
H.z *= -1;
target.xyz = H + random3(pos);
target.w = 1;
}
else if(random3(pos).x > pow(length(texCoordVarying.st - uHottest1.st)/5,16*16)+0) {
vec2 h = uHottest0.st;
vec4 hray = texture(u_world, h);
float hdepth = -depth * 65535.0;
if(hdepth == 0) hdepth = -0.01 * 65535.0;
vec3 H = vec3(hray.xy * hdepth, hdepth);
vec3 H = uHottest3d1;
H.z *= -1;
target.xyz = H + random3(pos);
target.w = 1;
}

View file

@ -127,7 +127,7 @@ void ofApp::setupGui()
debugGui.setup("DEBUG");
debugGui.add(dummyMode.setup("dummy", true)); // should be false
debugGui.add(dummyXY.setup("XY", {0, 0}, {-400, -400}, {400, 400})); // should be false
debugGui.add(dummyXY.setup("XY", {256, 256}, {0, 0}, {511, 511})); // should be false
debugGui.add(debugFps.setup("FPS", "0"));
debugGui.setPosition(230, 10);
}
@ -158,6 +158,16 @@ void ofApp::exit()
kinectDevice.close();
}
ofVec3f ofApp::getDepthAt(int x, int y)
{
auto ray = kinectDevice.getDepthToWorldPix().getColor(x, y);
float depth = kinectDevice.getDepthPix().getColor(x, y).r;
if (depth == 0)
depth = 2000;
ofVec3f pos(ray.r * depth, ray.g * depth, depth);
return pos;
}
void ofApp::updateThermal()
{
v4l2Cam.grabFrame();
@ -204,6 +214,29 @@ void ofApp::updateThermal()
{
std::sort(hotspots.at(i).begin(), hotspots.at(i).end(), compareZThermal);
}
if (hotspots.size() > 0 && hotspots.at(0).size() > 0)
{
hotspot0 = hotspots.at(0).at(0);
}
if (dummyMode == false)
{
if (hotspots.size() > 1 && hotspots.at(1).size() > 0)
{
hotspot1 = hotspots.at(1).at(0);
}
else if (hotspots.size() > 0 && hotspots.at(0).size() > 1)
{
hotspot1 = hotspots.at(0).at(1);
}
}
else
{
hotspot1 = ofVec3f(dummyXY);
}
hotspot3d0 = getDepthAt(hotspot0.x, hotspot0.y);
hotspot3d1 = getDepthAt(hotspot1.x, hotspot1.y);
}
}
@ -226,35 +259,18 @@ void ofApp::onParticlesUpdate(ofxShader &shader)
shader.setUniform2i("uFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight());
shader.setUniform2i("uDepthFrameSize", kinectDevice.getDepthTex().getWidth(), kinectDevice.getDepthTex().getHeight());
if (hotspots.size() > 0 && hotspots.at(0).size() > 0)
{
shader.setUniform3f("uHottest0", hotspots.at(0).at(0));
}
if (hotspots.size() > 1 && hotspots.at(1).size() > 0)
{
shader.setUniform3f("uHottest1", hotspots.at(1).at(0));
}
else if (hotspots.size() > 0 && hotspots.at(0).size() > 1)
{
shader.setUniform3f("uHottest1", hotspots.at(0).at(1));
}
if (hotspots.size() > 0 && hotspots.at(0).size() > 0)
{
shader.setUniform3f("uColdest0", hotspots.at(0).back());
}
if (hotspots.size() > 1 && hotspots.at(1).size() > 0)
{
shader.setUniform3f("uColdest1", hotspots.at(1).back());
}
else if (hotspots.size() > 0 && hotspots.at(0).size() > 1)
{
shader.setUniform3f("uColdest1", hotspots.at(0).at(hotspots.at(0).size() - 2));
}
shader.setUniform3f("uHottest0", hotspot0);
shader.setUniform3f("uHottest1", hotspot1);
shader.setUniform3f("uHottest3d0", hotspot3d0);
shader.setUniform3f("uHottest3d1", hotspot3d1);
}
void ofApp::onParticlesDraw(ofxShader &shader)
{
shader.setUniform3f("uHottest0", hotspot0);
shader.setUniform3f("uHottest1", hotspot1);
shader.setUniform3f("uHottest3d0", hotspot3d0);
shader.setUniform3f("uHottest3d1", hotspot3d1);
}
void ofApp::drawMain()

View file

@ -23,6 +23,7 @@ public:
void setup();
void exit();
ofVec3f getDepthAt(int x, int y);
void updateThermal();
void update();
void drawMain();
@ -59,6 +60,8 @@ private:
ofxGpuParticles particles;
std::vector<std::vector<ofVec3f>> hotspots;
ofVec3f hotspot0, hotspot1;
ofVec3f hotspot3d0, hotspot3d1;
ofxVec2Slider registrationXY;
ofxFloatSlider registrationScale;