def croproi(frame,roiindex,roicenter_pixels,cropsize=(300,300),background=None,
            flip=False,cropoffset=(0,0)):
    roicenter = roicenter_pixels[roiindex]
    roicenter = (roicenter[0] + cropoffset[0], roicenter[1] + cropoffset[1])
    
    frame = imgproc.croprect(roicenter,cropsize,frame)
    if background is not None:
        background = imgproc.croprect(roicenter,cropsize,background)
        frame = cv2.subtract(frame,background)
    if flip:
        frame = cv2.flip(frame,1)
    return frame
Ejemplo n.º 2
0
def croproi(frame,roiindex,roicenter_pixels,cropsize=(300,300),background=None,
            flip=False,cropoffset=(0,0)):
    roicenter = roicenter_pixels[roiindex]
    roicenter = (roicenter[0] + cropoffset[0], roicenter[1] + cropoffset[1])
    
    frame = imgproc.croprect(roicenter,cropsize,frame)
    if background is not None:
        background = imgproc.croprect(roicenter,cropsize,background)
        frame = cv2.subtract(frame,background)
    if flip:
        frame = cv2.flip(frame,1)
    return frame
 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
Ejemplo n.º 4
0
def clusterslipframes(act, info, leftgap, rightgap):
    slipactivity = act.iloc[:, 25:32]
    return clusterroiframes(
        act, slipactivity, info, leftgap, rightgap, slipcenter_cm,
        lambda f, i: imgproc.croprect(
            (slipcenter_pixels[i][0] - 100, slipcenter_pixels[i][1]),
            (300, 400), f))
Ejemplo n.º 5
0
def medianposture(steps,info,cropsize=(300,300),ax=None):
    if ax is None:
        fig = plt.figure()
        ax = fig.gca()
    
    xhead = activitytables.flipleftwards(steps.xhead,steps.side)
    median = steps[xhead == xhead.median()].iloc[-1,:]
    stepindex = 4 if median.side == 'leftwards' else 3
    stepcenter = steprois_crop.center[stepindex]
    info = info.ix[median.name[:2],:]
    videopath = datapath.relativepath(info,'front_video.avi')
    
    background = video.readsinglebackground(videopath,median.frame)
    background = cv2.cvtColor(background,cv2.cv.CV_GRAY2BGR)
    background *= 2.1
    
    frame = video.readsingleframe(videopath,median.frame,segmented=True)
    _,mask = cv2.threshold(frame,3,255,cv2.cv.CV_THRESH_BINARY)
    mask = mask.astype(np.bool)
    frame = cv2.cvtColor(frame,cv2.cv.CV_GRAY2BGR)
    frame *= 2.1
    
    frame[mask,...] += background[mask,...]
    fliprois = RoiSet(steprois_pixels.rois,flipxy=True)
    pts = np.array(fliprois.rois[stepindex])
    cv2.polylines(background,[pts],True,(0,0,255),2)
    background[mask,...] = frame[mask,...]
    frame = background
    
    frame = imgproc.croprect(stepcenter,cropsize,frame)
    ax.imshow(frame)
    x,y = _cmtopixel_(median.xhead,median.yhead)
    x,y = _pixelcrop_(x,y,stepcenter,cropsize)
    ax.scatter(x,y,color='r')
    ax.set_axis_off()
def clusterstepframes(act, info, leftstep, rightstep):
    stepactivity = act.iloc[:, 17:25]
    return clusterroiframes(
        act,
        stepactivity,
        info,
        leftstep,
        rightstep,
        stepcenter_cm,
        lambda f, i: imgproc.croprect(stepcenter_pixels[i], (200, 200), f),
    )
def clusterslipframes(act, info, leftgap, rightgap):
    slipactivity = act.iloc[:, 25:32]
    return clusterroiframes(
        act,
        slipactivity,
        info,
        leftgap,
        rightgap,
        slipcenter_cm,
        lambda f, i: imgproc.croprect((slipcenter_pixels[i][0] - 100, slipcenter_pixels[i][1]), (300, 400), f),
    )
    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
Ejemplo n.º 9
0
def clusterstepframes(act, info, leftstep, rightstep):
    stepactivity = act.iloc[:, 17:25]
    return clusterroiframes(
        act, stepactivity, info, leftstep, rightstep, stepcenter_cm,
        lambda f, i: imgproc.croprect(stepcenter_pixels[i], (200, 200), f))
Ejemplo n.º 10
0
def clusterstepframes(act, info, leftstep, rightstep):
    stepactivity = act.iloc[:, stepslice]
    return clusterroiframes(
        act, stepactivity, info, leftstep, rightstep, steprois_cm.center,
        lambda f, i: imgproc.croprect(steprois_crop.center[i], (200, 200), f))