PyKinect helps/ about TODO in version 2.1b1 get_next_frame()

Jun 13 at 10:44 PM
Edited Jun 13 at 10:44 PM
I am working with Kynect+python (without using Micosoft visual studio), on windows 7.

Has somebody solve how to get frames from kinect without using an event loop??

I am refering to this method of Pykinect/nui/init.py
def get_next_frame(self, milliseconds_to_wait = 0):
    # TODO: Allow user to provide a NUI_IMAGE_FRAME ?
    return self.runtime._nui.NuiImageStreamGetNextFrame(self._stream, milliseconds_to_wait)
The above function is what i need and it isnt implemented yet. I need it to get frames on demand (without using an event loop).

Please help me, this going to get me crasy at this time.

Thanks a lot. Best Regards

Python 2.7.2, Pykinect 2.1b1, Kinect sensor (from XBOX v1), kinect SDK 1.8, Windows 7
Coordinator
Jun 13 at 11:08 PM
That TODO message doesn't make any sense - I'm not sure who put it there, but there's no functionality available that would suit having an input frame.

And as far as I can tell, each time you call this function you will get a frame. That's "on demand". What are you trying to do that makes this unsuitable?
Jun 16 at 5:16 PM
Edited Jun 16 at 5:16 PM
Hi thanks for the answer.

Lets simplify the issue, the trouble is that, that function doesnt work (get_next_frame()). the following code should works and it doesnt:
import pykinect
from pykinect import nui
import time

kinect = nui.Runtime()
kinect.video_stream.open(nui.ImageStreamType.Video, 1, nui.ImageResolution.Resolution640x480, nui.ImageType.Color)
while True:
    time.sleep(1)
    frame = kinect.video_stream.get_next_frame(1)  
    print frame 
Please, if you can make it work, tell me. Or give some advice how to do it.
Coordinator
Jun 17 at 9:27 PM
Edited Jun 17 at 9:28 PM
Thanks for the report... There seem to be two things going on here. First is that the first calls to get_next_frame can fail because the Kinect doesn't yet have any frames available to send back. If you handle the exception there then you'll be able to get a couple of calls which return frames. But then it'll start failing again because the frames aren't getting released. So then you need to start explicitly releasing each frame. I ended up with this code which is able to report a bunch of frames after the first couple of frames fail:
import pykinect
from pykinect import nui
import time

kinect = nui.Runtime()
kinect.video_stream.open(nui.ImageStreamType.Video, 1, nui.ImageResolution.Resolution640x480, nui.ImageType.Color)
while True:
    time.sleep(1)
    try:
        frame = kinect.video_stream.get_next_frame(1)  
        print frame 
        kinect._nui.NuiImageStreamReleaseFrame(kinect.video_stream._stream, frame)
    except:
        print('error')
Jun 19 at 4:28 PM
thanks man, you have helped me a lot . The above quote works well. But i have to added this also (inside _interop.py):
    def NuiImageStreamGetNextFrame(self, hStream, dwMillisecondsToWait):
        res = ImageFrame()
        try:
            _NuiInstance._NuiImageStreamGetNextFrame(self, hStream, dwMillisecondsToWait, ctypes.byref(res))
        except: pass
        return res
just a try-except in that method, and everything works :-). thanks again