首页 文章

如何在openkinect中停止并启动kinect?

提问于
浏览
1

我正在使用openkinect与python绑定并运行以下演示应用程序...

#!/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

当我按下逃脱时,这个程序不会停止 . 所以我试着按如下方式执行它

#!/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

仅执行10次 .

问题是程序永远不会停止并继续显示图像 . 我认为需要停止kinect .

我想在特定的时间实例拍摄深度图像 . 所以这意味着必须重新启动kinect . 我不能让它一直在执行 .

请有人帮我这个 .

3 回答

  • 1

    无需停止Kinect:似乎永远不会遇到打破时间的条件 . 这可能取决于平台,opencv版本和其他几个因素 . 尝试以下方法:

    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
    

    要仔细检查为什么按ESC键不会将键码27传递给 cv.WaitKey ,请尝试打印上面的键码 k ,看看当你按下ESC时会发生什么 .

  • 0

    使用'q'的int值而不是'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
    

相关问题