-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDepthImage.py
71 lines (57 loc) · 2.03 KB
/
DepthImage.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
import png
import math
from numpy import *
class DepthImage:
def __init__(self, w, h, p):
self.width = w
self.height = h
self.path = p
self.dataType = int
self.rows = ones((w,h), dtype = int)
self.bitDepth = 8
self.x_index = 0
self.y_index = 0
self.quantizeFactor = (2 ** self.bitDepth) - 1
def setDimensions( self, w, h ) :
self.width = w
self.height = h
def setPath( self, p ) :
self.path = p
def setDataType( self, dt ) :
self.dataType = dt
def setBitDepth( self, d ) :
self.bitDepth = d
def initializeImage( self ) :
self.rows = ones((w,h), dtype = self.dataType)
def writeFile( self ) :
# print( 'called writeFile')
f = open(self.path, 'wb')
w = png.Writer(len(self.rows[0]), len(self.rows), greyscale=True, bitdepth=self.bitDepth)
w.write(f, self.rows)
f.close()
def addRowData(self, data, repeat) :
q = self.quantize( float(data) )
for i in range (0, int(repeat)) :
# print('adding: ' + str(q) + ' at [' + str(self.x_index%self.width) + ',' + str(self.y_index) + ']' )
self.rows[self.x_index%self.width][self.y_index] = q
# print (self.path + ' added value: ' + str(self.rows[self.x_index%self.width][self.y_index]))
self.x_index += 1
#When we wrap x, add another row
if self.x_index%self.width == 0 :
self.y_index += 1
def quantize(self, data) :
q = data*self.quantizeFactor
return int(math.floor(q))
def printRowData(self) :
# print( 'Current rows for ' + self.path )
dataString = '[\n'
for y in range (0, self.y_index) :
dataString += '['
for x in range (0, self.x_index%500) :
dataString += (str(self.rows[x,y]) + ' ')
dataString += '],\n'
dataString += ']\n'
# print (dataString)
def path(self) :
return self.filePath