Commit eee6612f by wester

test

parent a6e10ef5
...@@ -76,7 +76,19 @@ static bool writeFile = false; ...@@ -76,7 +76,19 @@ static bool writeFile = false;
static bool captureFrame = false; static bool captureFrame = false;
int lastX, lastY; int lastX, lastY;
bool enableCustomCloudFilter = false;
float degreeToRadioan(float degree) {
return degree*M_PI / 180.0;
}
//Filter Settings
//Custom
//float angleDegrees = 20.0f;
float maxNormalAngle = degreeToRadioan(25.0f);
bool enableDepthFilter = false;
bool enableNormalFilter = true;//true;
//Bilateral / FastDepthNoise
float repairThreshold = 100.0f;
void DrawCoordinateSystem() { void DrawCoordinateSystem() {
...@@ -158,57 +170,6 @@ bool initKinect() { ...@@ -158,57 +170,6 @@ bool initKinect() {
} }
} }
//bilateral Filter
//https://github.com/anlcnydn/bilateral/blob/master/bilateral_filter.cpp
float distance(int x, int y, int i, int j) {
return float(sqrt(pow(x - i, 2) + pow(y - j, 2)));
}
double gaussian(float x, double sigma) {
return exp(-(pow(x, 2)) / (2 * pow(sigma, 2))) / (2 * M_PI * pow(sigma, 2));
}
void applyBilateralFilter(unsigned short* source, unsigned short* filteredImage, int x, int y, int diameter, double sigmaI, double sigmaS) {
double iFiltered = 0;
double wP = 0;
int neighbor_x = 0;
int neighbor_y = 0;
int half = diameter / 2;
//why
const int width = 512;
const int height = 424;
for (int i = 0; i < diameter; i++) {
for (int j = 0; j < diameter; j++) {
neighbor_x = x - (half - i);
neighbor_y = y - (half - j);
double gi = gaussian(source[neighbor_x + width* neighbor_y] - source[x + width* y], sigmaI);
double gs = gaussian(distance(x, y, neighbor_x, neighbor_y), sigmaS);
double w = gi * gs;
iFiltered = iFiltered + source[neighbor_x + width* neighbor_y] * w;
wP = wP + w;
}
}
iFiltered = iFiltered / wP;
filteredImage[x + width* y] = iFiltered;
}
void bilateralFilterOwn(unsigned short* source, unsigned short* filterd, int diameter, double sigmaI, double sigmaS) {
const int width = 512;
const int height = 424;
for (int i = 4; i < width - 12; i++) {
for (int j = 4; j < height - 12; j++) {
applyBilateralFilter(source, filterd, i, j, diameter, sigmaI, sigmaS);
}
}
}
//bilateral Filter end
void getDepthData(IMultiSourceFrame* frame) { void getDepthData(IMultiSourceFrame* frame) {
IDepthFrame* depthframe; IDepthFrame* depthframe;
IDepthFrameReference* frameref = NULL; IDepthFrameReference* frameref = NULL;
...@@ -241,7 +202,7 @@ void getDepthData(IMultiSourceFrame* frame) { ...@@ -241,7 +202,7 @@ void getDepthData(IMultiSourceFrame* frame) {
cv::Mat FilerdDepth; cv::Mat FilerdDepth;
FilerdDepth.create(OriginalDepthFrame.size(), OriginalDepthFrame.type()); FilerdDepth.create(OriginalDepthFrame.size(), OriginalDepthFrame.type());
FastDepthNoiseRemoval filter(3,0.0f,3, 100.0f); FastDepthNoiseRemoval filter(3,0.0f,3, repairThreshold);
filter.setKillBorder(true); filter.setKillBorder(true);
filter.setInput(OriginalDepthFrame); filter.setInput(OriginalDepthFrame);
filter.filter(OriginalDepthFrame); filter.filter(OriginalDepthFrame);
...@@ -261,27 +222,31 @@ void getDepthData(IMultiSourceFrame* frame) { ...@@ -261,27 +222,31 @@ void getDepthData(IMultiSourceFrame* frame) {
{ {
unsigned int i = x + y* width; unsigned int i = x + y* width;
framePositions[i] = glm::vec3(depth2xyz[i].X, depth2xyz[i].Y, depth2xyz[i].Z); framePositions[i] = glm::vec3(depth2xyz[i].X, depth2xyz[i].Y, depth2xyz[i].Z);
if (enableCustomCloudFilter && x > 0 && y > 0 && x < width - 1 && y < height - 1) {
//normalen if ((enableNormalFilter || enableDepthFilter) && x > 0 && y > 0 && x < width - 1 && y < height - 1) {
float dzdx = ( curr[x + 1 + width * y] - curr[x - 1 + width * y]) / 2.0; if (enableNormalFilter) {
float dzdy = ( curr[x + width * (y+1)] - curr[x + width * (y - 1)]) / 2.0; //normalen
float dzdx = (curr[x + 1 + width * y] - curr[x - 1 + width * y]) / 2.0;
glm::vec3 d(-dzdx, -dzdy, 1.0f); float dzdy = (curr[x + width * (y + 1)] - curr[x + width * (y - 1)]) / 2.0;
frameNormals[i] = normalize(d);
// dz tiefenwert glm::vec3 d(-dzdx, -dzdy, 1.0f);
float z = depth2xyz[i].Z; frameNormals[i] = normalize(d);
if (true) {
frameDepthDifference[i] = (depth2xyz[x + 1 + width * (y)].Z - z)*(depth2xyz[x + 1 + width * (y)].Z - z)
+ (depth2xyz[x - 1 + width * (y)].Z - z)*(depth2xyz[x - 1 + width * (y)].Z - z)
+ (depth2xyz[x + width * (y + 1)].Z - z)*(depth2xyz[x + width * (y + 1)].Z - z)
+ (depth2xyz[x + width * (y - 1)].Z - z)*(depth2xyz[x + width * (y - 1)].Z - z);
} }
else { if (enableDepthFilter) {
frameDepthDifference[i] = 0.0f; // dz tiefenwert
float z = depth2xyz[i].Z;
if (true) {
frameDepthDifference[i] = (depth2xyz[x + 1 + width * (y)].Z - z)*(depth2xyz[x + 1 + width * (y)].Z - z)
+ (depth2xyz[x - 1 + width * (y)].Z - z)*(depth2xyz[x - 1 + width * (y)].Z - z)
+ (depth2xyz[x + width * (y + 1)].Z - z)*(depth2xyz[x + width * (y + 1)].Z - z)
+ (depth2xyz[x + width * (y - 1)].Z - z)*(depth2xyz[x + width * (y - 1)].Z - z);
}
else {
frameDepthDifference[i] = 0.0f;
}
} }
//if (x == width / 2 && y == height / 2) std::cout << "Frame Difference " << frameDepthDifference[i]<< std::endl; //if (x == width / 2 && y == height / 2) std::cout << "Frame Difference " << frameDepthDifference[i]<< std::endl;
} } else {
else {
frameNormals[i] = glm::vec3(0.0, 0.0, 1.0); frameNormals[i] = glm::vec3(0.0, 0.0, 1.0);
frameDepthDifference[i] = 0.0f; frameDepthDifference[i] = 0.0f;
} }
...@@ -335,6 +300,7 @@ void getRgbData(IMultiSourceFrame* frame) { ...@@ -335,6 +300,7 @@ void getRgbData(IMultiSourceFrame* frame) {
*fvalid++ = false; *fvalid++ = false;
} }
else { else {
if (depth2xyz[i].Z > maxTrackingKinect || depth2xyz[i].Z < minTrackingKinect) { if (depth2xyz[i].Z > maxTrackingKinect || depth2xyz[i].Z < minTrackingKinect) {
*fdest++ = 0; *fdest++ = 0;
...@@ -345,8 +311,7 @@ void getRgbData(IMultiSourceFrame* frame) { ...@@ -345,8 +311,7 @@ void getRgbData(IMultiSourceFrame* frame) {
continue; continue;
} }
if (enableCustomCloudFilter) { if (enableDepthFilter && frameDepthDifference[i] > 100.0) {
if ( frameDepthDifference[i] > 100.0) {
*fdest++ = 255; *fdest++ = 255;
*fdest++ = 140; *fdest++ = 140;
*fdest++ = 0; *fdest++ = 0;
...@@ -355,8 +320,10 @@ void getRgbData(IMultiSourceFrame* frame) { ...@@ -355,8 +320,10 @@ void getRgbData(IMultiSourceFrame* frame) {
continue; continue;
} }
if (enableNormalFilter) {
float angle = dot(frameNormals[i], glm::vec3(0.0, 0.0, 1.0)); float angle = dot(frameNormals[i], glm::vec3(0.0, 0.0, 1.0));
if ( angle < 0.05) { if ( angle < maxNormalAngle) {
*fdest++ = 0; *fdest++ = 0;
*fdest++ = 0; *fdest++ = 0;
*fdest++ = 255; *fdest++ = 255;
...@@ -364,8 +331,8 @@ void getRgbData(IMultiSourceFrame* frame) { ...@@ -364,8 +331,8 @@ void getRgbData(IMultiSourceFrame* frame) {
*fvalid++ = false; *fvalid++ = false;
continue; continue;
} }
}
}
int idx = (int)p.X + colorwidth*(int)p.Y; int idx = (int)p.X + colorwidth*(int)p.Y;
*fdest++ = rgbimage[4 * idx + 0]; *fdest++ = rgbimage[4 * idx + 0];
*fdest++ = rgbimage[4 * idx + 1]; *fdest++ = rgbimage[4 * idx + 1];
...@@ -413,10 +380,14 @@ void processCurrentFrameForExport() { ...@@ -413,10 +380,14 @@ void processCurrentFrameForExport() {
for (unsigned int i = 0; i < width*height; i++) { for (unsigned int i = 0; i < width*height; i++) {
if (frameValidPoints[i]) { if (frameValidPoints[i]) {
glm::vec3 positionLocal = framePositions[i]; glm::vec3 position = framePositions[i];
glm::vec3 positionGlobal = glm::vec3(*currentControlerPos * controlerToKinect * glm::vec4(positionLocal, 1.0f)); glm::vec3 positionGlobal = glm::vec3(*currentControlerPos * controlerToKinect * glm::vec4(position, 1.0f));
if (isinf(position.x) || isinf(position.y) || isinf(position.z))
continue;
glm::vec3 position = positionLocal;
if (position.x < minx) minx = position.x; if (position.x < minx) minx = position.x;
if (position.x > maxx) maxx = position.x; if (position.x > maxx) maxx = position.x;
if (position.y < miny) miny = position.y; if (position.y < miny) miny = position.y;
...@@ -684,9 +655,7 @@ void captureNextFrame(vr::VREvent_t event) ...@@ -684,9 +655,7 @@ void captureNextFrame(vr::VREvent_t event)
} }
} }
float degreeToRadioan(float degree) {
return degree*M_PI / 180.0;
}
void printVector(glm::vec3 vector) void printVector(glm::vec3 vector)
......
...@@ -16,6 +16,12 @@ ...@@ -16,6 +16,12 @@
"refine": "add", "refine": "add",
"children": [ "children": [
{ {
"transform": [
1.0, 0.0, 0.0, 0.0,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
],
"boundingVolume": { "boundingVolume": {
"sphere": [ "sphere": [
0, 0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment