def loadFrame(self, filename, frame_number): sys.stderr.write("Loading video frames isn't supported.") return None """ Load the video referenced to by the filename, and return frame ``frame_number``. In the default implementation this will try to load the video from a path relative to the label files directory. """ fullpath = str(self._fullpath(filename)) if not os.path.exists(fullpath) and not os.path.exists(fullpath.split('%')[0]): LOG.warn("Video file %s does not exist." % fullpath) return None # get video source from cache or load from file if fullpath in self._video_cache: vidsrc = self._video_cache[fullpath] else: vidsrc = okv.createVideoSourceFromString(fullpath) vidsrc = okv.toRandomAccessVideoSource(vidsrc) self._video_cache[fullpath] = vidsrc # get requested frame if not vidsrc.getFrame(frame_number): LOG.warn("Frame %d could not be loaded from video source %s" % (frame_number, fullpath)) return None return vidsrc.getImage()
def loadFrame(self, filename, frame_number): """ Load the video referenced to by the filename, and return frame ``frame_number``. In the default implementation this will try to load the video from a path relative to the label files directory. """ fullpath = str(self._fullpath(filename)) if not os.path.exists(fullpath) and not os.path.exists(fullpath.split('%')[0]): LOG.warn("Video file %s does not exist." % fullpath) return None # get video source from cache or load from file if fullpath in self._video_cache: vidsrc = self._video_cache[fullpath] else: vidsrc = okv.createVideoSourceFromString(fullpath) vidsrc = okv.toRandomAccessVideoSource(vidsrc) self._video_cache[fullpath] = vidsrc # get requested frame if not vidsrc.getFrame(frame_number): LOG.warn("Frame %d could not be loaded from video source %s" % (frame_number, fullpath)) return None return vidsrc.getImage()
def addVideoFile(self, fname): fileitem = { 'filename': fname, 'class': 'video', 'frames': [], } # FIXME: OKAPI should provide a method to get all timestamps at once # FIXME: Some dialog should be displayed, telling the user that the # video is being loaded/indexed and that this might take a while LOG.info("Importing frames from %s. This may take a while..." % fname) video = okv.createVideoSourceFromString(fname) video = okv.toRandomAccessVideoSource(video) # try to convert to iseq, getting all timestamps will be significantly faster iseq = okv.toImageSeqReader(video) if iseq is not None: timestamps = iseq.getTimestamps() LOG.debug("Adding %d frames" % len(timestamps)) fileitem['frames'] = [{ 'annotations': [], 'num': i, 'timestamp': ts, 'class': 'frame' } for i, ts in enumerate(timestamps)] else: i = 0 while video.getNextFrame(): LOG.debug("Adding frame %d" % i) ts = video.getTimestamp() frame = { 'annotations': [], 'num': i, 'timestamp': ts, 'class': 'frame' } fileitem['frames'].append(frame) i += 1 self._model._root.appendFileItem(fileitem)
def addVideoFile(self, fname): sys.stderr.write("Loading videos isn't supported.") return None fileitem = { 'filename': fname, 'class': 'video', 'frames': [], } # FIXME: OKAPI should provide a method to get all timestamps at once # FIXME: Some dialog should be displayed, telling the user that the # video is being loaded/indexed and that this might take a while LOG.info("Importing frames from %s. This may take a while..." % fname) video = okv.createVideoSourceFromString(fname) video = okv.toRandomAccessVideoSource(video) # try to convert to iseq, getting all timestamps will be significantly faster iseq = okv.toImageSeqReader(video) if iseq is not None: timestamps = iseq.getTimestamps() LOG.debug("Adding %d frames" % len(timestamps)) fileitem['frames'] = [{'annotations': [], 'num': i, 'timestamp': ts, 'class': 'frame'} for i, ts in enumerate(timestamps)] else: i = 0 while video.getNextFrame(): LOG.debug("Adding frame %d" % i) ts = video.getTimestamp() frame = {'annotations': [], 'num': i, 'timestamp': ts, 'class': 'frame' } fileitem['frames'].append(frame) i += 1 self._model._root.appendFileItem(fileitem)