33 static const size_t FRAME_SIZE_640x480x16BIT = (640*480*2);
34 static const size_t FRAME_SIZE_640x480x32BIT = (640*480*4);
35 static const size_t FRAME_SIZE_512x424x32BIT = (512*424*4);
46 float margins[4]={0.0f, 0.0f, 0.0f, 0.0f};
68 if(!tex.isAllocated()) {
70 if(size == FRAME_SIZE_640x480x16BIT) {
71 tex.allocate(640, 480, GL_RGB);
73 ofLogWarning() <<
"Frame-size not supported by ofxDepthStream::loadDepthTexture16bit: " << size;
86 float edgeData[(int)tex.getWidth() * (int)tex.getHeight() * 3];
88 for (
int y = 0.0; y < tex.getHeight(); y++) {
89 for (
int x = 0.0; x < tex.getWidth(); x++) {
91 int posX = x + ((y - tex.getHeight() / 2.0) / (tex.getHeight() / 2.0)) * opts.keystone * (x - tex.getWidth() / 2.0);
94 int depthIndex = int((posX + y * tex.getWidth()) * 2);
98 uint16_t
depth = *((uint16_t*)(&((
char*)data)[depthIndex]));
99 int edgeIndex = (x + y * tex.getWidth());
106 && posX >= opts.margins[3]
108 && posX <= tex.getWidth() - opts.margins[1]
110 && y <= tex.getHeight() - opts.margins[2])
112 int correctMaxDistance = opts.maxDistance * (1.0 - opts.vertCorrection * (std::cos(M_PI / 3.0 * (tex.getHeight() - y) / tex.getHeight()) - 0.5));
113 if (
depth >= opts.minDistance &&
depth <= correctMaxDistance) {
114 float intensity = (
depth - opts.minDistance) / (
float)(correctMaxDistance - opts.minDistance);
115 edgeData[edgeIndex * 3 + 0] = 1 - intensity;
116 edgeData[edgeIndex * 3 + 1] = 1 - intensity;
117 edgeData[edgeIndex * 3 + 2] = 1 - intensity;
122 edgeData[edgeIndex * 3 + 0] = 0.0;
123 edgeData[edgeIndex * 3 + 1] = 0.0;
124 edgeData[edgeIndex * 3 + 2] = 0.0;
129 tex.loadData((
float*)edgeData, tex.getWidth(), tex.getHeight(), GL_RGB);
140 if(!tex.isAllocated()) {
142 if(size == FRAME_SIZE_640x480x32BIT) {
143 tex.allocate(640, 480, GL_RGB);
144 }
else if(size == FRAME_SIZE_512x424x32BIT){
145 tex.allocate(512, 424, GL_RGB);
147 ofLogWarning() <<
"Frame-size not supported by ofxDepthStream::loadDepthTexture32bit: " << size;
160 float edgeData[(int)tex.getWidth() * (int)tex.getHeight() * 3];
162 for (
int y = 0.0; y < tex.getHeight(); y++) {
163 for (
int x = 0.0; x < tex.getWidth(); x++) {
165 int posX = x + ((y - tex.getHeight() / 2.0) / (tex.getHeight() / 2.0)) * opts.keystone * (x - tex.getWidth() / 2.0);
168 int depthIndex = int((posX + y * tex.getWidth()) * 4);
169 int byte0 = ((
unsigned char*)data)[depthIndex + 0];
170 int byte1 = ((
unsigned char*)data)[depthIndex + 1];
171 int byte2 = ((
unsigned char*)data)[depthIndex + 2];
172 int byte3 = ((
unsigned char*)data)[depthIndex + 3];
173 int depth = byte0 << 24 | (byte1 & 0xFF) << 16 | (byte2 & 0xFF) << 8 | (byte3 & 0xFF);
175 int edgeIndex = (x + y * tex.getWidth());
182 && posX >= opts.margins[3]
184 && posX <= tex.getWidth() - opts.margins[1]
186 && y <= tex.getHeight() - opts.margins[2])
188 int correctMaxDistance = opts.maxDistance * (1.0 - opts.vertCorrection * (std::cos(M_PI / 3.0 * (tex.getHeight() - y) / tex.getHeight()) - 0.5));
189 if (
depth >= opts.minDistance &&
depth <= correctMaxDistance) {
190 float intensity = (
depth - opts.minDistance) / (
float)(correctMaxDistance - opts.minDistance);
191 edgeData[edgeIndex * 3 + 0] = 1 - intensity;
192 edgeData[edgeIndex * 3 + 1] = 1 - intensity;
193 edgeData[edgeIndex * 3 + 2] = 1 - intensity;
198 edgeData[edgeIndex * 3 + 0] = 0.0;
199 edgeData[edgeIndex * 3 + 1] = 0.0;
200 edgeData[edgeIndex * 3 + 2] = 0.0;
205 tex.loadData((
float*)edgeData, tex.getWidth(), tex.getHeight(), GL_RGB);
213 if (size == FRAME_SIZE_640x480x16BIT) {
218 if (size == FRAME_SIZE_640x480x32BIT || size == FRAME_SIZE_512x424x32BIT) {
223 ofLogWarning() <<
"Frame size not supported by ofxDepthStream::loadDepthTexture (bytes): " << size;
249 const uint16_t* pointData = (
const uint16_t*)data;
253 for (
int y = 0; y < height; y++) {
254 for (
int x = 0; x < width; x++) {
255 uint16_t val = pointData[y*width+x];
256 ofVec3f p(x,y, val * opts.depthFactor);
260 float hue = ofMap(val, 0, 6000, 0, 255);
261 mesh.addColor(ofColor::fromHsb(hue, 255, 255));
270 const uint32_t* pointData = (
const uint32_t*)data;
274 for (
int y = 0; y < height; y++) {
275 for (
int x = 0; x < width; x++) {
276 uint32_t val = pointData[y*width+x];
277 ofVec3f p(x,y, val * opts.depthFactor);
281 float hue = ofMap(val, 0, 6000, 0, 255);
282 mesh.addColor(ofColor::fromHsb(hue, 255, 255));
293 if(size == FRAME_SIZE_640x480x16BIT) {
298 if(size == FRAME_SIZE_640x480x32BIT) {
303 if(size == FRAME_SIZE_512x424x32BIT){
308 ofLogWarning() <<
"Frame size not supported by ofxDepthStream::loadMesh (bytes): " << size;
333 if(tex.isAllocated()) {
334 pixels.allocate(tex.getWidth(), tex.getHeight(), OF_IMAGE_COLOR);
336 ofLogWarning() <<
"TODO: infer color texture resolution from data-size";
337 pixels.allocate(1280, 720, OF_IMAGE_COLOR);
338 tex.allocate(pixels);
342 if((tex.getWidth() * tex.getHeight()) * 3 != size) {
343 ofLogWarning() <<
"Color texture size did not match data-size (got: " << size <<
", expected: 1280x720x3=2764800)";
348 pixels.setFromPixels((
const unsigned char *)data, pixels.getWidth(), pixels.getHeight(), OF_IMAGE_COLOR);
349 tex.loadData(pixels);
int minDistance
Definition: src/ofxDepthStream/functional.h:41
float depthFactor
Definition: src/ofxDepthStream/functional.h:241
MeshLoaderOpts & setDepthFactor(float v)
Definition: src/ofxDepthStream/functional.h:242
Definition: src/ofxDepthStream/functional.h:240
Definition: src/ofxDepthStream/functional.h:31
DepthLoaderOpts & setMinDistance(int v)
Definition: src/ofxDepthStream/functional.h:48
void loadDepthTexture32bit(ofTexture &tex, const void *data, size_t size, const DepthLoaderOpts &opts=DepthLoaderOpts())
populates the texture instance with 32-bit grayscale depth-image data from the given frame-data...
Definition: src/ofxDepthStream/functional.h:136
float margins[4]
Definition: src/ofxDepthStream/functional.h:46
DepthLoaderOpts & setKeystone(float v)
Definition: src/ofxDepthStream/functional.h:56
DepthLoaderOpts & setShift1(int v)
Definition: src/ofxDepthStream/functional.h:57
DepthLoaderOpts & setMarginBottom(float v)
Definition: src/ofxDepthStream/functional.h:54
contains all classes and functions of the DepthStream library.
Definition: Buffer.h:22
DepthLoaderOpts & setMaxDistance(int v)
Definition: src/ofxDepthStream/functional.h:49
DepthLoaderOpts & setMarginTop(float v)
Definition: src/ofxDepthStream/functional.h:52
void emptyAndInflateBuffer(Buffer &buf, Frame::InputFunc func)
Definition: libs/DepthStream/src/functional.h:140
int maxDistance
Definition: src/ofxDepthStream/functional.h:42
int shift1
Definition: src/ofxDepthStream/functional.h:44
DepthLoaderOpts & setShift2(int v)
Definition: src/ofxDepthStream/functional.h:58
void loadDepthTexture(ofTexture &tex, const void *data, size_t size, const DepthLoaderOpts &opts=DepthLoaderOpts())
populates the texture instance with grayscale depth-image data from the given frame-data.
Definition: src/ofxDepthStream/functional.h:212
void loadMesh(ofMesh &mesh, const void *data, size_t size, const MeshLoaderOpts &opts=MeshLoaderOpts())
populates the mesh instance with depth-image data.
Definition: src/ofxDepthStream/functional.h:292
void loadDepthTexture16bit(ofTexture &tex, const void *data, size_t size, const DepthLoaderOpts &opts=DepthLoaderOpts())
populates the texture instance with 16-bit grayscale depth-image data from the given frame-data...
Definition: src/ofxDepthStream/functional.h:64
void loadMesh16bit(ofMesh &mesh, const void *data, size_t width, size_t height, const MeshLoaderOpts &opts=MeshLoaderOpts())
populates the mesh instance with 16-bit depth-image data.
Definition: src/ofxDepthStream/functional.h:248
DepthLoaderOpts & setMarginRight(float v)
Definition: src/ofxDepthStream/functional.h:53
float keystone
Definition: src/ofxDepthStream/functional.h:45
DepthLoaderOpts & setVertCorrection(int v)
Definition: src/ofxDepthStream/functional.h:50
DepthLoaderOpts & setMarginLeft(float v)
Definition: src/ofxDepthStream/functional.h:55
DepthLoaderOpts & setMargins(const float *v)
Definition: src/ofxDepthStream/functional.h:51
int vertCorrection
Definition: src/ofxDepthStream/functional.h:43
int shift2
Definition: src/ofxDepthStream/functional.h:44
void loadColorTexture(ofTexture &tex, const void *data, size_t size)
UNTESTED populates the texture with color-image data from the given frame-data.
Definition: src/ofxDepthStream/functional.h:329
Manages a reference to a Frame instance.
Definition: Buffer.h:29
Options container for the loadDepth* methods.
Definition: src/ofxDepthStream/functional.h:40
void loadMesh32bit(ofMesh &mesh, const void *data, size_t width, size_t height, const MeshLoaderOpts &opts=MeshLoaderOpts())
UNTESTED populates the mesh instance with 32-bit depth-image data.
Definition: src/ofxDepthStream/functional.h:269