effective javaを読んだ時のメモ
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import numpy as np | |
| import imageio | |
| class Video: | |
| def __init__(self, path, mask_path): | |
| reader = imageio.get_reader(path) | |
| meta_data = reader.get_meta_data() | |
| self.width, self.height = meta_data['size'] | |
| self.frame = meta_data['nframes'] | |
| self.fps = meta_data['fps'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import cv2 | |
| import numpy as np | |
| from PIL import Image | |
| def get_movie(path): | |
| cap = cv2.VideoCapture(path) | |
| imgs = [] | |
| while(True): | |
| ret, frame = cap.read() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def conver_n_bit(img, n=1): | |
| count = 2**n | |
| extents = np.linspace(0, 255, num=count+1, dtype=int) | |
| pixels = np.linspace(0, 255, num=count, dtype=int) | |
| output = np.zeros(img.shape, dtype=int) | |
| for i in range(count): | |
| pixel = pixels[i] | |
| bool_arr = (extents[i] <= img) & (img < extents[i+1]) | |
| output += bool_arr * pixel |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def main(): | |
| rootfolder = Folder('root') | |
| binfolder = Folder('bin') | |
| rootfolder.add(binfolder) | |
| binfolder.add(File('vi', 10000)) | |
| binfolder.add(File('latex', 20000)) | |
| rootfolder.accept(ListVistor()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABCMeta, abstractmethod | |
| def main(): | |
| try: | |
| print('Making root entries') | |
| rootfolder = Folder('root') | |
| binfolder = Folder('bin') | |
| tmpfolder = Folder('tmp') | |
| usrfolder = Folder('usr') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from abc import ABCMeta, abstractmethod | |
| def main(): | |
| try: | |
| print('Making root entries') | |
| rootfolder = Folder('root') | |
| binfolder = Folder('bin') | |
| tmpfolder = Folder('tmp') | |
| usrfolder = Folder('usr') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ListVistor(Vistor): | |
| def __init__(self): | |
| self.currentfolder = '' | |
| def visit(self, file=None, folder=None): | |
| if file is not None: | |
| print('{}/{}'.format(self.currentfolder, file)) | |
| return | |
| elif folder is not None: | |
| print('{}/{}'.format(self.currentfolder, folder)) |
NewerOlder