def clusterstepframes(cr, info, leftstep, rightstep):
    # Compute step times
    stepactivity = cr.iloc[:, 16:24]
    stepdiff = stepactivity.diff()
    steppeaks = siphon.findpeaksMax(stepdiff, 1500)
    pksloc = [[stepdiff.index.get_loc(peak) for peak in step]
              for step in steppeaks]

    # 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)
    ]

    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

    leftframes, leftindices = getstepframes(leftstep, False)
    rightframes, rightindices = getstepframes(rightstep, True)
    frames = np.array(leftframes + rightframes)
    frameindices = np.array(leftindices + rightindices)
    sortindices = np.argsort(frameindices)
    frames = frames[sortindices]
    frameindices = frameindices[sortindices]

    R, labels, h = imgproc.cluster(frames, videos[0], frameindices)
    return frames, stepdiff, steppeaks, pksloc, R, labels
Пример #2
0
def clusterroiframes(act, roiactivity, info, leftroi, rightroi, roicenter_cm,
                     cropframes):
    # Compute step times
    roidiff = roiactivity.diff()
    roipeaks = activitytables.findpeaks(roidiff, 1500)
    pksloc = [[roidiff.index.get_loc(peak) for peak in roi]
              for roi in roipeaks]

    # 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)
    ]

    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

    leftframes, leftindices = getroiframes(leftroi, False)
    rightframes, rightindices = getroiframes(rightroi, True)
    print "==========================="
    frames = np.array(leftframes + rightframes)
    frameindices = np.array(leftindices + rightindices)
    sortindices = np.argsort(frameindices)
    frames = frames[sortindices]
    frameindices = frameindices[sortindices]

    Z, R, labels, h = imgproc.cluster(frames, videos[0], frameindices)
    return frames, roidiff, roipeaks, pksloc, Z, R, labels
def clusterroiframes(act, roiactivity, info, leftroi, rightroi, roicenter_cm, cropframes):
    # Compute step times
    roidiff = roiactivity.diff()
    roipeaks = activitytables.findpeaks(roidiff, 1500)
    pksloc = [[roidiff.index.get_loc(peak) for peak in roi] for roi in roipeaks]

    # 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)]

    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

    leftframes, leftindices = getroiframes(leftroi, False)
    rightframes, rightindices = getroiframes(rightroi, True)
    print "==========================="
    frames = np.array(leftframes + rightframes)
    frameindices = np.array(leftindices + rightindices)
    sortindices = np.argsort(frameindices)
    frames = frames[sortindices]
    frameindices = frameindices[sortindices]

    Z, R, labels, h = imgproc.cluster(frames, videos[0], frameindices)
    return frames, roidiff, roipeaks, pksloc, Z, R, labels
def clusterstepframes(cr,info,leftstep,rightstep):
    # Compute step times
    stepactivity = cr.iloc[:,16:24]
    stepdiff = stepactivity.diff()
    steppeaks = siphon.findpeaksMax(stepdiff,1500)
    pksloc = [[stepdiff.index.get_loc(peak) for peak in step] for step in steppeaks]    
    
    # 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)]

    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

    leftframes,leftindices = getstepframes(leftstep,False)
    rightframes,rightindices = getstepframes(rightstep,True)
    frames = np.array(leftframes + rightframes)
    frameindices = np.array(leftindices + rightindices)
    sortindices = np.argsort(frameindices)
    frames = frames[sortindices]
    frameindices = frameindices[sortindices]
    
    R,labels,h = imgproc.cluster(frames,videos[0],frameindices)
    return frames,stepdiff,steppeaks,pksloc,R,labels