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))
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)
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))
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')
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')
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)
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))
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)
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)
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))
def poc(): dset = dataset.vidset('data/vid_top.avi') image = np.copy(dset[1]).astype(float) antia = np.array([[1, 2, 4, 2, 1], [2, 4, 8, 4, 2], [4, 8, 16, 8, 4], [2, 4, 8, 4, 2], [1, 2, 4, 2, 1]], dtype=float) big_antia = np.array([[1, 2, 4, 8, 4, 2, 1], [2, 4, 8, 16, 8, 4, 2], [4, 8, 16, 32, 16, 8, 4], [8, 16, 32, 64, 32, 16, 8], [4, 8, 16, 32, 16, 8, 4], [2, 4, 8, 16, 8, 4, 2], [1, 2, 4, 8, 4, 2, 1]], dtype=float) med = np.array([[1, 1, 1], [1, 0, 1], [1, 1, 1]], 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) sharp = np.array([[0, -1, 0], [-1, 5, -1], [0, -1, 0]], 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) med *= (1 / 8) big_med *= (1 / 48) antia *= (1 / 104) big_antia *= (1 / np.sum(big_antia)) 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) cvutil.comp_images(sharp_image.astype(np.uint8), blur_image.astype(np.uint8)) result1 = dset[1] - blur_image result1[result1 < -3] = 0 result1[result1 > 3] = 0 result1[result1 != 0] = 255 mask = (result1[..., 0] == 0) & (result1[..., 1] == 0) & (result1[..., 2] == 0) mask = np.invert(mask) result1[mask] = 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 cvutil.comp_images(result1.astype(np.uint8), result2.astype(np.uint8))
def poc() : dset = dataset.vidset('data/vid_top.avi') image = np.copy(dset[1]).astype(float) antia = np.array( [[1, 2, 4, 2 ,1], [2, 4, 8, 4, 2], [4, 8, 16, 8, 4], [2, 4, 8, 4, 2], [1, 2, 4, 2, 1]], dtype=float) big_antia = np.array( [[1, 2, 4, 8 ,4, 2, 1], [2, 4, 8, 16, 8, 4, 2], [4, 8, 16, 32, 16, 8, 4], [8, 16, 32, 64, 32, 16, 8], [4, 8, 16, 32, 16, 8, 4], [2, 4, 8, 16, 8, 4, 2], [1, 2, 4, 8 ,4, 2, 1]], dtype=float) med = np.array( [ [1,1,1], [1,0,1], [1,1,1]], 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) sharp = np.array( [ [0,-1,0], [-1,5,-1], [0,-1,0]], 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) med *= (1/8) big_med *= (1/48) antia *= (1/104) big_antia *= (1/np.sum(big_antia)) 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) cvutil.comp_images(sharp_image.astype(np.uint8), blur_image.astype(np.uint8)) result1 = dset[1] - blur_image result1[result1 < -3] = 0 result1[result1 > 3] = 0 result1[result1 != 0] = 255 mask = (result1[...,0] == 0) & (result1[...,1] == 0) & (result1[...,2] == 0) mask = np.invert(mask) result1[mask] = 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 cvutil.comp_images(result1.astype(np.uint8), result2.astype(np.uint8))