def __init__(self, dst_hero, last_hero): self.x, self.y = random.randint(0 + 50, 800 - 50), 400 self.draw_scale_x, self.draw_scale_y = enemy.size, enemy.size + 150 self.frame = 0 self.hit_frame = 0 self.lev = random.randint(1, 3) self.damage = 5 * self.lev self.hp = enemy.max_hp * self.lev #상태 관련 변수 self.state = enemy.state_appear self.do_not_change_frame = False self.do_not_change_hit_frame = False self.state_begin_stand_time = 0 self.state_changed_time = 0 self.state_elapsed_time = 0 self.time_storage = 0 self.from_attack = False self.look = False self.del_sign = False self.depress = True self.change_pics = False #약화 상태 변수 self.depress_obj = [] #공격 관련 변수 self.attack_time = random.uniform(0.1, 2) self.attack_object = [] self.dst_attack = dst_hero self.last_dst_attack = last_hero #이동 관련 변수 self.move_time = random.uniform(0.1, 0.5) self.stand_time = random.uniform(1, 2) self.go_R = False self.go_L = False self.speed = random.randint(5, 10) self.max_speed = self.speed #히트박스 self.head_box = rectangle.rectangle(self.x, self.y + 4, 16, 16) self.body_box = rectangle.rectangle(self.x, self.y - 10, 10, 4) self.legs_box = rectangle.rectangle(self.x, self.y - 20, 2, 4) self.hit_num = -1 self.skill_hit_num = -1 self.knock_back_range = 5 if len(enemy.image) is 0: enemy.image += [load_image('../Pics/enemy_level1.png')] enemy.image += [load_image('../Pics/enemy_level2.png')] enemy.image += [load_image('../Pics/enemy_level3.png')] enemy.Rimage += [load_image('../R_Pics/enemy_level1.png')] enemy.Rimage += [load_image('../R_Pics/enemy_level2.png')] enemy.Rimage += [load_image('../R_Pics/enemy_level3.png')] if len(enemy.sound) is 0: enemy.sound += [load_music('../sounds/level1_dead.mp3')] enemy.sound += [load_music('../sounds/level2_dead.mp3')] enemy.sound += [load_music('../sounds/level3_dead.mp3')] if enemy.hit_effect is None: enemy.hit_effect = load_image('../Pics/hit_effect.png') enemy.Rhit_effect = load_image('../R_Pics/hit_effect.png') if enemy.depress_effect is None: enemy.depress_effect = load_image('../Pics/weak_icon.png') enemy.Rdepress_effect = load_image('../R_Pics/weak_icon.png')
def main(): rect1 = rectangle(4, 40) print("The area of a rectangle with the width of", rect1.getWidth(), "and height of", rect1.getHeight(), "is", rect1.getArea(), "and the perimeter is", rect1.getPerimeter()) rect2 = rectangle(3.5, 35.7) print("The area of a rectangle with the width of", rect2.getWidth(), "and height of", rect2.getHeight(), "is", rect2.getArea(), "and the perieter is", rect2.getPerimeter())
def update(self, e): if self.dist == 0: self.check_hit_attack_with_hero(e) return self.frame = (self.frame + 1) % 5 self.x += self.dif_x * self.speed / self.dist self.y += self.dif_y * self.speed / self.dist self.hit_box = rectangle.rectangle(self.x, self.y, 19 * 3 / 2, 10 * 3 / 2) self.body_box = rectangle.rectangle(self.x, self.y, 50 * 3 / 2, 50 * 3 / 2) if self.x > 800 - 25 or self.x < 0 + 25: self.del_sign = True if self.y > 600 - 25 or self.y < e.y - 25: self.del_sign = True self.check_hit_attack_with_hero(e)
def porte(x,y,couleur): ''' Paramètres : x est l'abcisse du centre de la porte y est l'ordonnée du sol du niveau de la porte couleur : couleur de la porte remarque: Cette fonction dessine une porte de 30 pixels de large pour 50 pixels de hauteur ''' turtle.fillcolor(couleur) turtle.penup() turtle.begin_fill() rectangle(x,y,30,50) turtle.pendown() turtle.end_fill()
def __init__(self, og_x, og_y, lev, dst_hero, last_dst_hero, cp): self.x, self.y = og_x, og_y self.level = lev self.life = lev self.speed = 10 self.frame = 0 self.attack_num = -1 self.dst_attack = dst_hero self.last_dst_attack = last_dst_hero if self.dst_attack.x < self.x: self.opposite = True else: self.opposite = False self.del_sign = False self.dif_x = self.dst_attack.x - self.x self.dif_y = self.dst_attack.y - self.y self.dist = math.sqrt(self.dif_x**2 + self.dif_y**2) self.degree = math.atan2(self.dif_y, self.dif_x) self.hit_box = rectangle.rectangle(self.x, self.y, 19 * 3 / 2, 10 * 3 / 2) self.change_pics = cp if len(arrow.image) is 0: arrow.image += [load_image('../Pics/enemy1_attack.png')] arrow.image += [load_image('../Pics/enemy2_attack.png')] arrow.image += [load_image('../Pics/enemy3_attack.png')] arrow.Rimage += [load_image('../R_Pics/enemy1_attack.png')] arrow.Rimage += [load_image('../R_Pics/enemy2_attack.png')]
def extractPicasa(cv_path): picasaMetadata = pfr.Imagedata(cv_path) xmpFaces = pfr.XMPFace(picasaMetadata).getFaces() # print(xmpFaces) faceList = [] for faces in xmpFaces: personName = faces[4] left = faces[0] top = faces[1] width = faces[2] height = faces[3] locRect = rectangle(height, width, leftEdge = left, topEdge = top) face = face_rect.FaceRect(locRect, encoding=None, name=personName) faceList.append(face) # print( len(faceList) ) return faceList
def test_rectangle_linear(): """Check that linear functions are integrated exactly (with midpoint) or with a known correctable error (left and right)""" method = ['left', 'mid', 'right'] f = lambda x: 6 * x - 4 slope = 6 F = lambda x: 3 * x**2 - 4 * x # Anti-derivative # From the slope of f (i.e. 6), we know that left will # under-estimate the inegral by C (given below), while # right will over-estimate by C a = 1.2 b = 4.4 exact = F(b) - F(a) #tol = 1E-14 tol = 1E-13 # Slightly relaxed compared to previously for n in 2, 20, 21: h = float(b - a) / n C = n * (0.5 * slope * h**2) # Correction term for left/right for i in range(len(method)): numerical = rectangle(f, a, b, n, method[i]) if (method[i] == 'left'): numerical += C elif (method[i] == 'right'): numerical -= C err = abs(exact - numerical) assert err < tol, 'n = %d, err = %g' % (n, err)
def test(): for i in range(0, 5): scramble() solve() box = rectangle(surface, white, 180, 480, 40, 40) box.draw() display_text(surface, black, 200, 500, 30, str((i + 1)))
def __init__(self, color, x, y, radius, hitbox, sx, sy): super().__init__(color, x, y) self.radius = radius self.sx = sx self.sy = sy self.hitbox = rectangle((0, 0, 100), self.x - self.radius, self.y - self.radius, self.radius * 2, self.radius * 2, self.sx)
def facade(x, y_sol, couleur, niveau): ''' Paramètres : x : abcisse du centre de la façade y_sol : ordonnée du sol du la rue couleur : couleur de la façade niveau : num du niveau (0 pour les rdc, ...) remarque : Facade dessine une facade sans les élements interieurs ''' h = 60 turtle.colormode(255) turtle.color(couleur) if niveau == 0: turtle.up() turtle.goto(x, y_sol) turtle.pendown() turtle.begin_fill() rectangle(x, y_sol, 140, h) if niveau == 1: turtle.up() turtle.goto(x, y_sol + h) turtle.pendown() turtle.begin_fill() rectangle(x, y_sol + h, 140, h) if niveau == 2: turtle.up() turtle.goto(x, y_sol + h * 2) turtle.pendown() turtle.begin_fill() rectangle(x, y_sol + h * 2, 140, h) if niveau == 3: turtle.up() turtle.goto(x, y_sol + h * 3) turtle.pendown() turtle.begin_fill() rectangle(x, y_sol + h * 3, 140, h) if niveau == 4: turtle.up() turtle.goto(x, y_sol + h * 4) turtle.pendown() turtle.begin_fill() rectangle(x, y_sol + h * 4, 140, h) turtle.end_fill()
def preprocess(lines: list): '''텍스트 파일로부터 정보를 받아 frameData 리스트를 반환한다.''' frames = [] delimiter = re.compile(r"\d+") frames.append(frameInfo()) for line in lines: if line == '\n' or delimiter.match(line): frames.append(frameInfo()) else: frames[-1].append(rectangle(line)) return [frame for frame in frames if frame]
def fenetre_balcon(x, y): ''' Paramètres : x est l'abcisse du centre de la porte-fenetre-balcon y est l'ordonnée du sol du niveau de la porte-fenetre-balcon Remarque: Dessine une porte-fenetre avec balcon en 2 temps: la porte fenetre de 30 pixels de large par 50 pixels de hauteur puis le balcon ''' #fenetre turtle.colormode(255) turtle.fillcolor(couleur_aleatoire()) turtle.begin_fill() rectangle(x, y, 30, 50) turtle.end_fill() # balcon turtle.pencolor('black') for i in range(10): rectangle(x + (3 * i) - 15, y, 3, 20) turtle.up() turtle.goto(x, y) turtle.down()
def test_rectangle_one_exact_result(): """Compare one hand-computed result.""" from math import exp v = lambda t: 3 * (t**2) * exp(t**3) method = ['left', 'mid', 'right'] n = 2 exact = [0.4249306699000599, 1.3817914596908085, \ 4.5023534125886275] tol = 1E-14 for i in range(len(method)): numerical = rectangle(v, 0, 1, n, method[i]) err = abs(exact[i] - numerical) assert err < tol, err
def init_hit_boxes(self): if self.look is False: self.body_box = rectangle.rectangle(self.x, self.y - 10, 14, 10) self.common_attack_box1 = rectangle.rectangle(self.x + hero.h_size//2, self.y, hero.h_size//2 + self.extra_hit_size_x//2, hero.h_size*4//5 + self.extra_hit_size_y//2) self.common_attack_box2 = rectangle.rectangle(self.x + hero.h_size*2//5, self.y - hero.h_size//2, hero.h_size*2//5 + self.extra_hit_size_x//2, hero.h_size*2//5 + self.extra_hit_size_y//2) else: self.body_box = rectangle.rectangle(self.x, self.y - 10, 14, 10) self.common_attack_box1 = rectangle.rectangle(self.x - hero.h_size//2, self.y, hero.h_size//2 + self.extra_hit_size_x//2, hero.h_size*4//5 + self.extra_hit_size_y//2) self.common_attack_box2 = rectangle.rectangle(self.x - hero.h_size*2//5, self.y - hero.h_size//2, hero.h_size*2//5 + self.extra_hit_size_x//2, hero.h_size*2//5 + self.extra_hit_size_y//2)
def grid_par_comp(A, eps, m): (max_r, min_r, max_i, min_i) = rectangle(A, eps) p = np.zeros((m, m)) n, r = np.shape(A) E = np.ones((n, n)) x = np.linspace(min_r, max_r, m) y = np.linspace(min_i, max_i, m) for k in range(m): for j in range(m): X = abs(np.linalg.inv(A - ((x[k] + y[j] * 1j) * np.eye(n)))) Y = np.dot(X, E) s, v = np.linalg.eig(Y) p[j, k] = max(abs(s)) plt.contour(x, y, p, [eps]) plt.show()
def convergence_rates(f, F, a, b, height, num_experiments=14): from math import log from numpy import zeros exact = F(b) - F(a) n = zeros(num_experiments, dtype=int) E = zeros(num_experiments) r = zeros(num_experiments - 1) for i in range(num_experiments): n[i] = 2**(i + 1) numerical = rectangle(f, a, b, n[i], height) E[i] = abs(exact - numerical) if i > 0: r_im1 = log(E[i] / E[i - 1]) / log(float(n[i]) / n[i - 1]) r[i - 1] = float('%.2f' % r_im1) # Truncate to two decimals return r
def merge_with(self, face, np_image): if self.detection_level < face.detection_level: encoding = self.encoding elif face.detection_level < self.detection_level: encoding = face.encoding else: # Not sure this is best idea... if self.rectangle.area > face.rectangle.area: encoding = self.encoding else: encoding = face.encoding if self.name == face.name: newname = self.name elif self.name == None: newname = face.name else: newname = self.name detection_level = min(self.detection_level, face.detection_level) new_rect_top = min(self.rectangle.top, face.rectangle.top) new_rect_bottom = max(self.rectangle.bottom, face.rectangle.bottom) new_rect_left = min(self.rectangle.left, face.rectangle.left) new_rect_right = max(self.rectangle.right, face.rectangle.right) new_width = abs(new_rect_left - new_rect_right) new_height = abs(new_rect_top - new_rect_bottom) # print(new_rect_left, self.rectangle.left, face.rectangle.left) # print(new_rect_right, self.rectangle.right, face.rectangle.right) new_rect = rectangle(new_height, new_width, leftEdge=new_rect_left, topEdge=new_rect_top) face_image = np_image[new_rect_top:new_rect_bottom, new_rect_left:new_rect_right] merge_rect = FaceRect(rectangle=new_rect, face_image=face_image, detection_level=detection_level, encoding=encoding, name=newname) return merge_rect
def grid_rect(A,eps,m): (max_r,min_r,max_i,min_i) = rectangle(A,eps) """ sigmin = np.zeros((m,m)) n,r = np.shape(A) x = np.linspace(min_r,max_r,m) y = np.linspace(min_i,max_i,m) for k in range(m): for j in range(m): u,s,v = np.linalg.svd(complex(x[k],y[j])*np.eye(n)-A) sigmin[j,k] = s[-1] """ sigmin = pymp.shared.array((m,m)) n,r = np.shape(A) x = np.linspace(min_r,max_r,m) y = np.linspace(min_i,max_i,m) with pymp.Parallel(4) as p: for k in p.range(m): for j in range(m): u,s,v = np.linalg.svd(complex(x[k],y[j])*np.eye(n)-A) sigmin[j,k] = s[-1] #plt.contour(x,y,sigmin,[eps]) #plt.show() return x,y,sigmin
import turtle from rectangle import rectangle if __name__ == '__main__': for i in range(10): rectangle(10 + i * 10) while True: pass
steps = calc_steps(DEPTH, -mat['pass_depth']) run_3_stages_abs(path, g, steps) if top == 1: g.move(z=2) g.move(y=0) g.move(z=0) hole(g, mat, DEPTH, d=19.0, offset="inside", fill=False) g.move(z=0) rectangleTool(g, mat, DEPTH, 19.0 - mat['tool_size'], -CUTY0, 0, "top", "center") else: g.move(z=2) g.move(x=0, y=0) g.move(z=0) hole(g, mat, DEPTH, d=4.2, offset="inside") g.move(z=2) g.move(y=CUTY0) g.move(z=0) rectangle(g, mat, END_DEPTH, 32.0, 0.0, 0.0, "bottom") g.move(z=2) g.move(y=CUTY1) g.move(z=0) rectangle(g, mat, END_DEPTH, 32.0, 0.0, 0.0, "bottom") g.move(z=15) g.spindle()
def __init__(self, px=400, py=225 + h_size//2, pstate=h_stand, curhp=100, jmp=False, ascnd=True, attck_effect=False,\ attck_type=random.randint(0,1), attck_frame=0, gol=False, gor=False, look=False, size_attack_x=0, size_attack_y=0, eat=False, mh=0, cht=0, chp=False): self.x, self.y = px, py self.frame = 0 self.state = pstate self.damage = 5 self.extra_damage = 0 self.hp = curhp self.overwhelming = False #무적 self.del_time = 0 self.ate_depress = eat self.ate_begin_time = 0 #점프 관련 변수 self.jump = jmp self.maxheight = mh self.quake_body = 0 self.quake_right = False self.ascend = ascnd self.jump_ready_time = 0 self.stand_begin_time = time.time() self.va_speed = 0 self.va_a = 0 #공격 관련 변수 self.attack_effect = attck_effect self.attack_type = attck_type self.attack_frame = attck_frame self.attack_num = 0 self.extra_hit_size_x, self.extra_hit_size_y = size_attack_x, size_attack_y self.extra_hit_time = cht self.change_pics = chp #이동 관련 변수 self.go_L = gol self.go_R = gor self.look = look self.dashing = False self.dash_dist = 0 self.dash_dir = 0 self.del_sign = False #히트박스 self.body_box = rectangle.rectangle(self.x, self.y-10, 14, 10) self.common_attack_box1 = rectangle.rectangle(self.x + 17, self.y - 11, 17, 33) self.common_attack_box2 = rectangle.rectangle(self.x + 4, self.y - 19, 35, 19) self.hit = [] if hero.h_image is None: hero.h_image = load_image('../Pics/hero.png') hero.Rh_image = load_image('../R_Pics/hero.png') if hero.attack_image is None: hero.attack_image = load_image('../Pics/attack_effect.png') hero.Rattack_image = load_image('../R_Pics/attack_effect.png') if hero.hp_image is None: hero.hp_image = load_image('../Pics/hp_bar.png') hero.Rhp_image = load_image('../R_Pics/hp_bar.png') if hero.blur_image is None: hero.blur_image = load_image('../Pics/for_blur.png') hero.Rblur_image = load_image('../R_Pics/for_blur.png') if hero.hit_image is None: hero.hit_image = load_image('../Pics/hero_hit.png') hero.Rhit_image = load_image('../R_Pics/hero_hit.png') if hero.sound_attack is None: hero.sound_attack = load_music('../sounds/sword_swing_short.mp3') hero.sound_attack.set_volume(50)
test_button = button(surface, gray, 825, 200, 75, 30, 'Test', white, 20) # event loop while True: # events in for loop for event in pygame.event.get(): # check if user has quit the game if event.type == pygame.QUIT: pygame.quit() sys.exit() # check if mouse is clicked if event.type == pygame.MOUSEBUTTONDOWN: (mouse_x, mouse_y) = pygame.mouse.get_pos() mouse = rectangle(surface, black, mouse_x, mouse_y, 1, 1) # checks if a square is clicked for s in range(0, 6): for i in range(0, 3): for j in range(0, 3): if mouse.intersects(graphics_cube[s][i][j]): graphics_cube[s][i][j].color_increment() break # checks for buttons if mouse.intersects(start_button): solving = True elif mouse.intersects(scramble_button): if not (solving): scramble()
user_input = input('''для вычисления площади квадрата введите: 1 для вычисления площади прямугольника введите: 2 для вычисления площади параллелограмма введите: 3 для перевода градусов в радианы введите: 4 для перевода радиан в градусы введите: 5 для определения високосного года введите: 6 для вычисления корней квадратного уравнения введите: 7 : ''') if user_input == '1': user_input = input('введите сторону квадрата для вычисления площади: ') print("площадь квадрата = ", square.square(user_input)) if user_input == '2': user_input1 = input('введите первую сторону прямоугольника: ') user_input2 = input('введите вторую сторону прямоугольника: ') print("площадь прямоугольника = ", rectangle.rectangle(user_input1, user_input2)) if user_input == "3": user_input1 = input('введите длину основания параллелограмма: ') user_input2 = input('введите высоту параллелограмма: ') print("площадь параллелограмма равна: ", parallelogram.parallelogram(user_input1, user_input2)) if user_input == "4": user_input = input('введите угол для перевода в радианы: ') print('угол равняется ', degree.degree_to_radian(user_input), "радиан") if user_input == "5": user_input = input('введите радианы для перевода в градусы: ') print('угол равняется ', radian.radian_to_degree(user_input), "градусов") if user_input == "6": user_input = int(input('введите год: ')) print('год', year.year(user_input))
print_lines=False) g.absolute() g.feed(mat['feed_rate']) g.move(z=CNC_TRAVEL_Z) g.spindle('CW', mat['spindle_speed']) # Drill holes for the tactile switch. holes = [[15.25, 14.75], [19.85, 14.75], [15.25, 8.26], [19.85, 8.26]] for h in holes: g.move(x=h[0], y=h[1]) drill(g, mat, cut_depth) # Mounting holes. mount = [[2.54, 3.175], [22.225, 3.175], [2.54, 19.685], [22.225, 19.685]] for m in mount: g.move(x=m[0], y=m[1]) hole(g, mat, cut_depth, 2.1 / 2) # Power port. g.move(x=7.62, y=11.43) hole(g, mat, cut_depth, 8.1 / 2) # Board outline. g.move(x=-half_tool, y=-half_tool) g.move(z=0) rectangle(g, mat, cut_depth, 24.76 + tool_size, 22.86 + tool_size) g.move(z=CNC_TRAVEL_Z) g.spindle()
W = 15 H = 8.5 Y2 = -8.4 - H mat = init_material("np883-aluminum-3.175") HALFTOOL = TOOLSIZE / 2 g = G(outfile='path.nc', aerotech_include=False, header=None, footer=None, print_lines=False) g.absolute() g.feed(mat['travel_feed']) g.move(z=CNC_TRAVEL_Z) g.move(y=Y0) g.spindle('CW', mat['spindle_speed']) hole(g, mat, -10, D0 / 2) g.move(y=Y1) hole(g, mat, -10, D1 / 2) g.move(x=-W / 2 + HALFTOOL, y=Y2 + HALFTOOL) g.move(z=0) rectangle(g, mat, -8, W - TOOLSIZE, H - TOOLSIZE) g.move(z=CNC_TRAVEL_Z) g.spindle() g.move(x=0, y=0)
func2(L) except ValueError: print('неверный формат строки') L = 0 if (WhatTheFigure == 3): L0 = 0 L1 = 0 while L0 <= 0: try: L0 = change("Введите длину 1 стороны прямоугльника: ") func3 = lambda L0: print("Длина стороны должна быть больше 0" ) if L0 <= 0 else print("") func3(L0) except ValueError: print('неверный формат строки') L0 = 0 while L1 <= 0: try: L1 = change("Введите дину второй стороны прямоугольника: ") func4 = lambda L1: print("Площадь прямоугльника равна " + str( rectangle.rectangle(L0, L1).reckon() )) if L1 > 0 else print("Длина стороны должна быть больше 0") func4(L1) except ValueError: print('неверный формат строки') L1 = 0 if (WhatTheFigure == 0): flag = False
def detect_pyramid(cv_image, parameters): assert isinstance(cv_image, np.ndarray) assert 'upsample' in parameters.keys() assert 'height' in parameters.keys() assert 'width' in parameters.keys() start_time = time.time() max_pixels_per_chip = int(parameters['height']) * int(parameters['width']) num_upsamples = int(parameters['upsample']) height = cv_image.shape[0] width = cv_image.shape[1] num_pixels = height * width num_chips = float(num_pixels / max_pixels_per_chip) num_iters = np.sqrt(num_chips) # First, we can resize the whole thing to the number of pixels # represented by the height and width parameters. This should # make it possible to fit in the GPU and we can get the biggest, # hardest-to-miss faces. num_faces = 0 faceList = [] pct_exp = 0.06 # Cut the image in a 3x3 grid, using split_range. Then we will # expand these even cuts slightly on top of each other to catch # faces that are on the border between the grids. for cuts in [1, 3]: # Get lists of left/right and top/bottom indices. width_parts = split_range(width, cuts) height_parts = split_range(height, cuts) # Expansion of the borders by a few percent. width_x_percent = int(pct_exp * width / cuts ) height_x_percent = int(pct_exp * height / cuts ) for leftIdx in range(len(width_parts) - 1): for topIdx in range(len(height_parts) - 1): # Get the top/bottom, left/right of each # grid. left_edge_0 = width_parts[leftIdx] right_edge_0 = width_parts[leftIdx + 1] top_edge_0 = height_parts[topIdx] bottom_edge_0 = height_parts[topIdx + 1] # Since the faces may be split on an edge, # put in a 3% overlap between tiles. # if left_edge > 0: left_edge = max(0, left_edge_0 - width_x_percent) # if top_edge > 0: # top_edge -= height_x_percent top_edge = max(0, top_edge_0 - height_x_percent) # if right_edge < width: # right_edge += width_x_percent right_edge = min(width, right_edge_0 + width_x_percent) # if bottom_edge < height: # bottom_edge += height_x_percent bottom_edge = min(height, bottom_edge_0 + height_x_percent) assert left_edge < right_edge assert top_edge < bottom_edge assert (bottom_edge - top_edge) <= int((bottom_edge_0 - top_edge_0) * (1 + pct_exp * 2) + 1) assert (right_edge - left_edge) <= int((right_edge_0 - left_edge_0) * (1 + pct_exp * 2) + 1) # Cut out the chip. chip_part = cv_image[top_edge:bottom_edge, left_edge:right_edge] # Then resize it to fit in the GPU memory, based # on the parameters passed to the function. height_chip = chip_part.shape[0] width_chip = chip_part.shape[1] pixels_here = height_chip * width_chip resize_ratio = np.sqrt(float(pixels_here) / max_pixels_per_chip) resized_chip = cv2.resize(chip_part, \ ( int( width_chip / resize_ratio ), \ int( height_chip / resize_ratio ) ) ) # print(resized_chip.shape) face_locations = face_recognition.face_locations(resized_chip, \ number_of_times_to_upsample=num_upsamples, model='cnn') # print(face_locations) # print("ID len: " + str(len(identity))) # assert len(identity) == len(face_locations), 'Identity vector length != face location vector length.' num_faces += len(face_locations) # print( num_faces ) for index in range(len(face_locations)): # Get the locations of the face from the # small, resized chip. These indices will # need to be scaled back up for proper # identification. top_chip, right_chip, bottom_chip, left_chip = face_locations[index] # encoding = identity[index] # height_face = abs(top_chip - bottom_chip) # width_face = abs(left_chip - right_chip) # rect = rectangle(height=height_face, width=width_face, leftEdge = left_chip, topEdge = top_chip) # # Upsize the rectangle as appropriate # rect.resize(resize_ratio) # While our rectangle class does have a # resize method, it wouldn't appropriately # account for the shift on sub-images. # So we need to build our own. top_scaled = int(top_chip * resize_ratio + top_edge) bottom_scaled = int(bottom_chip * resize_ratio + top_edge) left_scaled = int(left_chip * resize_ratio + left_edge) right_scaled = int(right_chip * resize_ratio + left_edge) height_face = int(np.abs(bottom_scaled - top_scaled)) width_face = int(np.abs(right_scaled - left_scaled)) face_loc_rescaled = [(top_scaled, right_scaled, bottom_scaled, left_scaled)] # Get the encoding on the upscaled image # using the face bounding boxes that are # upsampled. encoding = face_recognition.face_encodings(cv_image, known_face_locations=face_loc_rescaled, num_jitters=10) assert len(encoding) == 1 encoding = encoding[0] # print(encoding) # Draw a rectangle on the image? # cv2.rectangle(cv_image, (left_scaled, top_scaled), (right_scaled, bottom_scaled), (0, 255, 0), 5) # pil_image = Image.fromarray(face_image) # pil_image.show() face_img = cv_image[top_scaled:bottom_scaled, left_scaled:right_scaled] face_loc_rect = rectangle(height_face, width_face, leftEdge = left_scaled, topEdge = top_scaled) face = face_rect.FaceRect(rectangle = face_loc_rect, face_image = face_img, encoding = encoding, name=None, detection_level = cuts) faceList.append(face) elapsed_time = time.time() - start_time print("Elapsed time is : " + str( elapsed_time ) ) for eachFace in list(set(faceList)): pass r = eachFace.rectangle left = r.left right = r.right top = r.top bottom = r.bottom cv2.rectangle(cv_image, (left, top), (right, bottom), (255, 0, 0), 5) # Convert to OpenCV colors, get a resized window, and show image. # cv_image = cv2.cvtColor(cv_image, cv2.COLOR_RGB2BGR) # cv2.namedWindow('Resized Window', cv2.WINDOW_NORMAL) # cv2.resizeWindow('Resized Window', 800, 600) # cv2.imshow('Resized Window', cv_image) # cv2.waitKey(0) # print(num_faces) return faceList
# Derived INSET_M = INSET_CENTER_M - INSET_L / 2 R = DIAMETER / 2 tool_size = mat['tool_size'] half_tool = tool_size / 2 ############################# g.absolute() g.feed(mat['feed_rate']) g.move(z=CNC_TRAVEL_Z) g.move(x=-R + half_tool, y=INSET_M + half_tool) g.move(z=0) rectangle(g, mat, CUT_DEPTH, DIAMETER - tool_size, INSET_L - tool_size) g.move(z=CNC_TRAVEL_Z) g.move(x=-R + half_tool, y=CRYSTAL_0_M + half_tool) g.move(z=0) rectangle(g, mat, CUT_DEPTH, DIAMETER - tool_size, CRYSTAL_0_L - tool_size) g.move(z=CNC_TRAVEL_Z) g.move(x=-R + half_tool, y=CRYSTAL_1_M + half_tool) g.move(z=0) rectangle(g, mat, CUT_DEPTH, DIAMETER - tool_size, CRYSTAL_1_L - tool_size) g.move(z=CNC_TRAVEL_Z) g.move(x=-OLED_W / 2 + half_tool, y=OLED_M + half_tool) g.move(z=0) rectangle(g, mat, CUT_DEPTH, OLED_W - tool_size, OLED_L - tool_size)
from rectangle import rectangle from stock import stock #Problem 1 rectangle1 = rectangle() rectangle1.setWidth(4) rectangle1.setHeight(40) print('Rectangle 1 Width: ' + str(rectangle1.width)) print('Rectangle 1 Height: ' + str(rectangle1.height)) print('Rectangle 1 Area: ' + str(rectangle1.getArea())) print('Rectangle 1 Perimeter: ' + str(rectangle1.getPerimeter())) rectangle2 = rectangle() rectangle2.setWidth(3.5) rectangle2.setHeight(35.7) print('Rectangle 2 Width: ' + str(rectangle2.width)) print('Rectangle 2 Height: ' + str(rectangle2.height)) print('Rectangle 2 Area: ' + str(rectangle2.getArea())) print('Rectangle 2 Perimeter: ' + str(rectangle2.getPerimeter())) #Problem 2 stock1 = stock("Intel Corporation", "INTC", 20.5, 20.35) print(str(stock1.getChangePercent()))
def update_hitbox(self): self.head_box = rectangle.rectangle(self.x, self.y + 4, 16, 16) self.body_box = rectangle.rectangle(self.x, self.y - 10, 10, 4) self.legs_box = rectangle.rectangle(self.x, self.y - 20, 2, 4)