当前位置: 首页>>代码示例>>Python>>正文


Python Clock.getTime方法代码示例

本文整理汇总了Python中psychopy.clock.Clock.getTime方法的典型用法代码示例。如果您正苦于以下问题:Python Clock.getTime方法的具体用法?Python Clock.getTime怎么用?Python Clock.getTime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psychopy.clock.Clock的用法示例。


在下文中一共展示了Clock.getTime方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: MovieStim3

# 需要导入模块: from psychopy.clock import Clock [as 别名]
# 或者: from psychopy.clock.Clock import getTime [as 别名]

#.........这里部分代码省略.........
    def setFlipVert(self, newVal=True, log=True):
        """If set to True then the movie will be flipped vertically (top-to-bottom).
        Note that this is relative to the original, not relative to the current state.
        """
        self.flipVert = not newVal
        logAttrib(self, log, 'flipVert')

    def getFPS(self):
        """
        Returns the movie frames per second playback speed.
        """
        return self._mov.fps

    def getCurrentFrameTime(self):
        """
        Get the time that the movie file specified the current video frame as
        having.
        """
        return self._nextFrameT - self._frameInterval

    def _updateFrameTexture(self):
        if self._nextFrameT is None:
            # movie has no current position, need to reset the clock
            # to zero in order to have the timing logic work
            # otherwise the video stream would skip frames until the
            # time since creating the movie object has passed
            self._videoClock.reset()
            self._nextFrameT = 0

        #only advance if next frame (half of next retrace rate)
        if self._nextFrameT > self.duration:
            self._onEos()
        elif (self._numpyFrame is not None) and \
            (self._nextFrameT > (self._videoClock.getTime()-self._retraceInterval/2.0)):
            return None
        self._numpyFrame = self._mov.get_frame(self._nextFrameT)
        useSubTex=self.useTexSubImage2D
        if self._texID is None:
            self._texID = GL.GLuint()
            GL.glGenTextures(1, ctypes.byref(self._texID))
            useSubTex=False

        #bind the texture in openGL
        GL.glEnable(GL.GL_TEXTURE_2D)
        GL.glBindTexture(GL.GL_TEXTURE_2D, self._texID)#bind that name to the target
        GL.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_WRAP_S,GL.GL_REPEAT) #makes the texture map wrap (this is actually default anyway)
        GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1)  # data from PIL/numpy is packed, but default for GL is 4 bytes
        #important if using bits++ because GL_LINEAR
        #sometimes extrapolates to pixel vals outside range
        if self.interpolate:
            GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR)
            GL.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR)
            if useSubTex is False:
                GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8,
                    self._numpyFrame.shape[1],self._numpyFrame.shape[0], 0,
                    GL.GL_RGB, GL.GL_UNSIGNED_BYTE, self._numpyFrame.ctypes)
            else:
                GL.glTexSubImage2D(GL.GL_TEXTURE_2D, 0, 0, 0,
                    self._numpyFrame.shape[1], self._numpyFrame.shape[0],
                    GL.GL_RGB, GL.GL_UNSIGNED_BYTE, self._numpyFrame.ctypes)

        else:
            GL.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MAG_FILTER,GL.GL_NEAREST)
            GL.glTexParameteri(GL.GL_TEXTURE_2D,GL.GL_TEXTURE_MIN_FILTER,GL.GL_NEAREST)
            if useSubTex is False:
                GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB8,
开发者ID:papr,项目名称:psychopy,代码行数:70,代码来源:movie3.py

示例2: MovieStim2

# 需要导入模块: from psychopy.clock import Clock [as 别名]
# 或者: from psychopy.clock.Clock import getTime [as 别名]

#.........这里部分代码省略.........
                v = int(v)
            self.volume = v
            self._audio_stream_player.audio_set_volume(v)

    def getVolume(self):
        """
        Returns the current movie audio volume. 0 is no audio, 100 is max audio
        volume.
        """
        if self._audio_stream_player:
            self.volume = self._audio_stream_player.audio_get_volume()
        return self.volume

    def getFPS(self):
        """
        Returns the movie frames per second playback speed.
        """
        return self._video_frame_rate

    def setFPS(self, fps):
        """
        If the movie was created with noAudio = True kwarg, then the movie
        playback speed can be changed from the original frame rate. For example,
        if the movie being played has 30 fps and you would like to play it at 2x
        normal speed, setFPS(60) will do that.
        """
        if self._no_audio:
            self._requested_fps = fps
            self._video_frame_rate = fps
            self._inter_frame_interval = 1.0/self._video_frame_rate
            return
        raise ValueError("Error calling movie.setFPS(): MovieStim must be created with kwarg noAudio=True.")

    def getTimeToNextFrameDraw(self):
        """
        Get the number of sec.msec remaining until the next movie video frame
        should be drawn.
        """
#        rt = (self._next_frame_sec - 1.0/self._retracerate) - self._video_track_clock.getTime()
        try:
            rt = (self._next_frame_sec - 1.0/self._retracerate) - self._video_track_clock.getTime()
            #print "getTimeToNextFrameDraw: ",self.getCurrentFrameNumber(), rt
            return rt
        except:
            #import traceback
            #traceback.print_exc()
            logging.WARNING("MovieStim2.getTimeToNextFrameDraw failed.")
            return 0.0

    def shouldDrawVideoFrame(self):
        """
        True if the next movie frame should be drawn, False if it is not yet
        time. See getTimeToNextFrameDraw().
        """
        return self.getTimeToNextFrameDraw() <= 0.0

    def getCurrentFrameNumber(self):
        """
        Get the current movie frame number. The first frame number in a file is
        1.
        """
        return self._next_frame_index

    def getCurrentFrameTime(self):
        """
        Get the time that the movie file specified the current video frame as
开发者ID:alexholcombe,项目名称:psychopy,代码行数:70,代码来源:movie2.py

示例3: MovieStim2

# 需要导入模块: from psychopy.clock import Clock [as 别名]
# 或者: from psychopy.clock.Clock import getTime [as 别名]

#.........这里部分代码省略.........

        self._audio_stream_clock = Clock()
        self._vlc_instance = None
        self._audio_stream = None
        self._audio_stream_player = None
        self._audio_stream_started = False
        self._audio_stream_event_manager = None

    def setMovie(self, filename, log=True):
        """See `~MovieStim.loadMovie` (the functions are identical).
        This form is provided for syntactic consistency with other visual stimuli.
        """
        self.loadMovie(filename, log=log)

    def loadMovie(self, filename, log=True):
        """Load a movie from file

        :Parameters:

            filename: string
                The name of the file, including path if necessary


        After the file is loaded MovieStim.duration is updated with the movie
        duration (in seconds).
        """
        self._unload()
        self._reset()
        if self._no_audio is False:
            self._createAudioStream()

        # Create Video Stream stuff
        self._video_stream.open(filename)
        vfstime = core.getTime()
        while not self._video_stream.isOpened() and core.getTime() - vfstime < 1.0:
            raise RuntimeError("Error when reading image file")

        if not self._video_stream.isOpened():
            raise RuntimeError("Error when reading image file")

        self._total_frame_count = self._video_stream.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)
        self._video_width = self._video_stream.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
        self._video_height = self._video_stream.get(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT)
        self._format = self._video_stream.get(cv2.cv.CV_CAP_PROP_FORMAT)
        # TODO: Read depth from video source
        self._video_frame_depth = 3

        cv_fps = self._video_stream.get(cv2.cv.CV_CAP_PROP_FPS)

        self._video_frame_rate = cv_fps

        self._inter_frame_interval = 1.0 / self._video_frame_rate

        # Create a numpy array that can hold one video frame, as returned by cv2.
        self._numpy_frame = numpy.zeros(
            (self._video_height, self._video_width, self._video_frame_depth), dtype=numpy.uint8
        )
        self.duration = self._total_frame_count * self._inter_frame_interval
        self.status = NOT_STARTED

        self.filename = filename
        logAttrib(self, log, "movie", filename)

    def _createAudioStream(self):
        """
        Create the audio stream player for the video using pyvlc.
开发者ID:RalRal,项目名称:psychopy,代码行数:70,代码来源:movie2.py

示例4: MovieStim2

# 需要导入模块: from psychopy.clock import Clock [as 别名]
# 或者: from psychopy.clock.Clock import getTime [as 别名]

#.........这里部分代码省略.........
        self._updateVertices()
        #set autoLog (now that params have been initialised)
        self.autoLog = autoLog
        if autoLog:
            logging.exp("Created %s = %s" %(self.name, str(self)))

    def _reset(self):
        self.duration = None
        self.status = NOT_STARTED
        self._numpy_frame = None
        self._frame_texture = None
        self._frame_data_interface = None
        self._video_stream = None
        self._total_frame_count = None
        self._video_width = None
        self._video_height = None
        # TODO: Read depth from video source
        self._video_frame_depth = 3
        self._video_frame_rate = None
        self._inter_frame_interval = None
        self._prev_frame_sec = None
        self._next_frame_sec = None
        self._next_frame_index = None
        self._prev_frame_index = None
        self._video_perc_done = None
        self._last_video_flip_time = None
        self._next_frame_displayed = False
        self._video_track_clock = Clock()
        self._vlc_instance = None
        self._vlc_event_manager = None
        self._audio_stream = None
        self._audio_stream_player = None
        self._audio_stream_started = False
        self._last_audio_callback_time = core.getTime()
        self._last_audio_stream_time = None
        self._first_audio_callback_time = None
        self._audio_computer_time_drift = None

    def setMovie(self, filename, log=True):
        """See `~MovieStim.loadMovie` (the functions are identical).
        This form is provided for syntactic consistency with other visual stimuli.
        """
        self.loadMovie(filename, log=log)

    def loadMovie(self, filename, log=True):
        """Load a movie from file

        :Parameters:

            filename: string
                The name of the file, including path if necessary


        After the file is loaded MovieStim.duration is updated with the movie
        duration (in seconds).
        """
        self._reset()
        self._unload()
        self._createAudioStream()
        self._video_stream = cv2.VideoCapture()
        self._video_stream.open(filename)
        if not self._video_stream.isOpened():
          raise RuntimeError( "Error when reading image file")

        self._total_frame_count = self._video_stream.get(cv2.cv.CV_CAP_PROP_FRAME_COUNT)
        self._video_width = self._video_stream.get(cv2.cv.CV_CAP_PROP_FRAME_WIDTH)
开发者ID:hanke,项目名称:psychopy,代码行数:70,代码来源:movie2.py


注:本文中的psychopy.clock.Clock.getTime方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。