Package pyforms :: Package terminal :: Package Controls :: Module ControlPlayer |
[hide private]
[frames] | no frames]

# Source Code for Module pyforms.terminal.Controls.ControlPlayer

      1  from pyforms.terminal.Controls.ControlBase import ControlBase
      2  import numpy
      3  import cv2
      4  import base64
      5  import numpy as np
      6  import StringIO
      7  from PIL import Image
      8
      9
     10
     11 -class ControlPlayer(ControlBase):
     12      _currentFrame = None
     13      _min = 0
     14      _max = 0
     15      _filename = ''
     16      _position = 0
     17
     18 -    def initControl(self):
     19          self._currentFrame = None
     20          return "controls.push(new ControlPlayer('"+self._name+"'));"
     21
     22 -    def processFrame(self, frame): pass
     23
     24 -    def updateFrame(self): pass
     25
     26 -    def videoPlay_clicked(self): pass
     27
     28 -    def save(self, data): pass
     29
     30 -    def load(self, data): pass
     31
     32 -    def refresh(self): pass
     33
     34 -    def convertFrameToTime(self, frame):
     35          currentMilliseconds = (frame / self.value.videoFrameRate) * 1000
     36          totalseconds = int(currentMilliseconds/1000)
     37          minutes = int(totalseconds / 60)
     38          seconds = totalseconds - (minutes*60)
     39          milliseconds = currentMilliseconds - (totalseconds*1000)
     40          return ( minutes, seconds, milliseconds )
     41
     42 -    def videoProgress_valueChanged(self): pass
     43
     44 -    def videoProgress_sliderReleased(self): pass
     45
     46 -    def videoFrames_valueChanged(self): pass
     47
     48 -    def isPlaying(self): pass
     49
     50 -    def changed(self): pass
     51
     52
     53      @property
     54 -    def value(self):
     55          result = {'min': self._min, 'max': self._max, 'position': self.video_index, 'frame': '', 'filename': self._filename }
     56          capture = self._value
     57
     58          _, image = capture.read()
     59          if isinstance(image, numpy.ndarray):
     60              image = self.processFrame(image)
     61
     62              if isinstance(image, list) or isinstance(image, tuple):
     63                  image = groupImage(image, True)
     64
     65
     66              if len(image.shape)>2: image = cv2.cvtColor(image,cv2.COLOR_BGR2RGB)
     67              image = Image.fromarray(image)
     68              buff = StringIO.StringIO()
     69              image.save(buff, format="PNG")
     70              content = buff.getvalue()
     71              buff.close()
     72              result['frame'] = base64.b64encode(content)
     73
     74          return result
     75
     76      @value.setter
     77 -    def value(self, value):
     78          if isinstance( value, (str, unicode) ):
     79              ControlBase.value.fset(self, cv2.VideoCapture( value ) )
     80              self._filename = value
     81          if isinstance( value, dict ):
     82              ControlBase.value.fset(self, cv2.VideoCapture( value['filename'] ) )
     83              if 'position' in value.keys(): self.video_index = int(value['position'])
     84              self._filename = value['filename']
     85          self._max = int(self._value.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT))
     86
     87
     88
     89      @property
     90 -    def video_index(self): return self._position
     91
     92      @video_index.setter
     93 -    def video_index(self, value): self._position = value
     94
     95
     96
     97      @property
     98 -    def startFrame(self):
     99          if self._value: return self._value.startFrame
    100          else: return -1
    101
    102      @startFrame.setter
    103 -    def startFrame(self, value): pass
    104
    105      @property
    106 -    def endFrame(self):
    107          if self._value: return self._value.startFrame
    108          else: return -1
    109
    110      @endFrame.setter
    111 -    def endFrame(self, value): pass
    112
    113
    114
    115      @property
    116 -    def image(self): return self._currentFrame
    117
    118      @image.setter
    119 -    def image(self, value): pass
    120