예제 #1
0
 def __init__(self,
              srcFilePath=None,
              bgStart=0,
              nBackgroundFrames=1,
              delay=5):
     """
     :param str srcFilePath: The source file path to read from (camera if None)
     :param int bgStart: The frame to use as first background frame
     :param int nBackgroundFrames: The number of frames to use for the background\
     A number >1 means average
     :param int delay: The time in ms to wait between frames
     """
     trackRangeParams = (bgStart, nBackgroundFrames)
     if srcFilePath is None:
         if isPi:
             self._stream = PiVideoStream(destFilePath, *trackRangeParams)
         else:
             self._stream = UsbVideoStream(destFilePath, *trackRangeParams)
     else:
         self._stream = RecordedVideoStream(srcFilePath, *trackRangeParams)
     self.delay = delay
예제 #2
0
    def __init__(self,
                 srcFilePath=None,
                 destFilePath=None,
                 threshold=20,
                 minArea=100,
                 maxArea=5000,
                 teleportationThreshold=10,
                 bgStart=0,
                 trackFrom=1,
                 trackTo=None,
                 nBackgroundFrames=1,
                 nSds=5.0,
                 clearBorders=False,
                 normalise=False,
                 plot=False,
                 fast=False,
                 extractArena=False,
                 cameraCalibration=None,
                 callback=None):
        """
        :param str srcFilePath: The source file path to read from (camera if None)
        :param str destFilePath: The destinatiopn file path to save the video
        :param int threshold: The numeric threshold for the masks (0<t<256)
        :param int minArea: The minimum area in pixels to be considered a valid mouse
        :param int minArea: The maximum area in pixels to be considered a valid mouse
        :param teleportationThreshold: The maximum number of pixels the mouse can \
        move in either dimesion (x,y) between 2 frames.
        :param int bgStart: The frame to use as first background frame
        :param int nBackgroundFrames: The number of frames to use for the background\
        A number >1 means average
        :param int nSds: The number of standard deviations the signal has to be above\
        to be considered above threshold. This option is not used if \
        nBackgroundFrames < 2
        :param int trackFrom: The frame to start tracking from
        :param int trackTo: The frame to stop tracking at
        :param bool clearBorders: Whether to clear objects that touch the outer borders\
        of the image.
        :param bool normalise: TODO
        :param bool plot: Whether to display the data during tracking:
        :param bool fast: Whether to skip some processing (e.g. frame denoising) for \
        the sake of acquisition speed.
        :param bool extractArena: Whether to detect the arena (it should be brighter than\
        the surrounding) from the background as an ROI.
        :param callback: The function to be executed upon finding the mouse in the ROI \
        during tracking.
        :type callback: `function`
        """

        if callback is not None: self.callback = callback
        trackRangeParams = (bgStart, nBackgroundFrames)
        if srcFilePath is None:
            if isPi:
                self._stream = PiVideoStream(destFilePath, *trackRangeParams)
            else:
                self._stream = UsbVideoStream(destFilePath, *trackRangeParams)
        else:
            self._stream = RecordedVideoStream(srcFilePath, *trackRangeParams)

        self.threshold = threshold
        self.minArea = minArea
        self.maxArea = maxArea
        self.teleportationThreshold = teleportationThreshold

        self.trackFrom = trackFrom
        self.trackTo = trackTo

        self.clearBorders = clearBorders
        self.normalise = normalise
        self.plot = plot
        self.fast = fast
        self.extractArena = extractArena

        self.nSds = nSds
        self.bg = None
        self.bgStd = None

        self.cameraCalibration = cameraCalibration

        self.defaultPos = (-1, -1)
        self.positions = []