Пример #1
0
def buf() :

    current_dset = dataset.dataset('data/basil/front', dtype=float)
    comp_dset = dataset.dataset('data/basil/front', dtype=float)


    kernel = np.array([[0,0,0], 
                       [0,18,0], 
                       [0,0,0]], dtype=float)

    time_kernel = np.array([[-1,-1,-1], 
                            [-1,-1,-1], 
                            [-1,-1,-1]], dtype=float)


    for i in comp_dset :
        i[...] = cv2.filter2D(i, -1, time_kernel)


    it = dataset.buffered_iterator(current_dset, 'movement3', bufsize = 30, outtype=np.uint8, start=1, end_offset=1)
    for i in it :

        i[...] = cv2.filter2D(i, -1, kernel)

        i[...] = comp_dset[it.index-1] + i + comp_dset[it.index+1] 

        mask = ((i > 100) | (i < -100))
        i[...][mask] = 0

        mask = (i != 0)
        i[...][mask] = 255

        mask = ((i[:,:,0] == 0) & (i[:,:,1] == 0) & (i[:,:,2] == 0))
        mask = np.invert(mask)
        i[...][mask] = 255 
Пример #2
0
def buf():

    current_dset = dataset.dataset('data/basil/front', dtype=float)
    comp_dset = dataset.dataset('data/basil/front', dtype=float)

    kernel = np.array([[0, 0, 0], [0, 18, 0], [0, 0, 0]], dtype=float)

    time_kernel = np.array([[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]],
                           dtype=float)

    for i in comp_dset:
        i[...] = cv2.filter2D(i, -1, time_kernel)

    it = dataset.buffered_iterator(current_dset,
                                   'movement3',
                                   bufsize=30,
                                   outtype=np.uint8,
                                   start=1,
                                   end_offset=1)
    for i in it:

        i[...] = cv2.filter2D(i, -1, kernel)

        i[...] = comp_dset[it.index - 1] + i + comp_dset[it.index + 1]

        mask = ((i > 100) | (i < -100))
        i[...][mask] = 0

        mask = (i != 0)
        i[...][mask] = 255

        mask = ((i[:, :, 0] == 0) & (i[:, :, 1] == 0) & (i[:, :, 2] == 0))
        mask = np.invert(mask)
        i[...][mask] = 255
Пример #3
0
def pofconcept():

    dset = dataset.dataset('data/basil/front')

    buffer = np.copy(dset[2])

    buffer -= dset[1]

    buffer2 = np.copy(dset[2])

    buffer2 = buffer2.astype(float)

    buffer2 -= dset[1]

    bmask = ((buffer2 > 0) & (buffer2 < 255))
    buffer2[bmask] = 0
    bmask = (buffer2 != 0)
    buffer2[bmask] = 255

    bmask = (buffer2[:, :, 0] == 255) & (buffer2[:, :, 1]
                                         == 255) & (buffer2[:, :, 2] == 255)
    bmask = np.invert(bmask)
    buffer2[bmask] = 0

    cvutil.comp_images(buffer, buffer2.astype(np.uint8))
Пример #4
0
def poc2():

    dset = dataset.dataset('data/basil/front', dtype=float)

    #h, s, v = cv2.split(cv2.cvtColor(dset[1], cv2.COLOR_BGR2HSV))

    past = np.copy(dset[1])
    current = np.copy(dset[2])
    future = np.copy(dset[3])

    kernel = np.array([[0, 0, 0], [0, 18, 0], [0, 0, 0]], dtype=float)

    time_kernel = np.array([[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]],
                           dtype=float)

    past = cv2.filter2D(past, -1, time_kernel)
    current = cv2.filter2D(current, -1, kernel)
    future = cv2.filter2D(future, -1, time_kernel)

    result = past + current + future

    mask = ((result > 100) | (result < -100))
    result[mask] = 0

    mask = (result != 0)
    result[mask] = 255

    mask = ((result[:, :, 0] == 0) & (result[:, :, 1] == 0) &
            (result[:, :, 2] == 0))
    mask = np.invert(mask)
    result[mask] = 255

    dset.set_dtype(np.uint8)

    cvutil.comp_images(dset[2], result.astype(np.uint8))
Пример #5
0
def poc() :

    dset = dataset.dataset('data/basil/front')

    
    #h, s, v = cv2.split(cv2.cvtColor(dset[1], cv2.COLOR_BGR2HSV))

    result = np.copy(dset[1])


    kernel = np.array([[0,-1,0], 
                       [-1,5,-1], 
                       [0,-1,0]], dtype=float)

    #kernel *= 1/(kernel.shape[0] * kernel.shape[1])


    #for p in (b, g, r) :
    #    p[...] = ndimage.correlate(p, kernel)
    #    p[...] = np.clip(p, 0, 255)
    
    #v = ndimage.convolve(v, kernel)
    result = cv2.filter2D(result, -1, kernel)
    #v = np.clip(v, 0, 255)

    
    #result = cv2.merge((h, s, v))
    #result = cv2.cvtColor(result, cv2.COLOR_HSV2BGR)

    cvutil.comp_images(dset[1], result)
Пример #6
0
def sparse_optical_flow() :
    dset = dataset.dataset('data/basil/front')

    tracking = cv2.goodFeaturesToTrack(cv2.cvtColor(dset[1], cv2.COLOR_BGR2GRAY), maxCorners = 100, qualityLevel = 0.3, minDistance = 7, blockSize = 7)

    old = None

    for d in range(2,len(dset)) :

        very_old = old

        old = np.copy(tracking)

        tracking, status, error = cv2.calcOpticalFlowPyrLK(cv2.cvtColor(dset[d - 1],cv2.COLOR_BGR2GRAY), cv2.cvtColor(dset[d], cv2.COLOR_BGR2GRAY), old, None, winSize=(15,15), maxLevel= 2)

        for i in range(old.shape[0]) :

            for j in range(old.shape[1]) :

                if (very_old != None) :
                    cv2.line(dset[d-1], (very_old[i][j][0], very_old[i][j][1]), (old[i][j][0], old[i][j][1]), (0,0,255), thickness=4)

                cv2.circle(dset[d-1], (old[i][j][0], old[i][j][1]), 4, (255,0,0), thickness=-1)


    dset.write_images('optflowbw')
Пример #7
0
def apply_test():

    dset = dataset.dataset('data/basil/front', dtype=float)

    def black(image):
        image[:, :, 0] = 0
        image[:, :, 1] = 0
        image[:, :, 2] = 0

    dset.apply(black, 'black')
Пример #8
0
def apply_test() :

    dset = dataset.dataset('data/basil/front', dtype=float)

    def black(image) :
        image[:,:,0] = 0
        image[:,:,1] = 0
        image[:,:,2] = 0

    dset.apply(black, 'black')
Пример #9
0
def main() :

    current_dset = dataset.dataset('data/basil/front', dtype=float)
    comp_dset = dataset.dataset('data/basil/front', dtype=float)


    kernel = np.array([[0,0,0], 
                       [0,18,0], 
                       [0,0,0]], dtype=float)

    time_kernel = np.array([[-1,-1,-1], 
                            [-1,-1,-1], 
                            [-1,-1,-1]], dtype=float)


    for i in comp_dset :
        i[...] = cv2.filter2D(i, -1, time_kernel)

    for i in current_dset :
        i[...] = cv2.filter2D(i, -1, kernel)

    for i in range(1, len(current_dset) -1 ) :
        current_dset[i] = comp_dset[i-1] + current_dset[i] + comp_dset[i+1] 

        mask = ((current_dset[i] > 100) | (current_dset[i] < -100))
        current_dset[i][mask] = 0

        mask = (current_dset[i] != 0)
        current_dset[i][mask] = 255

        mask = ((current_dset[i][:,:,0] == 0) & (current_dset[i][:,:,1] == 0) & (current_dset[i][:,:,2] == 0))
        mask = np.invert(mask)
        current_dset[i][mask] = 255 

        current_dset[i] = current_dset[i].astype(np.uint8)

    current_dset.set_dtype(np.uint8)

    current_dset.write_images('movement3')
Пример #10
0
def main() :
    
    for s in sources :

        print("starting " + s)
        dset = dataset.dataset(os.path.join(source_root, s))
        final_dest = os.path.join(dest, dest_prefix + s)

        iterator = dataset.buffered_iterator(dset, final_dest, video=True, fps=40) 
        for f in iterator :
            dataset.print_status_bar(iterator.index, iterator.end);
            pass

        print("\nfinished " + s)
Пример #11
0
def main():
    dset = dataset.dataset('data/basil/front')

    for i in dset:
        converted = cv2.cvtColor(i, cv2.COLOR_BGR2HSV)
        h, s, v = cv2.split(converted)
        mask = (h > 45) & (h < 90)
        mask = np.invert(mask)
        v[mask] = 0
        converted = cv2.merge([h, s, v])

        i[...] = cv2.cvtColor(converted, cv2.COLOR_HSV2BGR)

    dset.write_images('colorf')
Пример #12
0
def main():

    current_dset = dataset.dataset('data/basil/front', dtype=float)
    comp_dset = dataset.dataset('data/basil/front', dtype=float)

    kernel = np.array([[0, 0, 0], [0, 18, 0], [0, 0, 0]], dtype=float)

    time_kernel = np.array([[-1, -1, -1], [-1, -1, -1], [-1, -1, -1]],
                           dtype=float)

    for i in comp_dset:
        i[...] = cv2.filter2D(i, -1, time_kernel)

    for i in current_dset:
        i[...] = cv2.filter2D(i, -1, kernel)

    for i in range(1, len(current_dset) - 1):
        current_dset[i] = comp_dset[i - 1] + current_dset[i] + comp_dset[i + 1]

        mask = ((current_dset[i] > 100) | (current_dset[i] < -100))
        current_dset[i][mask] = 0

        mask = (current_dset[i] != 0)
        current_dset[i][mask] = 255

        mask = ((current_dset[i][:, :, 0] == 0) &
                (current_dset[i][:, :, 1] == 0) &
                (current_dset[i][:, :, 2] == 0))
        mask = np.invert(mask)
        current_dset[i][mask] = 255

        current_dset[i] = current_dset[i].astype(np.uint8)

    current_dset.set_dtype(np.uint8)

    current_dset.write_images('movement3')
Пример #13
0
def main() :
    dset = dataset.dataset('data/basil/front')

    for i in dset :
        converted = cv2.cvtColor(i, cv2.COLOR_BGR2HSV)
        h, s, v = cv2.split(converted)
        mask = (h > 45) & (h < 90)
        mask = np.invert(mask)
        v[mask] = 0
        converted = cv2.merge([h,s,v])

        i[...] = cv2.cvtColor(converted, cv2.COLOR_HSV2BGR)


    dset.write_images('colorf')
Пример #14
0
def vein_detect():

    dset = dataset.dataset('data/basil/front', dtype=float)

    big_med = np.array([
        [1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 0, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1],
        [1, 1, 1, 1, 1, 1, 1],
    ],
                       dtype=float)

    big_sharp = np.array([
        [-1, 0, 0, -1, 0, 0, -1],
        [0, -1, 0, -1, 0, -1, 0],
        [0, 0, -1, -1, -1, 0, 0],
        [-1, -1, -1, 25, -1, -1, -1],
        [0, 0, -1, -1, -1, 0, 0],
        [0, -1, 0, -1, 0, -1, 0],
        [-1, 0, 0, -1, 0, 0, -1],
    ],
                         dtype=float)

    big_med *= (1 / 48)

    for image in dset:
        sharp_image = cv2.filter2D(image, -1, big_sharp)
        blur_image = cv2.filter2D(image, -1, big_med)

        sharp_image = np.clip(sharp_image, 0, 255)
        blur_image = np.clip(blur_image, 0, 255)
        result2 = sharp_image - blur_image

        result2[result2 < -40] = 0
        result2[result2 > 40] = 0
        result2[result2 != 0] = 255

        mask = (result2[..., 0] == 0) & (result2[..., 1]
                                         == 0) & (result2[..., 2] == 0)
        mask = np.invert(mask)
        result2[mask] = 255

        image[...] = result2

    dset.write_images('edge')
Пример #15
0
def main() :

    dset = dataset.dataset('data/basil/front')

    for i in range(len(dset) - 1, 0, -1) :

        dset[i] = dset[i].astype(float)

        dset[i] -= dset[i - 1]
        threshold(dset[i])
        
        dset[i] = dset[i].astype(np.uint8)

    cvutil.comp_images(dset[1], dset[2])

    dset.write_images('movement')
Пример #16
0
def main():

    dset = dataset.dataset('data/basil/front')

    for i in range(len(dset) - 1, 0, -1):

        dset[i] = dset[i].astype(float)

        dset[i] -= dset[i - 1]
        threshold(dset[i])

        dset[i] = dset[i].astype(np.uint8)

    cvutil.comp_images(dset[1], dset[2])

    dset.write_images('movement')
Пример #17
0
def poc():

    dset = dataset.dataset('data/basil/front')
    converted = cv2.cvtColor(dset[1], cv2.COLOR_BGR2HSV)

    h, s, v = cv2.split(converted)

    mask = (h > 45) & (h < 90)

    mask = np.invert(mask)

    v[mask] = 0

    converted = cv2.merge([h, s, v])

    cvutil.display_image(cv2.cvtColor(converted, cv2.COLOR_HSV2BGR))
Пример #18
0
def poc() :

    dset = dataset.dataset('data/basil/front')
    converted = cv2.cvtColor(dset[1], cv2.COLOR_BGR2HSV)


    h, s, v = cv2.split(converted)

    mask = (h > 45) & (h < 90)

    mask = np.invert(mask)

    v[mask] = 0

    converted = cv2.merge([h,s,v])

    cvutil.display_image(cv2.cvtColor(converted, cv2.COLOR_HSV2BGR))
Пример #19
0
def vein_detect() :

    dset = dataset.dataset('data/basil/front', dtype=float)

    big_med = np.array( [  [1, 1, 1, 1 ,1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 0, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1],
                           [1, 1, 1, 1, 1, 1, 1], ], dtype = float)

    big_sharp = np.array( [  [-1, 0, 0, -1 ,0, 0, -1],
                             [0, -1, 0, -1, 0, -1, 0],
                             [0, 0, -1, -1, -1, 0, 0],
                             [-1, -1, -1, 25, -1, -1, -1],
                             [0, 0, -1, -1, -1, 0, 0],
                             [0, -1, 0, -1, 0, -1, 0],
                             [-1, 0, 0, -1, 0, 0, -1], ], dtype = float)



    big_med *= (1/48)


    for image in dset :
        sharp_image = cv2.filter2D(image, -1, big_sharp)
        blur_image = cv2.filter2D(image, -1, big_med)

        sharp_image = np.clip(sharp_image, 0, 255)
        blur_image = np.clip(blur_image, 0, 255)
        result2 = sharp_image - blur_image

        result2[result2 < -40] = 0 
        result2[result2 > 40] = 0 
        result2[result2 != 0] = 255

        mask = (result2[...,0] == 0) & (result2[...,1] == 0) & (result2[...,2] == 0)
        mask = np.invert(mask)
        result2[mask] = 255

        image[...] = result2


    dset.write_images('edge')
Пример #20
0
def poc_dense() :

    dset = dataset.dataset('data/basil/front')
    first = cv2.cvtColor(dset[1],cv2.COLOR_BGR2GRAY, dstCn=1)
    last = cv2.cvtColor(dset[2], cv2.COLOR_BGR2GRAY, dstCn=1)

    canvas = np.zeros_like(dset[1])

    canvas[...,1] = 255

    flow = cv2.calcOpticalFlowFarneback(first,last ,flow=None, pyr_scale=0.5,levels= 3, winsize=15, iterations=2, poly_n=5, poly_sigma=1.1, flags=0)

    mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])

    canvas[...,0]  = ang * 180/np.pi/2
    canvas[...,2] = cv2.normalize(mag, None, 0, 255,cv2.NORM_MINMAX)

    print(canvas)
    cvutil.display_image(cv2.cvtColor(canvas, cv2.COLOR_HSV2BGR))
Пример #21
0
def poc():

    image = dataset.dataset('edge')[2]
    orig = np.copy(image)
    checker = gen_bound_checker(image)

    traces = []

    cvutil.display_image(image)

    for y in range(image.shape[0]):
        for x in range(image.shape[1]):
            if not (checker(x, y) or trace.in_any_traces(x, y)):
                t = trace(x, y, checker)
                t.trace_bounds()
                t.fill_bounds()
                traces.append(t)
                dataset.print_status_bar(y * image.shape[1] + x,
                                         image.shape[0] * image.shape[1])

    print('\n coloring')
    for i, t in enumerate(traces):
        if len(t) < 50:
            for p in t.points:
                image[p.y][p.x][0] = 200
                image[p.y][p.x][1] = 200
                image[p.y][p.x][2] = 200
        else:
            randcolor = (random.choice(range(255)), random.choice(range(255)),
                         random.choice(range(255)))
            for p in t.points:
                image[p.y][p.x][0] = randcolor[0]
                image[p.y][p.x][1] = randcolor[1]
                image[p.y][p.x][2] = randcolor[2]
            image[t.init_p.y][t.init_p.x][0] = 0
            image[t.init_p.y][t.init_p.x][1] = 0
            image[t.init_p.y][t.init_p.x][2] = 255
        dataset.print_status_bar(i, len(traces))

    cvutil.comp_images(orig, image)
Пример #22
0
def poc() :
    dset = dataset.dataset('data/basil/front')

    display = np.copy(dset[-1])

    tracking = cv2.goodFeaturesToTrack(cv2.cvtColor(dset[1], cv2.COLOR_BGR2GRAY), maxCorners = 100, qualityLevel = 0.3, minDistance = 7, blockSize = 7)

    old = tracking


    for i in range(2,len(dset)) :
        result, status, error = cv2.calcOpticalFlowPyrLK(dset[i - 1], dset[i], old, None, winSize=(15,15), maxLevel= 2)
        old = result

        for i in range(tracking.shape[0]) :

            for j in range(tracking.shape[1]) :

                cv2.circle(display, (old[i][j][0], old[i][j][1]), 4, (0,0,255))


    cvutil.display_image(display)
Пример #23
0
def poc2() :

    dset = dataset.dataset('data/basil/front', dtype=float)

    
    #h, s, v = cv2.split(cv2.cvtColor(dset[1], cv2.COLOR_BGR2HSV))

    past = np.copy(dset[1])
    current = np.copy(dset[2])
    future = np.copy(dset[3])

    kernel = np.array([[0,0,0], 
                       [0,18,0], 
                       [0,0,0]], dtype=float)

    time_kernel = np.array([[-1,-1,-1], 
                             [-1,-1,-1], 
                             [-1,-1,-1]], dtype=float)


    past = cv2.filter2D(past, -1, time_kernel)
    current = cv2.filter2D(current, -1, kernel)
    future = cv2.filter2D(future, -1, time_kernel)

    result = past + current + future

    mask = ((result > 100) | (result < -100))
    result[mask] = 0

    mask = (result != 0)
    result[mask] = 255

    mask = ((result[:,:,0] == 0) & (result[:,:,1] == 0) & (result[:,:,2] == 0))
    mask = np.invert(mask)
    result[mask] = 255 

    dset.set_dtype(np.uint8)

    cvutil.comp_images(dset[2], result.astype(np.uint8))
Пример #24
0
def dense_optical_flow() :
    dset = dataset.dataset('data/basil/front')

    prev = cv2.cvtColor(dset[1],cv2.COLOR_BGR2GRAY)
    canvas = np.zeros_like(dset[1])

    canvas[...,1] = 255

    for i in range(2, len(dset)) :
        next = cv2.cvtColor(dset[i], cv2.COLOR_BGR2GRAY)
        flow = cv2.calcOpticalFlowFarneback(prev, next, flow=None, pyr_scale=0.5,levels= 3, winsize=15, iterations=2, poly_n=5, poly_sigma=1.1, flags=0)

        mag, ang = cv2.cartToPolar(flow[...,0], flow[...,1])

        canvas[...,0]  = ang * 180/np.pi/2
        canvas[...,2] = cv2.normalize(mag, None, 0, 255,cv2.NORM_MINMAX)

        prev = np.copy(next)
        dset[i] = cv2.cvtColor(np.copy(canvas), cv2.COLOR_HSV2BGR)


    dset.write_images('denseflow')
Пример #25
0
def poc() :

    image = dataset.dataset('edge')[2]
    orig = np.copy(image)
    checker = gen_bound_checker(image)

    traces = []

    cvutil.display_image(image)

    for y in range(image.shape[0]) :
        for x in range(image.shape[1]) :
            if not (checker(x, y) or trace.in_any_traces(x, y)) :
                t = trace(x, y, checker)
                t.trace_bounds()
                t.fill_bounds()
                traces.append(t)
                dataset.print_status_bar(y * image.shape[1] + x, image.shape[0] * image.shape[1])

    print('\n coloring')
    for i,t in enumerate(traces) :
        if len(t) < 50 :
            for p in t.points :
                image[p.y][p.x][0] = 200
                image[p.y][p.x][1] = 200
                image[p.y][p.x][2] = 200
        else :
            randcolor = (random.choice(range(255)),random.choice(range(255)),random.choice(range(255)))
            for p in t.points :
                image[p.y][p.x][0] = randcolor[0]
                image[p.y][p.x][1] = randcolor[1]
                image[p.y][p.x][2] = randcolor[2]
            image[t.init_p.y][t.init_p.x][0] = 0
            image[t.init_p.y][t.init_p.x][1] = 0
            image[t.init_p.y][t.init_p.x][2] = 255
        dataset.print_status_bar(i, len(traces))

    cvutil.comp_images(orig, image)
Пример #26
0
def pofconcept() :

    dset = dataset.dataset('data/basil/front')

    buffer = np.copy(dset[2])

    buffer -= dset[1]

    buffer2 = np.copy(dset[2])

    buffer2 = buffer2.astype(float)

    buffer2 -= dset[1]

    bmask = ((buffer2 > 0) & (buffer2 < 255))
    buffer2[bmask] = 0
    bmask = (buffer2 != 0)
    buffer2[bmask] = 255

    bmask = (buffer2[:,:,0] == 255) & (buffer2[:,:,1] == 255) & (buffer2[:,:,2] == 255)
    bmask = np.invert(bmask)
    buffer2[bmask] = 0

    cvutil.comp_images(buffer, buffer2.astype(np.uint8))
Пример #27
0
def poc():

    dset = dataset.dataset('data/basil/front')

    #h, s, v = cv2.split(cv2.cvtColor(dset[1], cv2.COLOR_BGR2HSV))

    result = np.copy(dset[1])

    kernel = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], dtype=float)

    #kernel *= 1/(kernel.shape[0] * kernel.shape[1])

    #for p in (b, g, r) :
    #    p[...] = ndimage.correlate(p, kernel)
    #    p[...] = np.clip(p, 0, 255)

    #v = ndimage.convolve(v, kernel)
    result = cv2.filter2D(result, -1, kernel)
    #v = np.clip(v, 0, 255)

    #result = cv2.merge((h, s, v))
    #result = cv2.cvtColor(result, cv2.COLOR_HSV2BGR)

    cvutil.comp_images(dset[1], result)
Пример #28
0
def poc() :
    image = dataset.dataset('data//basil/front')[2]
    image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(image, 100,200)

    cvutil.display_image(cv2.cvtColor(edges, cv2.COLOR_GRAY2BGR))