1

I am using the openkinect with python bindings and running the following demo app...

   #!/usr/bin/env python
   import freenect
   import cv
   import frame_convert

   cv.NamedWindow('Depth')
   cv.NamedWindow('Video')
   print('Press ESC in window to stop')


   def get_depth():
       return frame_convert.pretty_depth_cv(freenect.sync_get_depth()[0])


   def get_video():
       return frame_convert.video_cv(freenect.sync_get_video()[0])


   while 1:
       cv.ShowImage('Depth', get_depth())
       cv.ShowImage('Video', get_video())
       if cv.WaitKey(10) == 27:
           break

When I press escape this program does not stop. So I have tried to execute it as follows

   #!/usr/bin/env python
   import freenect
   import cv
   import frame_convert

   cv.NamedWindow('Depth')
   cv.NamedWindow('Video')
   print('Press ESC in window to stop')


   def get_depth():
       return frame_convert.pretty_depth_cv(freenect.sync_get_depth()[0])


   def get_video():
       return frame_convert.video_cv(freenect.sync_get_video()[0])


   for i in range(10):
       cv.ShowImage('Depth', get_depth())
       cv.ShowImage('Video', get_video())
       if cv.WaitKey(10) == 27:
           break

to execute it 10 times only.

The problem is that the program never stops and keep displaying the images. I think that one needs to stop kinect.

I want to take the depth image at a specific time instance. So it means that the kinect has to be restarted. I cant keep it executing all the time.

Could anybody help me in this please.

veducm
  • 5,933
  • 2
  • 34
  • 40
Shan
  • 18,563
  • 39
  • 97
  • 132

3 Answers3

1

No need to stop the Kinect: it seems the condition to break the while is never met. This may depend on the platform, the opencv version and several other factors. Try something like:

while 1:
       cv.ShowImage('Depth', get_depth())
       cv.ShowImage('Video', get_video())
       k = cv.WaitKey(10) # k contains integer keycode
       if chr(k) == 'q': # press q to exit
           break

To double check why pressing the ESC key does not pass the keycode 27 to cv.WaitKey try printing the keycode k above and see what happens when you hit ESC.

Masci
  • 5,864
  • 1
  • 26
  • 21
0

use int value of 'q' instead of 'q'

0
k=0
while k != 1048689:   # key value of 'q' is 1048689
    cv.ShowImage('Depth', get_depth())
    cv.ShowImage('Video', get_video())
    k = cv.WaitKey(10) # k contains integer keycode
M. Hoffman
  • 56
  • 4