Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/301.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在openkinect中停止和启动kinect?_Python_Kinect_Openkinect - Fatal编程技术网

Python 如何在openkinect中停止和启动kinect?

Python 如何在openkinect中停止和启动kinect?,python,kinect,openkinect,Python,Kinect,Openkinect,我将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

我将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
当我按escape时,该程序不会停止。所以我试着执行它如下

   #!/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必须重新启动。我不能让它一直执行下去


谁能帮我一下吗。

无需停止Kinect:似乎打破while的条件从未满足过。 这可能取决于平台、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键不能将keycode 27传递到
cv.WaitKey
请尝试打印上面的keycode
k
,查看按下ESC键时会发生什么情况。

无需停止Kinect:似乎从未满足中断while的条件。 这可能取决于平台、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键不能将keycode 27传递给
cv.WaitKey
请尝试打印上面的keycode
k
,看看当您按ESC键时会发生什么。

使用“q”的int值而不是“q”

使用“q”的int值而不是“q”

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