pilas.video.webcam

Package pilas :: Package video :: Module webcam |
[hide private]
[frames] | no frames]

# Source Code for Module pilas.video.webcam

     1  '''
     2  import pilas
     3  try:
     4      import Image
     5      import opencv
     6      from opencv import highgui
     7
     8      GLOBALCAM=highgui.cvCreateCameraCapture(0)
     9
    10      for algo in range(30):
    11          ULTIMO_CUADRO_BASURA = highgui.cvQueryFrame(GLOBALCAM)
    12
    13      ULTIMO_CUADRO_BASURA = opencv.adaptors.Ipl2PIL(opencv.cvGetMat(ULTIMO_CUADRO_BASURA)).convert('RGBA')
    14  except ImportError:
    15      print "Falta la biblioteca opencv o PIL"
    16      pass
    17
    18
    19  class __camara_buffer(object):
    20      def __init__(self):
    21          self._ultimo_numero_de_cuadro = 0
    22          self._camera = GLOBALCAM
    23          self._ultimo_cuadro = ULTIMO_CUADRO_BASURA.tostring()
    24
    25      def _obtener_imagen_de_camara(self):
    26          imagen_ipl = highgui.cvQueryFrame(self._camera)
    27          imagen_ipl = opencv.cvGetMat(imagen_ipl)
    28          self._ultimo_cuadro = opencv.adaptors.Ipl2PIL(imagen_ipl).convert('RGBA').tostring()
    29
    30      def obtener_imagen(self, numero_de_cuadro=0):
    31          if numero_de_cuadro == self._ultimo_numero_de_cuadro:
    32             self._obtener_imagen_de_camara()
    33             self._ultimo_numero_de_cuadro += 1
    34          return self._ultimo_cuadro, self._ultimo_numero_de_cuadro
    35
    36  CamaraWeb = __camara_buffer()
    37  '''
    38