Пример #1
0
 def background(self, frameindex):
     if self.timestamps is None:
         raise ValueError("video does not have timestamps")
     frametime = self.frametime(frameindex)
     vidfolder = os.path.split(self.path)[0]
     backfolder = os.path.join(vidfolder, r'Analysis\Background')
     return activitymovies.getbackground(backfolder, frametime)
def slipframes(slipactivity,
               info,
               cropsize=(300, 200),
               subtractBackground=False):
    vidpaths = activitymovies.getmoviepath(info)
    timepaths = activitymovies.gettimepath(info)
    backpaths = activitymovies.getbackgroundpath(info)
    videos = [
        video.video(path, timepath)
        for path, timepath in zip(vidpaths, timepaths)
    ]

    frames = []
    for index, trial in slipactivity.iterrows():
        rightwards = trial.side == 'rightwards'
        frame = videos[0].frame(trial.frame)
        background = None
        if subtractBackground:
            timestamp = videos[0].timestamps[trial.frame]
            background = activitymovies.getbackground(backpaths[0], timestamp)
        if cropsize is not None:
            frame = cropslip(frame, trial.gapindex, cropsize, background,
                             rightwards)
        frames.append(frame)
    return frames
def roiframes(indices,
              side,
              info,
              leftroi,
              rightroi,
              croproi,
              cropsize=(300, 300),
              subtractBackground=False):
    # Tile step frames
    vidpaths = activitymovies.getmoviepath(info)
    timepaths = activitymovies.gettimepath(info)
    backpaths = activitymovies.getbackgroundpath(info)
    videos = [
        video.video(path, timepath)
        for path, timepath in zip(vidpaths, timepaths)
    ]

    frames = []
    for frameindex, side in zip(indices, side):
        leftwards = side == 'leftwards'
        roiindex = leftroi if leftwards else rightroi

        frame = videos[0].frame(frameindex)
        background = None
        if subtractBackground:
            timestamp = videos[0].timestamps[frameindex]
            background = activitymovies.getbackground(backpaths[0], timestamp)
        frame = croproi(frame, roiindex, cropsize, background,
                        roiindex == rightroi)
        frames.append(frame)
    return frames
 def getstepframes(stepindex,flip=False):
     stepcenterxcm = stepcenters[stepindex][1] * preprocess.width_pixel_to_cm
     framehead = [p for p in pksloc[stepindex]
                  if (cr.xhead[p] < stepcenterxcm if not flip else cr.xhead[p] > stepcenterxcm)]
     
     frames = [imgproc.croprect(stepcenters[stepindex],(200,200),videos[0].frame(p))
               for p in framehead]
     backgrounds = [imgproc.croprect(stepcenters[stepindex],(200,200),activitymovies.getbackground(backpaths[0],videos[0].timestamps[p]))
                    for p in framehead]
     frames = [cv2.subtract(f,b) for f,b in zip(frames,backgrounds)]
     if flip:
         frames = [cv2.flip(f,1) for f in frames]
     return frames,framehead
    def getroiframes(roiindex, flip=False):
        roicenterxcm = roicenter_cm[roiindex][1]
        headdistance = [act.xhead[p] - roicenterxcm for p in pksloc[roiindex]]
        print headdistance
        framehead = [
            p
            for i, p in enumerate(pksloc[roiindex])
            if (-25 < headdistance[i] < -5 if not flip else 5 < headdistance[i] < 25)
        ]

        frames = [cropframes(videos[0].frame(p), roiindex) for p in framehead]
        backgrounds = [
            cropframes(activitymovies.getbackground(backpaths[0], videos[0].timestamps[p]), roiindex) for p in framehead
        ]
        frames = [cv2.subtract(f, b) for f, b in zip(frames, backgrounds)]
        if flip:
            frames = [cv2.flip(f, 1) for f in frames]
        return frames, framehead
Пример #6
0
    def getroiframes(roiindex, flip=False):
        roicenterxcm = roicenter_cm[roiindex][1]
        headdistance = [act.xhead[p] - roicenterxcm for p in pksloc[roiindex]]
        print headdistance
        framehead = [
            p for i, p in enumerate(pksloc[roiindex])
            if (-25 < headdistance[i] < -5
                if not flip else 5 < headdistance[i] < 25)
        ]

        frames = [cropframes(videos[0].frame(p), roiindex) for p in framehead]
        backgrounds = [
            cropframes(
                activitymovies.getbackground(backpaths[0],
                                             videos[0].timestamps[p]),
                roiindex) for p in framehead
        ]
        frames = [cv2.subtract(f, b) for f, b in zip(frames, backgrounds)]
        if flip:
            frames = [cv2.flip(f, 1) for f in frames]
        return frames, framehead
def roiframes(activity,crossings,info,leftroi,rightroi,roiframeindices,croproi,
               cropsize=(300,300),subtractBackground=False):
    # Tile step frames    
    vidpaths = activitymovies.getmoviepath(info)
    timepaths = activitymovies.gettimepath(info)
    backpaths = activitymovies.getbackgroundpath(info)
    videos = [video.video(path,timepath) for path,timepath in zip(vidpaths,timepaths)]
    
    frames = []
    indices,side = roiframeindices(activity,crossings,leftroi,rightroi)
    for frameindex,side in zip(indices,side):
        leftwards = side == 'leftwards'
        roiindex = leftroi if leftwards else rightroi
        
        frame = videos[0].frame(frameindex)
        background = None
        if subtractBackground:
            timestamp = videos[0].timestamps[frameindex]
            background = activitymovies.getbackground(backpaths[0],timestamp)
        frame = croproi(frame,roiindex,cropsize,background,roiindex == rightroi)
        frames.append(frame)
    return frames
    def getstepframes(stepindex, flip=False):
        stepcenterxcm = stepcenters[stepindex][1] * preprocess.width_pixel_to_cm
        framehead = [
            p for p in pksloc[stepindex]
            if (cr.xhead[p] < stepcenterxcm
                if not flip else cr.xhead[p] > stepcenterxcm)
        ]

        frames = [
            imgproc.croprect(stepcenters[stepindex], (200, 200),
                             videos[0].frame(p)) for p in framehead
        ]
        backgrounds = [
            imgproc.croprect(
                stepcenters[stepindex], (200, 200),
                activitymovies.getbackground(backpaths[0],
                                             videos[0].timestamps[p]))
            for p in framehead
        ]
        frames = [cv2.subtract(f, b) for f, b in zip(frames, backgrounds)]
        if flip:
            frames = [cv2.flip(f, 1) for f in frames]
        return frames, framehead