camera.py 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. _is_init = 0
  2. def init():
  3. global list_cameras, Camera, colorspace, _is_init
  4. import os,sys
  5. use_opencv = False
  6. use_vidcapture = False
  7. use__camera = True
  8. if sys.platform == 'win32':
  9. use_vidcapture = True
  10. use__camera = False
  11. elif "linux" in sys.platform:
  12. use__camera = True
  13. elif "darwin" in sys.platform:
  14. use__camera = True
  15. else:
  16. use_opencv = True
  17. # see if we have any user specified defaults in environments.
  18. camera_env = os.environ.get("PYGAME_CAMERA", "")
  19. if camera_env == "opencv":
  20. use_opencv = True
  21. if camera_env == "vidcapture":
  22. use_vidcapture = True
  23. # select the camera module to import here.
  24. # the _camera module has some code which can be reused by other modules.
  25. # it will also be the default one.
  26. if use__camera:
  27. from pygame import _camera
  28. colorspace = _camera.colorspace
  29. list_cameras = _camera.list_cameras
  30. Camera = _camera.Camera
  31. if use_opencv:
  32. try:
  33. from pygame import _camera_opencv_highgui
  34. except:
  35. _camera_opencv_highgui = None
  36. if _camera_opencv_highgui:
  37. _camera_opencv_highgui.init()
  38. list_cameras = _camera_opencv_highgui.list_cameras
  39. Camera = _camera_opencv_highgui.Camera
  40. if use_vidcapture:
  41. try:
  42. from pygame import _camera_vidcapture
  43. except:
  44. _camera_vidcapture = None
  45. if _camera_vidcapture:
  46. _camera_vidcapture.init()
  47. list_cameras = _camera_vidcapture.list_cameras
  48. Camera = _camera_vidcapture.Camera
  49. _is_init = 1
  50. pass
  51. def quit():
  52. global _is_init
  53. _is_init = 0
  54. pass
  55. def _check_init():
  56. global _is_init
  57. if not _is_init:
  58. raise ValueError("Need to call camera.init() before using.")
  59. def list_cameras():
  60. """
  61. """
  62. _check_init()
  63. raise NotImplementedError()
  64. class Camera:
  65. def __init__(self, device =0, size = (320, 200), mode = "RGB"):
  66. """
  67. """
  68. _check_init()
  69. raise NotImplementedError()
  70. def set_resolution(self, width, height):
  71. """Sets the capture resolution. (without dialog)
  72. """
  73. pass
  74. def start(self):
  75. """
  76. """
  77. def stop(self):
  78. """
  79. """
  80. def get_buffer(self):
  81. """
  82. """
  83. def set_controls(self, **kwargs):
  84. """
  85. """
  86. def get_image(self, dest_surf = None):
  87. """
  88. """
  89. def get_surface(self, dest_surf = None):
  90. """
  91. """
  92. if __name__ == "__main__":
  93. # try and use this camera stuff with the pygame camera example.
  94. import pygame.examples.camera
  95. #pygame.camera.Camera = Camera
  96. #pygame.camera.list_cameras = list_cameras
  97. pygame.examples.camera.main()