Skip to content

Commit 26eefa7

Browse files
FoST MacBook AirFoST MacBook Air
FoST MacBook Air
authored and
FoST MacBook Air
committed
Evan - ground truths
1 parent cd583aa commit 26eefa7

20 files changed

+621
-225
lines changed

.DS_Store

6 KB
Binary file not shown.

BinaryImplementation.cpp

+20-2
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ void BinaryImplementation::iterationProcess() {
122122
}
123123
}
124124
}
125-
125+
/*
126126
void BinaryImplementation::postIterationsProcess() {
127127
Rect croppedArea = experiment->getInfrastructure()->getCroppedArea();
128+
double width = experiment->getInfrastructure()->getCameraResolution().width/getNumberColumns();
128129
for (int y = 0; y < croppedArea.height; y++) {
129130
int lastBinaryCode = -1;
130131
@@ -134,11 +135,28 @@ void BinaryImplementation::postIterationsProcess() {
134135
if (currentBinaryCode != -1 && currentBinaryCode != lastBinaryCode) {
135136
136137
double displacement = getDisplacement((double)currentBinaryCode,x);
137-
slDepthExperimentResult result(x, y, displacement * this->getScale());
138+
slDepthExperimentResult result(currentBinaryCode*width/2, y, displacement * this->getScale());
138139
experiment->storeResult(&result);
139140
140141
lastBinaryCode = currentBinaryCode;
141142
}
142143
}
143144
}
144145
}
146+
*/
147+
double BinaryImplementation::solveCorrespondence(int x, int y) {
148+
static int lastBinaryCode = -1;
149+
150+
if (x == 0) {
151+
lastBinaryCode = -1;
152+
}
153+
154+
int currentBinaryCode = getBinaryCode(x,y);
155+
156+
if (currentBinaryCode != -1 && currentBinaryCode != lastBinaryCode) {
157+
lastBinaryCode = currentBinaryCode;
158+
return (double)currentBinaryCode;
159+
}
160+
161+
return -1;
162+
}

BinaryImplementation.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class BinaryImplementation : public slImplementation {
1717
bool hasMoreIterations();
1818
virtual Mat generatePattern();
1919
virtual void iterationProcess();
20-
virtual void postIterationsProcess();
20+
//virtual void postIterationsProcess();
2121
//Getters and Setters
2222
unsigned int getNumberPatterns();
2323
unsigned int getNumberColumns();
@@ -34,6 +34,8 @@ class BinaryImplementation : public slImplementation {
3434

3535
void generateBackground(Mat &pattern, Scalar &colour);
3636

37+
virtual double solveCorrespondence(int, int);
38+
3739
protected:
3840
unsigned int numberPatterns;
3941
unsigned int numberColumns;

GroundTruthImplementation.cpp

-83
This file was deleted.

GroundTruthImplementation.h

-28
This file was deleted.

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ ifeq ($(OS),Windows_NT)
33
CV_LIB = /c/opencv/bin
44
CV_VERSION = 300
55
else
6-
CV_INCLUDE = /usr/local/include
7-
CV_LIB = /usr/local/lib
6+
CV_INCLUDE = /usr/local/Cellar/opencv3/3.2.0/include
7+
CV_LIB = /usr/local/Cellar/opencv3/3.2.0/lib
88
CV_VERSION =
99
endif
1010

@@ -30,7 +30,7 @@ $(LIBOBJS):%.o: %.cpp %.h
3030
$(CXX) $(CPPFLAGS) -c $< -o $@
3131

3232
clean:
33-
-$(RM) $(LIBOBJS) main
33+
-$(RM) $(LIBOBJS) slBenchmark
3434

3535
clean_experiments:
3636
-$(RM) -r [0-9]*/

RaycastDepth.py

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import bpy
2+
import math
3+
import sys
4+
import os
5+
import json
6+
import numpy as np
7+
from mathutils import Vector
8+
9+
def getDirection(camera):
10+
#Y = np.tan(np.deg2rad(camera.angle_x / 2))
11+
#Z = np.tan(np.deg2rad(camera.angle_y / 2))
12+
Y = np.tan(bpy.data.cameras['Camera.001'].angle_x / 2)
13+
Z = np.tan(bpy.data.cameras['Camera.001'].angle_y / 2)
14+
15+
return (-1, Y, Z)
16+
17+
def getDirections(obj, camera, cameraWidth, cameraHeight, outputPath):
18+
out = open(outputPath, 'w')
19+
x, y, z = getDirection(camera)
20+
21+
for yDirection in np.linspace(-y, y, cameraWidth):
22+
for zDirection in np.linspace(z, -z, cameraHeight):
23+
dst = Vector((x, yDirection, zDirection)) + camera.location
24+
direction = Vector((x, yDirection, zDirection))
25+
26+
27+
mw = obj.matrix_world
28+
mwi = mw.inverted()
29+
30+
# src and dst in local space of cb
31+
32+
origin = mwi * camera.location
33+
dest = mwi * dst
34+
direction = (dest - origin).normalized()
35+
36+
result, location, normal, index = obj.ray_cast(origin, direction)
37+
38+
#xPixel = int(round(((yDirection + y) / (2 * y)) * cameraWidth))
39+
#yPixel = int(round(((-zDirection + z) / (2 * z)) * cameraHeight))
40+
xPixel = ((yDirection + y) / (2 * y)) * cameraWidth
41+
yPixel = ((-zDirection + z) / (2 * z)) * cameraHeight
42+
locationWorld = mw * location
43+
fromCamera = locationWorld - camera.location
44+
45+
if result:
46+
out.write(str(xPixel) + " " + str(yPixel) + " " + str(fromCamera.x) + '\n')
47+
out.close()
48+
49+
if __name__ == "__main__":
50+
argv = sys.argv
51+
argv = argv[argv.index("--") + 1:]
52+
53+
bpy.ops.wm.open_mainfile(filepath=os.path.abspath(argv[0]))
54+
55+
outputPath = os.path.abspath(argv[1])
56+
cameraWidth = int(argv[2])
57+
cameraHeight = int(argv[3])
58+
59+
singleObject = None
60+
61+
for ob in bpy.context.scene.objects:
62+
if ob.type == 'MESH':
63+
ob.select = True
64+
bpy.context.scene.objects.active = ob
65+
else:
66+
ob.select = False
67+
68+
bpy.ops.object.join()
69+
70+
for ob in bpy.context.scene.objects:
71+
if ob.type == 'MESH':
72+
singleObject = ob
73+
74+
75+
getDirections(singleObject, bpy.context.scene.camera, cameraWidth, cameraHeight, outputPath)
76+
77+

RaycastImplementation.cpp

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include "RaycastImplementation.h"
2+
3+
RaycastImplementation::RaycastImplementation(): slImplementation(string("RaycastImplementation")) {
4+
//this->setScale(250);
5+
this->setScale(280);
6+
}
7+
8+
bool RaycastImplementation::hasMoreIterations() {
9+
return experiment->getIterationIndex() == 0;
10+
}
11+
12+
Mat RaycastImplementation::generatePattern() {
13+
Size cameraResolution = experiment->getInfrastructure()->getCameraResolution();
14+
15+
int iterationIndex = experiment->getIterationIndex();
16+
17+
int cameraWidth = (int)cameraResolution.width;
18+
int cameraHeight = (int)cameraResolution.height;
19+
20+
Mat pattern(cameraHeight, cameraWidth, CV_8UC3, Scalar(0, 0, 0));
21+
return pattern;
22+
}
23+
24+
void RaycastImplementation::postIterationsProcess() {
25+
stringstream blenderFilename, outputFilename, blenderCommandLine;
26+
27+
blenderFilename << experiment->getPath() << "slVirtualScene_0.blend";
28+
outputFilename << experiment->getPath() << "raycast_depth.xyz";
29+
30+
Size cameraResolution = experiment->getInfrastructure()->getCameraResolution();
31+
Rect croppedArea = experiment->getInfrastructure()->getCroppedArea();
32+
33+
blenderCommandLine
34+
<< "blender -b -P RaycastDepth.py -- "
35+
<< blenderFilename.str() << " "
36+
<< outputFilename.str() << " "
37+
<< (int)cameraResolution.width << " "
38+
<< (int)cameraResolution.height;
39+
40+
DB("blenderCommandLine: " << blenderCommandLine.str())
41+
42+
int exeResult = system(blenderCommandLine.str().c_str());
43+
44+
ifstream raycastDepthfile(outputFilename.str());
45+
string line;
46+
47+
while (getline(raycastDepthfile, line)) {
48+
stringstream lineStream(line);
49+
istream_iterator<string> iterator(lineStream);
50+
istream_iterator<string> end;
51+
vector<string> results(iterator, end);
52+
53+
//int x = atoi(results[0].c_str());
54+
//int y = atoi(results[1].c_str());
55+
double x = atof(results[0].c_str());
56+
double y = atof(results[1].c_str());
57+
double z = atof(results[2].c_str());
58+
59+
// if (x >= croppedArea.x && x < (croppedArea.x + croppedArea.width) && y >= croppedArea.y && y < (croppedArea.y + croppedArea.height)) {
60+
//slDepthExperimentResult result(x - croppedArea.x, y - croppedArea.y, z * this->getScale());
61+
slDepthExperimentResult result(x, y, (z * this->getScale()) + 2660);
62+
experiment->storeResult(&result);
63+
// }
64+
}
65+
66+
remove(outputFilename.str().c_str());
67+
/*
68+
Rect croppedArea = experiment->getInfrastructure()->getCroppedArea();
69+
70+
for (int y = 0; y < croppedArea.height; y++) {
71+
//int lastBinaryCode = -1;
72+
73+
for (int x = 0; x < croppedArea.width; x++) {
74+
int currentOriginalColumn = originalColumn[(y * croppedArea.width) + x];
75+
76+
//if (currentBinaryCode != -1 && currentBinaryCode != lastBinaryCode) {
77+
if (currentOriginalColumn != -1) {
78+
79+
double displacement =
80+
((double)x / (double)croppedArea.width) - ((double)currentOriginalColumn / (double)experiment->getInfrastructure()->getCameraResolution().width);
81+
82+
slDepthExperimentResult result(x, y, displacement * RAYCAST_Z_SCALE);
83+
experiment->storeResult(&result);
84+
85+
//lastBinaryCode = currentBinaryCode;
86+
}
87+
}
88+
}
89+
*/
90+
}

RaycastImplementation.h

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef RAYCAST_IMPLEMENTATION_H
2+
#define RAYCAST_IMPLEMENTATION_H
3+
4+
#include "slBenchmark.h"
5+
6+
using namespace cv;
7+
8+
class RaycastImplementation : public slImplementation {
9+
public:
10+
RaycastImplementation();
11+
virtual ~RaycastImplementation() {};
12+
virtual Mat generatePattern();
13+
virtual void postIterationsProcess();
14+
bool hasMoreIterations();
15+
virtual double solveCorrespondence(int, int) {return 0;}
16+
};
17+
18+
#endif //RAYCAST_IMPLEMENTATION_H

0 commit comments

Comments
 (0)