Skip to content

Commit 53160e4

Browse files
committed
Recent Tests, weird resolution issue
1 parent 4b29eb7 commit 53160e4

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed

Diff for: primesense/openni2.py

+10
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ def create_ir_stream(self):
296296
def get_property(self, property_id, rettype):
297297
ret = rettype()
298298
size = ctypes.c_int(ctypes.sizeof(ret))
299+
#oniStreamGetProperty(self._handle, property_id, ctypes.byref(ret), ctypes.byref(size))
299300
c_api.oniDeviceGetProperty(self._handle, property_id, ctypes.byref(ret), ctypes.byref(size))
300301
return ret
301302
def get_int_property(self, property_id):
@@ -313,7 +314,13 @@ def invoke(self, command_id, data, size = None):
313314
def is_command_supported(self, command_id):
314315
return bool(c_api.oniDeviceIsCommandSupported(self._handle, command_id))
315316

317+
'''
318+
The following do not appear to be working:
319+
*get throws error, takes no input, but still crashes...
320+
*set throws same error, regardless of mode passed
321+
'''
316322
def is_image_registration_mode_supported(self, mode):
323+
#mode = IMAGE_REGISTRATION_DEPTH_TO_COLOR for example
317324
return bool(c_api.oniDeviceIsImageRegistrationModeSupported(self._handle, mode))
318325
def get_image_registration_mode(self):
319326
return self.get_property(c_api.ONI_DEVICE_PROPERTY_IMAGE_REGISTRATION, c_api.OniImageRegistrationMode)
@@ -588,6 +595,9 @@ def convert_depth_to_color(depthStream, colorStream, depthX, depthY, depthZ):
588595
def get_bytes_per_pixel(format):
589596
c_api.oniFormatBytesPerPixel(format)
590597

598+
'''
599+
Inherit from this class to make your own listerner? Fill in the Implement Me functions?
600+
'''
591601
class DeviceListener(HandleObject):
592602
def __init__(self):
593603
handle = c_api.OniCallbackHandle()

Diff for: testPythonOpenniFull.py

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
'''
2+
Short test file, may get longer
3+
'''
4+
from primesense import openni2
5+
from primesense import _openni2 as c_api
6+
#numpy, for matrix manipulation fo the images
7+
import numpy as np
8+
#matplotlib, for temporary display to check the images
9+
import matplotlib.pyplot as plt
10+
11+
#takes frame data, and the type it is and displays the image
12+
#frame_data = frame.get_buffer_as_blah(); thisType = numpy.someType
13+
def print_frame(frame_data, thisType):
14+
#need to know what format to get the buffer in:
15+
# if color pixel type is RGB888, then it must be uint8,
16+
#otherwise it will split the pixels incorrectly
17+
img = np.frombuffer(frame_data, dtype=thisType)
18+
whatisit = img.size
19+
#QVGA is what my camera defaulted to, so: 1 x 480 x 640
20+
#also order was weird (1, 480, 640) not (640, 480, 1)
21+
if whatisit == (640*480*1):#QVGA
22+
img.shape = (1, 480, 640)
23+
#This order? Really? ^
24+
#shape it accordingly
25+
img = np.concatenate((img, img, img), axis=0)
26+
img = np.swapaxes(img, 0, 2)
27+
img = np.swapaxes(img, 0, 1)
28+
elif whatisit == (640*480*3):
29+
img.shape = (480, 640, 3)
30+
#these are, what is it, normalizsed?
31+
else:
32+
print "Frames are of size: ",img.size
33+
#images still appear to be reflected, but I don't need them to be correct in that way
34+
print img.shape
35+
#need both of follwoing: plt.imShow adds image to plot
36+
plt.imshow(img)
37+
#plt.show shows all the currently added figures
38+
#plt.show()
39+
plt.pause(0.1)
40+
plt.draw()
41+
plt.close()
42+
43+
def print_frames(frame_data, frame_data2, thisType, thisType2):
44+
img = np.frombuffer(frame_data, dtype=thisType)
45+
whatisit = img.size
46+
print "Image size 1 ",whatisit
47+
if whatisit == (640*480*1): #QVGA, default
48+
img.shape = (1, 480, 640)
49+
#This order? Really? ^
50+
#shape it accordingly
51+
img = np.concatenate((img, img, img), axis=0)
52+
img = np.swapaxes(img, 0, 2)
53+
img = np.swapaxes(img, 0, 1)
54+
elif whatisit == (640*480*3):
55+
img.shape = (480, 640, 3)
56+
#these are, what is it, normalizsed?
57+
else:
58+
print "Frames are of size: ",img.size
59+
print img.shape
60+
plt.imshow(img)
61+
plt.show()
62+
63+
img1 = np.frombuffer(frame_data2, dtype=thisType2)
64+
whatisit = img1.size
65+
print "Image size 2 ",whatisit
66+
if whatisit == (640*480*1): #QVGA, default
67+
img1.shape = (1, 480, 640)
68+
#This order? Really? ^
69+
#shape it accordingly
70+
img1 = np.concatenate((img1, img1, img1), axis=0)
71+
img1 = np.swapaxes(img1, 0, 2)
72+
img1 = np.swapaxes(img1, 0, 1)
73+
elif whatisit == (640*480*3):
74+
img1.shape = (480, 640, 3)
75+
img1 = np.swapaxes(img1, 0, 2)
76+
#these are, what is it, normalizsed?
77+
else:
78+
print "Frames are of size: ",img1.size
79+
print img1.shape
80+
plt.imshow(img1)
81+
82+
plt.show()
83+
84+
openni2.initialize() # can also accept the path of the OpenNI redistribution
85+
86+
dev = openni2.Device.open_any()
87+
print dev.get_sensor_info(openni2.SENSOR_DEPTH)
88+
89+
print "testing depth "
90+
depth_stream = dev.create_depth_stream()
91+
'''depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_1_MM, resolutionX = 640, resolutionY = 480, fps = 30))
92+
depth_stream.start()
93+
frame = depth_stream.read_frame()
94+
frame_data = frame.get_buffer_as_uint16()
95+
print_frame(frame_data, np.uint16)
96+
depth_stream.stop()'''
97+
98+
'''print "Testing depth 2 "
99+
depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_100_UM, resolutionX = 640, resolutionY = 480, fps = 30))
100+
depth_stream.start()
101+
frame = depth_stream.read_frame()
102+
frame_data = frame.get_buffer_as_uint16()
103+
print_frame(frame_data, np.uint16)
104+
depth_stream.stop()'''
105+
106+
print "Testing Color "
107+
color_stream = dev.create_color_stream()
108+
'''color_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_RGB888, resolutionX = 640, resolutionY = 480, fps = 30))
109+
color_stream.start()
110+
frame = color_stream.read_frame()
111+
frame_data1 = frame.get_buffer_as_uint8()
112+
print_frame(frame_data1, np.uint8)
113+
color_stream.stop()'''
114+
115+
print "what?"
116+
depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_100_UM, resolutionX = 640, resolutionY = 480, fps = 30))
117+
color_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_RGB888, resolutionX = 640, resolutionY = 480, fps = 30))
118+
print "Starting Streams"
119+
depth_stream.start()
120+
color_stream.start()
121+
print "Read frames"
122+
frame = depth_stream.read_frame()
123+
frame1 = color_stream.read_frame()
124+
print "Getting Buffer"
125+
frame_data = frame.get_buffer_as_uint16()
126+
frame_data1 = frame1.get_buffer_as_uint8()
127+
print "Printing"
128+
print_frames(frame_data, frame_data1, np.uint16, np.uint8)
129+
depth_stream.stop()
130+
color_stream.stop()
131+
132+
openni2.unload()

Diff for: testPythonOpenniQuarter.py

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
'''
2+
Short test file, may get longer
3+
'''
4+
from primesense import openni2
5+
from primesense import _openni2 as c_api
6+
#numpy, for matrix manipulation fo the images
7+
import numpy as np
8+
#matplotlib, for temporary display to check the images
9+
import matplotlib.pyplot as plt
10+
11+
#takes frame data, and the type it is and displays the image
12+
#frame_data = frame.get_buffer_as_blah(); thisType = numpy.someType
13+
def print_frame(frame_data, thisType):
14+
#need to know what format to get the buffer in:
15+
# if color pixel type is RGB888, then it must be uint8,
16+
#otherwise it will split the pixels incorrectly
17+
img = np.frombuffer(frame_data, dtype=thisType)
18+
whatisit = img.size
19+
#QVGA is what my camera defaulted to, so: 1 x 240 x 320
20+
#also order was weird (1, 240, 320) not (320, 240, 1)
21+
if whatisit == (320*240*1):#QVGA
22+
img.shape = (1, 240, 320)
23+
#This order? Really? ^
24+
#shape it accordingly
25+
img = np.concatenate((img, img, img), axis=0)
26+
img = np.swapaxes(img, 0, 2)
27+
img = np.swapaxes(img, 0, 1)
28+
elif whatisit == (320*240*3):
29+
img.shape = (240, 320, 3)
30+
#these are, what is it, normalizsed?
31+
elif whatisit == (640*480*1):
32+
img.shape = (1, 480, 640)
33+
#This order? Really? ^
34+
#shape it accordingly
35+
img = np.concatenate((img, img, img), axis=0)
36+
img = np.swapaxes(img, 0, 2)
37+
img = np.swapaxes(img, 0, 1)
38+
elif whatisit == (640*480*3):
39+
img.shape = (480,640,3)
40+
else:
41+
print "Frames are of size: ",img.size
42+
#images still appear to be reflected, but I don't need them to be correct in that way
43+
print img.shape
44+
#need both of follwoing: plt.imShow adds image to plot
45+
plt.imshow(img)
46+
#plt.show shows all the currently added figures
47+
#plt.show()
48+
plt.pause(0.1)
49+
plt.draw()
50+
plt.close()
51+
52+
openni2.initialize() # can also accept the path of the OpenNI redistribution
53+
54+
dev = openni2.Device.open_any()
55+
print dev.get_sensor_info(openni2.SENSOR_DEPTH)
56+
57+
print "testing depth "
58+
depth_stream = dev.create_depth_stream()
59+
#depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_1_MM, resolutionX = 320, resolutionY = 240, fps = 30))
60+
depth_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_DEPTH_1_MM, resolutionX = 640, resolutionY = 480, fps = 30))
61+
62+
print "Testing Color "
63+
color_stream = dev.create_color_stream()
64+
#color_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_RGB888, resolutionX = 320, resolutionY = 240, fps = 30))
65+
color_stream.set_video_mode(c_api.OniVideoMode(pixelFormat = c_api.OniPixelFormat.ONI_PIXEL_FORMAT_RGB888, resolutionX = 640, resolutionY = 480, fps = 30))
66+
67+
print "Starting Streams"
68+
depth_stream.start()
69+
color_stream.start()
70+
openni2.wait_for_any_stream([depth_stream])
71+
openni2.wait_for_any_stream([color_stream])
72+
print "Reading frames"
73+
frame_depth = depth_stream.read_frame()
74+
frame_color = color_stream.read_frame()
75+
print "Getting Buffers"
76+
frame_data_depth = frame_depth.get_buffer_as_uint16()
77+
frame_data_color = frame_color.get_buffer_as_uint8()
78+
print "Printing"
79+
print_frame(frame_data_depth, np.uint16)
80+
print_frame(frame_data_color, np.uint8)
81+
depth_stream.stop()
82+
color_stream.stop()
83+
84+
openni2.unload()

0 commit comments

Comments
 (0)