Control Logitech摄像头和模拟按键

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Control Logitech摄像头和模拟按键相关的知识,希望对你有一定的参考价值。

  1. #!/usr/bin/python
  2. from SimpleXMLRPCServer import SimpleXMLRPCServer
  3. import subprocess as subp
  4. import lpantilt
  5. import time
  6. import socket
  7. import thread
  8.  
  9. from ctypes import cdll
  10.  
  11. class Dir :
  12. UP = "UP>"
  13. DOWN = "DOWN>"
  14. LEFT = "LEFT>"
  15. RIGHT = "RIGHT>"
  16. RESET = "RESET>"
  17.  
  18.  
  19. class KeySimulator :
  20. PRESS_UP = 0
  21. PRESS_DOWN = 1
  22. PRESS_LEFT = 2
  23. PRESS_RIGHT = 3
  24. PRESS_ENTER = 4
  25. PRESS_ESC = 5
  26. PRESS_HOME = 6
  27.  
  28. def __init__(self):
  29. self.lib = cdll.LoadLibrary("./lib/Util_KeyPressSimulator.so")
  30.  
  31. def simPress(self, key):
  32. if key == "UP" :
  33. self.lib.press(self.PRESS_UP)
  34. elif key == "DOWN" :
  35. self.lib.press(self.PRESS_DOWN)
  36. elif key == "LEFT" :
  37. self.lib.press(self.PRESS_LEFT)
  38. elif key == "RIGHT" :
  39. self.lib.press(self.PRESS_RIGHT)
  40. elif key == "HOME" :
  41. self.lib.press(self.PRESS_HOME)
  42. elif key == "B" :
  43. self.lib.press(self.PRESS_ESC)
  44. elif key == "A" :
  45. self.lib.press(self.PRESS_ENTER)
  46.  
  47. print "simulating " + key
  48.  
  49. class CameraControl :
  50. def __init__(self):
  51. self.lpt = lpantilt.Lpantilt("/dev/video0")
  52. self.stop = False
  53. self.key_simulator = KeySimulator()
  54.  
  55. def move(self, drt):
  56. self.stop = False
  57. if drt == Dir.UP :
  58. thread.start_new_thread(self.startTilt,(0,-2))
  59. elif drt == Dir.DOWN:
  60. thread.start_new_thread(self.startTilt,(0,2))
  61. elif drt == Dir.LEFT :
  62. thread.start_new_thread(self.startTilt,(-2,0))
  63. elif drt == Dir.RIGHT :
  64. thread.start_new_thread(self.startTilt ,(2,0))
  65. elif drt == Dir.RESET :
  66. self.lpt.reset()
  67. else :
  68. self.stopMove()
  69.  
  70.  
  71. def startTilt(self, pan, tilt):
  72. while not self.stop :
  73. self.lpt.pantilt(pan, tilt)
  74. print "tilt ..."
  75.  
  76. def startPan(self, pan):
  77. while not self.stop :
  78. self.lpt.pan(pan)
  79. print "panning ..."
  80.  
  81. def stopMove(self):
  82. self.stop = True
  83. print "stop..."
  84.  
  85.  
  86. def updateState(self, state):
  87. print "new state = ", state
  88.  
  89. if state == "B-UP" :
  90. self.move(Dir.UP)
  91. elif state == "B-DOWN" :
  92. self.move(Dir.DOWN)
  93. elif state == "B-LEFT" :
  94. self.move(Dir.LEFT)
  95. elif state == "B-RIGHT" :
  96. self.move(Dir.RIGHT)
  97. elif state == "B-A" :
  98. self.move(Dir.RESET)
  99. else :
  100. print "else state " + state
  101. self.key_simulator.simPress(state)
  102. self.move(state)
  103.  
  104. if __name__ == "__main__" :
  105. c = CameraControl()
  106. server = SimpleXMLRPCServer( ("localhost", 9191) )
  107. server.register_function(c.updateState)
  108.  
  109. print "service start @localhost 9191 forever"
  110. server.serve_forever()

以上是关于Control Logitech摄像头和模拟按键的主要内容,如果未能解决你的问题,请参考以下文章

Window 10 OpenCV 打开罗技(Logitech)摄像头速度慢问题解决

罗技f710logitech profiler怎样使用

模拟 IP 摄像机 [关闭]

BetaFlight模块设计之十九:摄像头按键控制模拟任务分析

Python 的键盘事件,怎么模拟键盘的command键

华为nova16手机配置