Merge branch 'camera_update' of https://github.com/akshayaurora/kivy into akshayaurora-camera_update

This commit is contained in:
Mathieu Virbel 2011-11-22 10:08:36 +01:00
commit be590903e6
5 changed files with 38 additions and 8 deletions

View File

@ -10,7 +10,6 @@ __all__ = ('CameraBase', 'Camera')
import sys
from kivy.clock import Clock
from kivy.event import EventDispatcher
from kivy.logger import Logger
from kivy.core import core_select_lib
@ -58,7 +57,7 @@ class CameraBase(EventDispatcher):
super(CameraBase, self).__init__()
self.register_event_type('on_load')
self.register_event_type('on_frame')
self.register_event_type('on_texture')
self.init_camera()
@ -101,13 +100,10 @@ class CameraBase(EventDispatcher):
def start(self):
'''Start the camera acquire'''
self.stopped = False
Clock.unschedule(self._update)
Clock.schedule_interval(self._update, 1. / 30)
def stop(self):
'''Release the camera'''
self.stopped = True
Clock.unschedule(self._update)
def _update(self, dt):
'''Update the camera (internal)'''
@ -120,9 +116,9 @@ class CameraBase(EventDispatcher):
return
self._texture.blit_buffer(self._buffer, colorfmt=self._format)
self._buffer = None
self.dispatch('on_frame')
self.dispatch('on_texture')
def on_frame(self):
def on_texture(self):
pass
def on_load(self):

View File

@ -4,7 +4,7 @@ GStreamer Camera: Implement CameraBase with GStreamer
__all__ = ('CameraGStreamer', )
from kivy.clock import Clock
from kivy.graphics.texture import Texture
from . import CameraBase
@ -77,7 +77,9 @@ class CameraGStreamer(CameraBase):
for x in self._decodebin.src_pads():
for cap in x.get_caps():
self._texturesize = (cap['width'], cap['height'])
Clock.schedule_once(self._update)
return
Clock.schedule_once(self._update)
def start(self):
super(CameraGStreamer, self).start()

View File

@ -9,6 +9,7 @@ OpenCV Camera: Implement CameraBase with OpenCV
__all__ = ('CameraOpenCV')
from kivy.logger import Logger
from kivy.clock import Clock
from kivy.graphics.texture import Texture
from . import CameraBase
@ -59,6 +60,11 @@ class CameraOpenCV(CameraBase):
# with self.init_camera (but slowly as we'd have to always get a frame).
self._resolution = (int(frame.width), int(frame.height))
#get fps
self.fps = cv.GetCaptureProperty(self._device, cv.CV_CAP_PROP_FPS)
if self.fps <= 0:
self.fps = 1/30
if not self.stopped:
self.start()
@ -83,3 +89,12 @@ class CameraOpenCV(CameraBase):
except:
Logger.exception('OpenCV: Couldn\'t get image from Camera')
def start(self):
super(CameraOpenCV, self).start()
Clock.unschedule(self._update)
Clock.schedule_interval(self._update, self.fps)
def stop(self):
super(CameraOpenCV, self).stop()
Clock.unschedule(self._update)

View File

@ -9,6 +9,7 @@ VideoCapture Camera: Implement CameraBase with VideoCapture
__all__ = ('CameraVideoCapture', )
from . import CameraBase
from kivy.clock import Clock
try:
from VideoCapture import Device
@ -33,6 +34,7 @@ class CameraVideoCapture(CameraBase):
self._device.setResolution(self.resolution[0], self.resolution[1])
except:
raise Exception('VideoCapture: Resolution not supported')
self.fps = 1 / 30
def _update(self, dt):
data, camera_width, camera_height = self._device.getBuffer()
@ -47,3 +49,14 @@ class CameraVideoCapture(CameraBase):
# update buffer
self._buffer = data
self._copy_to_gpu()
def start(self):
super(CameraVideoCapture, self).start()
Clock.unschedule(self._update)
Clock.schedule_interval(self._update, self.fps)
def stop(self):
super(CameraVideoCapture, self).stop()
Clock.unschedule(self._update)

View File

@ -89,6 +89,9 @@ class Camera(Image):
resolution=self._on_index)
self._on_index()
def on_tex(self, *l):
self.canvas.ask_update()
def _on_index(self, *largs):
self._camera = None
if self.index < 0:
@ -98,6 +101,7 @@ class Camera(Image):
self._camera.bind(on_load=self._camera_loaded)
if self.play:
self._camera.start()
self._camera.bind(on_texture=self.on_tex)
def _camera_loaded(self, *largs):
self.texture = self._camera.texture