def __init__(self, path): self.helpers = Helpers() # Image helpers if (path == 'error1'): self.errorimg = self.loadImage('input.jpeg') W = self.errorimg.shape[0] H = self.errorimg.shape[1] cv2.putText(self.errorimg, "Grid not Detected", (0, int(H / 2)), cv2.FONT_HERSHEY_SIMPLEX, int(1 * (W / 400)), (0, 0, 255), 3) self.helpers.show(self.errorimg, 'Final Sudoku grid') return if (path == 'error2'): self.errorimg = self.loadImage('input.jpeg') W = self.errorimg.shape[0] H = self.errorimg.shape[1] cv2.putText(self.errorimg, "Could not Solve", (0, int(H / 2)), cv2.FONT_HERSHEY_SIMPLEX, int(1 * (W / 400)), (0, 0, 255), 3) self.helpers.show(self.errorimg, 'Final Sudoku grid') return self.image = self.loadImage(path) self.preprocess() #self.helpers.show(self.image, 'After Preprocessing') self.sudoku = self.cropSudoku() #self.helpers.show(sudoku, 'After Cropping out grid') self.sudoku = self.straighten(self.sudoku) #self.helpers.show(self.sudoku, 'Final Sudoku grid') self.digits = Cells(self.sudoku).cells
def __init__(self, path): self.tools = Tools() self.image = self.loadImage(path) self.preprocess() sudoku_image = self.cropSudoku() sudoku_image = self.strengthen(sudoku_image) self.cells = Cells(sudoku_image).cells
def __init__(self, path): self.helpers = Helpers() # Image helpers self.image = self.loadImage(path) self.preprocess() sudoku = self.cropSudoku() sudoku = self.straighten(sudoku) self.cells = Cells(sudoku).cells
def __init__(self, path): self.helpers = Helpers() # Image helpers self.image = self.loadImage(path) self.preprocess() #self.helpers.show(self.image, 'After Preprocessing') sudoku = self.cropSudoku() self.helpers.show(sudoku, 'After Cropping out grid') sudoku = self.straighten(sudoku) #self.helpers.show(sudoku, 'Final Sudoku grid') self.cells = Cells(sudoku).cells
def __init__(self): # Initialise PyGame. pygame.init() # Set up the clock. This will tick every frame and thus maintain a relatively constant framerate. Hopefully. self.fpsClock = pygame.time.Clock() # Set up the window. self.width, self.height = 640, 640 self.screen = pygame.display.set_mode((self.width, self.height)) initial_state = [[0 for j in range(32)] for i in range(32)] self.cells = Cells(initial_state) self.paused = False
def read_data(folder, fname): """ read simulation data through hdf5 file""" ### access the file fpath = folder + fname assert os.path.exists(fpath), "out_fil.h5 does NOT exist for " + fpath fl = h5py.File(fpath, 'r') ### read in the positions of filaments xi = np.array(fl['/positions/xi'], dtype=np.float32) # center of mass of MT ori = np.array(fl['/positions/ori'], dtype=np.float32) # <orientation> of MT ### read in the box info lx = fl['/info/box/x'][...] ly = fl['/info/box/y'][...] ### read in the general simulation info dt = fl['/info/dt'][...] nsteps = fl['/info/nsteps'][...] nbeads = fl['/info/nbeads'][...] nsamp = fl['/info/nsamp'][...] ### read in the filament information nfils = fl['/info/nfils'][...] nbpf = fl['/info/nbpf'][...] ### read in the simulation parameters density = fl['/param/density'][...] kappa = fl['/param/kappa'][...] km = fl['/param/km'][...] pa = fl['/param/pa'][...] bl = fl['/param/bl'][...] sigma = fl['/param/sigma'][...] ### close the file fl.close() sim = Simulation(lx, ly, dt, nsteps, nbeads, nsamp, nfils, nbpf, density, kappa, km, pa, bl, sigma) fils = Cells(xi, ori, sim) return fils, sim
def main(image_path): # get the final worksheet from the image ext = Extractor(image_path, False) final = ext.final # get the form code by checking the image's QR code decoded_qr_code = reader(final) # extract the cells and student's responses cells = Cells(final) # grade the worksheet by using a CNN to OCR the student's responses grader = Grader(decoded_qr_code) grader.grade(cells.student_responses) worksheet = grader.display(final, cells.sorted_contours) Helpers.save_image(f'{Helpers.IMAGE_DIRECTORY}/graded.png', worksheet)
def __init__(self, window, x, y, width, height, name="Game", background=(224, 224, 224)): self.name = name self.position = vector(x, y) self.window = window self.width = width self.height = height self.screen = pygame.Surface((self.width, self.height)) self.grid = [[Cells(self.screen, x, y, 30, 30) for x in range(16)] for y in range(25)] self.background = background self.rect = self.screen.get_rect()
B = Biomes() BLOBS = Blobs() CONFIG = Configuration(B, BLOBS) P = Player(Vec2(82, 16).mul(32)) CAM = Camera(P.pos.sub(Vec2(64, 64 + 128))) CLOUDS = Clouds() TREES = Trees(CONFIG) BUSHES = Bushes(CONFIG) BUILDINGS = Buildings(CONFIG) M = MapFormat(CreateRandomWorld()) P.pos.y -= 128 CELLS = Cells(flr(CAM.pos.x / CELL_SIZE), flr(CAM.pos.y / CELL_SIZE), M.mapdata, CONFIG) def _init(): print("CAMERA", CAM.pos.x, CAM.pos.y) palt(0, False) palt(14, True) def _update(): global PERSPECTIVE_OFFSET P.update() PERSPECTIVE_OFFSET = Vec2(64 + sin(px8_time() / 9) * 4, 80 + sin(px8_time() / 11) * 4)
def test_maze_grid(): cells = Cells(constants.FILENAME) maze = MazeGrid(cells)
def cli(rbc, plt, verbose, output, axes, bounding_box, clip, stl): """Convert and visualise cell position files used in HemoCell [0]. The script reads from any number of red blood cell position files (RBC.pos) and allows for direct visualisation with PyVista [1] or conversion to XDMF for inspection with Paraview through `-o, --output`. The RBC positions can be provided through `stdin` by specifying a dash (`-`) as argument and piping the input, e.g. `cat RBC.pos | pos_to_vtk -`. Optionally, any number of platelets position files (PLT.pos) can be supplied by the `--plt` argument, which might be repeated any number of times to specify multiple PLT.pos files. [0] https://hemocell.eu [1] https://dev.pyvista.org/index.html """ if len(rbc) == 0 and len(plt) == 0: message = """No input files provided. When passing an RBC through `stdin`, please provide a dash (`-`) as the argument.""" raise click.UsageError(message) if (bounding_box is not None) and (stl is not None): message = """Options `--bounding-box` and `--stl` are exclusive and cannot be combined. Please provide only one.""" raise click.UsageError(message) rbcs = Cells(flatten([Cells.from_pos(rbc) for rbc in rbc])) plts = Cells(flatten([Cells.from_pos(plt) for plt in plt])) if len(rbcs) == 0: # The script terminates early when no RBCs are present. This # most-likely corresponds with users error, e.g. by providing the wrong # file path or an empty file. raise click.UsageError("No RBC cells to display." "") if bounding_box: bounds = flatten(zip((0, 0, 0), bounding_box)) wireframe = pv.Box(bounds) if stl: wireframe = pv.get_reader(stl).read() wireframe.scale((1e3, 1e3, 1e3)) if clip: rbcs = rbcs.clip(wireframe, bounding_box) plts = plts.clip(wireframe, bounding_box) if len(rbcs) == 0 and len(plts) == 0: raise click.UsageError("No cells remain after clipping.") if output: rbcs = create_glyphs(rbcs, CellType.RBC) merged_cells = rbcs.merge(plts) if plt else rbcs pv.save_meshio(output, merged_cells) if verbose: click.echo(f"Written to: '{click.format_filename(output)}'") return 0 plotter = pv.Plotter() rbcs_glyph = create_glyphs(rbcs, CellType.RBC) rbcs_actor = plotter.add_mesh(rbcs_glyph, color="red") if plt: plts_glyph = create_glyphs(plts, CellType.PLT) plts_actor = plotter.add_mesh(plts_glyph, color="yellow") if bounding_box or stl: plotter.add_mesh(wireframe, style='wireframe') message = f'RBC: {len(rbcs)}\nPLT: {len(plts)}\n' if clip: # Only when the domain is clipped, a bounding domain is known either # through the given bounding box or by the given STL surface mesh. # These allow to determine an estimate of the domain's volume and # thereby estimate the expected hematocrit given the number of RBCs # left after clipping. volume = 1e-6 * wireframe.volume hc_percentage = 100 * rbcs.hematocrit(wireframe) message += f'Domain volume estimate (µm^3): {volume:.2f}\n' message += f'Hematocrit (vol%): {hc_percentage:.2f}\n' plotter.add_text(message, position='lower_right') # A simple widget illustrating the x-y-z axes orientation of the domain. if axes: plotter.add_axes(line_width=5, labels_off=False) # Two radio buttons are added that enable to show/hide the glyphs # corresponding to all RBCs or PLTs, where the lambda functions are given # to implement the callback function toggling the right set of glyphs. plotter.add_checkbox_button_widget(lambda x: rbcs_actor.SetVisibility(x), position=(5, 12), color_on="red", value=True) plotter.add_checkbox_button_widget(lambda x: plts_actor.SetVisibility(x), position=(5, 62), color_on="yellow", value=True) return plotter.show()