def calculate_convex_hull(point_list: List[Point]) -> List[Point]: """ This method returns a list of points which is in the right order such that, when these points are connected with their neighboring points in the list that it will be the convex hull of the given point_list. This method uses the Grahams scan method to calculate the convex hull. This method will also show the calculated convex hull using matplotlib. """ if len(point_list) == 0: return [] else: drawing.draw_dynamically(point_list, [], 0.1) lowest_point = get_lowest_point(point_list) reference_point = Point.Point(lowest_point.get_x() + 1, lowest_point.get_y()) sorted_point_list = sorted(point_list, key=lambda point: lowest_point.calculate_angle(reference_point, point)) stack = [lowest_point] + sorted_point_list[:2] for i in range(2, len(sorted_point_list) - 1): current_point = sorted_point_list[i] while not stack[-1].turns_left(stack[-2], current_point): stack.pop() drawing.draw_dynamically(point_list, stack) stack.append(current_point) drawing.draw_dynamically(point_list, stack) stack.append(lowest_point) drawing.draw_set_of_points(point_list) drawing.draw_set_of_lines(stack) drawing.draw() return stack
def draw_it(dt): try: if debug: drawpolygon(shape, screen_size) current_points = next(points) draw(current_points, screen_size) except StopIteration: window.set_caption("Done!")
def savePicture(dictGoodId): for key, value in dictGoodId.iteritems(): #这两个列表至关重要,不能放在其他循环那里 goodDayType = [] goodDayNum = [] goodDay = {} #给每一个值赋值0 days = [3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 100] for i in range(len(days)): goodDay[days[i]] = [0] for key1, value1 in value.iteritems(): if key1 in goodDay: goodDay[key1] = value1 #对数据进行一个排序,按照时间来,否则会是乱序,但字典没有顺序asd[0]根据键排序,asd=[1]根据值排序 goodDay = sorted(goodDay.iteritems(), key=lambda asd: asd[0], reverse=True) # print goodDay #获取一个月的数据 for key2, value2 in goodDay[1:]: goodDayType.append(key2) goodDayNum.append(value2[0]) #数据整理好之后开始画图: pic_path = draw(goodDayType, goodDayNum, key) print pic_path sqlAdd(pic_path, key)
def calculate_convex_hull(point_list: List[Point]) -> List[Point]: """ This method returns a list of points which is in the right order such that, when these points are connected with their neighboring points in the list that it will be the convex hull of the given point_list. This method uses the Jarvis march method to calculate the convex hull. This method will also show the calculated convex hull using matplotlib. """ if len(point_list) == 0: return [] else: lowest_point, highest_point = get_lowest_and_highest_point(point_list) passed_highest_point = False current_point = lowest_point result = [current_point] while not (current_point == lowest_point and passed_highest_point): # constructing reference point if passed_highest_point: reference_point = Point.Point(current_point.get_x() - 1, current_point.get_y()) else: reference_point = Point.Point(current_point.get_x() + 1, current_point.get_y()) # getting point with smallest angle compared to current_point and reference_point smallest_angle = 2 * math.pi point_with_smallest_angle = current_point for point in point_list: current_angle = current_point.calculate_angle( reference_point, point) if current_angle < smallest_angle: smallest_angle = current_angle point_with_smallest_angle = point current_point = point_with_smallest_angle result.append(current_point) # check if current_point is the highest point if current_point.__eq__(highest_point): passed_highest_point = True drawing.draw_set_of_points(point_list) drawing.draw_set_of_lines(result) drawing.draw() return result
def main(): from drawing import draw pygame.init() window = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT)) pygame.display.set_caption("Valkyrie") level = Level.load(Level.ONE, AssetFactory()) state = level.initial_game_state running = True while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN and event.key == pygame.K_q: running = False update(state, level.update) draw(window, state) pygame.quit()
def bibi(self): url = "https://passport.bilibili.com/login" self.browser.get(url) xpath = '//*[@id="login-username"]' self.wait.until(EC.presence_of_element_located( (By.XPATH, xpath))).send_keys('Python') xpath = '//*[@id="login-passwd"]' self.wait.until(EC.presence_of_element_located( (By.XPATH, xpath))).send_keys('Python') xpath = '//*[@id="geetest-wrap"]//*[@class="btn btn-login"]' self.click(xpath) xpath = '//*[@class="geetest_item_img"]' logo = self.wait.until( EC.presence_of_element_located((By.XPATH, xpath))) # 获取图片路径 f = logo.get_attribute('src') if not f: return None content = requests.get(f).content res = cap.run(content) plan = to_selenium(res) X, Y = logo.location['x'], logo.location['y'] # print(X, Y) lan_x = 259 / 334 lan_y = 290 / 384 for p in plan: x, y = p['place'] ActionChains(self.browser).move_by_offset( X + x * lan_x - self.x_offset, Y + y * lan_y).click().perform() ActionChains(self.browser).move_by_offset( -(X + x * lan_x - self.x_offset), -(Y + y * lan_y)).perform() # 将鼠标位置恢复到移动前 time.sleep(0.5) xpath = "//*[@class='geetest_commit_tip']" self.click(xpath) draw(content, res)
def generate(template, xlsx, domain, total): # print(total) # exit() rows = [] fields = [] wb_obj = openpyxl.load_workbook(xlsx) sheet_obj = wb_obj.active max_col = sheet_obj.max_column max_row = sheet_obj.max_row print(max_col, max_row) # Will print a particular row value for i in range(2, max_row + 1): tmp = [] for j in range(1, max_col + 1): cell_obj = sheet_obj.cell(row=i, column=j) tmp.append(str(cell_obj.value)) rows.append(tmp) print(rows) from drawing import draw draw(rows, template, domain, total, 0)
def main(args): model_dir = args.model_dir load_num = args.load_num model_path = os.path.join(model_dir,cfgs.DataSet_Name) model_path = os.path.join(model_path,cfgs.ModelPrefix) model_path = "%s-%s" %(model_path,load_num) det = Detector( model_path=model_path, input_size=args.input_size, use_sfam=args.sfam, threshold=args.threshold) if args.inputs.endswith('.mp4'): cap = cv2.VideoCapture(args.inputs) while True: ret, img = cap.read() if not ret: break results = det.detect(img) draw(img, results) cv2.imshow('video', img) cv2.waitKey(1) elif os.path.isdir(args.inputs): paths = glob.glob(os.path.join(args.inputs, '*')) for path in paths: print(path) img = cv2.imread(path) results = det.detect(img) draw(img, results) cv2.imshow('', img) cv2.waitKey(0) else: img = cv2.imread(args.inputs) results = det.detect(img) draw(img, results) cv2.imshow('src', img) cv2.waitKey(0)
import sys import tsp import drawing import tspstep as step import sa import tspstep as steps print('running on {}'.format(sys.platform)) t = tsp.TSP(8, True) steps.createnew(t) d = t.clone drawing.draw(d, 1, False) SA = sa.SimulatedAnnealing(t, 50, 1500, 50, 50) SA.runAlgorithm() drawing.draw(SA.globalBest, 2, True)
""" @author: jiajia @file: demo.py @time: 2021/3/28 15:31 """ from src import captcha from drawing import draw import time if __name__ == '__main__': path = r"img/1234.jpg" with open(path, 'rb') as f: path = f.read() cap = captcha.TextSelectCaptcha(GPU=True) s1 = time.time() data = cap.run(path) print(data) print(time.time() - s1) draw(path, data)
def graphOrder(grid, bestPinsOrder): drawing.draw(grid) h = len(grid[0]) w = len(grid) tags = [[0 for j in xrange(h)] for i in xrange(w)] visited = set() index = 0 temp_grid = copy.deepcopy(grid) pins = list(bestPinsOrder) number_of_pins = len(pins) count = 0 # print pins while pins: pin = pins.pop(0) queue = [tuple(pin[0])] tags[pin[0][0]][pin[0][1]] = 1 traceable = False while queue: vertex = queue.pop(0) # print vertex, "popped" # print visited # print tuple(vertex) if tuple(vertex) not in visited: # print "not visited" visited.add(tuple(vertex)) neigh = neighbours(vertex, h, w, temp_grid, pin[2]) queue.extend(neigh) # print neigh for x in neigh: if tags[x[0]][x[1]] == 0: tags[x[0]][x[1]] = tags[vertex[0]][vertex[1]] + 1 for x in neigh: drawing.printTag(x[0], x[1], tags[x[0]][x[1]]) # print [x[0]],[x[1]], # print tags[x[0]][x[1]] if [x[0], x[1]] == pin[1]: count = count + 1 traceable = True path = traceBack(tags, pin[1], pin[0], w, h) drawing.click() drawing.drawWire(path, pin[2]) break if (traceable): break # drawing.click() #Enable for very slow speed steps # drawing.click() #Enable for intermediate speed steps if (traceable): for point in path: temp_grid[point[0]][point[1]][0] = 3 #Setting the state = wire temp_grid[point[0]][point[1]][1] = pin[2] #Setting "belong to" to wire number #Clear the drawing, Empty the tags list, Empty the visited set drawing.click() drawing.clearTags(temp_grid) #Clear the drawing first tags = [[0 for j in xrange(h)] for i in xrange(w)] visited.clear() index = index + 1 print count, print "segments were routed", print "out of", print number_of_pins return tags
GREEN = (0, 255, 0) RED = (255, 0, 0) BLUE = (0, 0, 255) size = (1024, 682) screen = pygame.display.set_mode(size) clock = pygame.time.Clock() heads = True crashed = False pygame.init() while not crashed: from drawing import draw for event in pygame.event.get(): if event.type == pygame.QUIT: crashed = True print(event) screen.fill(WHITE) draw() pygame.display.update() clock.tick(60)
from PIL import Image import drawing, processing # Properties # name: name of files # expansion: number of iterations in L-System # size: length and width of lines, radius of circles # energy: length of lines, randomness of lines and circles # weight: angle of turns # wind: horizontal distance added to lines name = "test" expansion = 5 size = 5 energy = 5 weight = 5 wind = 0 commands = drawing.write(expansion) unfilteredImg = drawing.draw(512, 512, commands, size, energy, weight, wind) unfilteredImg.save(name + ".png", "PNG") filteredImg = processing.process(unfilteredImg) filteredImg.save(name + "_filtered.png", "PNG")
def save_pages_as_pdf(self, pages): dialog = Gtk.FileChooserDialog( _("Select a pdf file"), self, Gtk.FileChooserAction.SAVE, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL, Gtk.STOCK_OPEN, Gtk.ResponseType.OK), ) dialog.set_default_response(Gtk.ResponseType.OK) filter = Gtk.FileFilter() filter.set_name(_("Pdf files")) filter.add_mime_type("application/pdf") filter.add_pattern("*.pdf") dialog.add_filter(filter) preview = MiniView(200) dialog.set_use_preview_label(False) dialog.set_preview_widget(preview) dialog.connect("update-preview", self.update_preview_cb, preview) response = dialog.run() if response == Gtk.ResponseType.OK: filename = dialog.get_filename() dialog.destroy() if not filename.endswith(".pdf"): filename += ".pdf" pdfsurface = cairo.PDFSurface(filename, 200, 200) context = cairo.Context(pdfsurface) progressdialog = Progreso(_("Save pdf"), self, len(pages)) for number_of_page in pages: if number_of_page > 0 and number_of_page < len(self.miniview.get_children()): page = self.miniview.get_children()[number_of_page - 1] context.save() if page.rotation_angle == 0.0 or page.rotation_angle == 2.0: width, height = page.get_size() else: height, width = page.get_size() pdfsurface.set_size(width, height) mtr = cairo.Matrix() mtr.rotate(page.rotation_angle * math.pi / 2.0) context.transform(mtr) if page.rotation_angle == 1.0: context.translate(0.0, -width) elif page.rotation_angle == 2.0: context.translate(-width, -height) elif page.rotation_angle == 3.0: context.translate(-height, 0.0) if page.page: page.page.render(context) context.restore() context.save() mtr = cairo.Matrix() mtr.rotate(page.rotation_angle * math.pi / 2.0) mtr.scale(1.0 / comun.RESOLUTION, 1.0 / comun.RESOLUTION) context.transform(mtr) if page.rotation_angle == 1.0: context.translate(0.0, -width * comun.RESOLUTION) elif page.rotation_angle == 2.0: context.translate(-width * comun.RESOLUTION, -height * comun.RESOLUTION) elif page.rotation_angle == 3.0: context.translate(-height * comun.RESOLUTION, 0.0) for drawing in page.drawings: drawing.draw(context) context.restore() context.show_page() progressdialog.increase() dialog.destroy()
# Author: Max Martinez Ruts # Creation: 2019 import time import chessboard as cb import drawing as dr import minmaxsearch as mm treeshape = [0, 0, 0, 0, 0] board, pieces = cb.initialize_board() while True: print(print(cb.get_numerical(board))) board = cb.wt(board) dr.draw(board) start = time.time() res = mm.max_search(board, 3, [], 9999) print('Execution time: ', time.time() - start, ' Tree shape: ', treeshape) print(res[0], 'b') board = res[1][1] dr.draw(board) sc = cb.get_score(board) if sc < -500: print('White wins') if sc > 500: print('Black wins') print('score', cb.get_score(board))
outputx = torch.cat(boxs, 1) return outputx def decect(self, img): # 图片转换为矩阵 image_numpy = self.to_numpy(img, shape=(self.img_size, self.img_size)) input_feed = self.get_input_feed(self.input_name, image_numpy) outputs = self.onnx_session.run(self.output_name, input_feed=input_feed) outputx = self.detect(outputs) pred = non_max_suppression(outputx) res = tag_images(img, pred, self.img_size, self.classes) return res if __name__ == '__main__': yolo = YOLO( "C:\CodeFiles\image\wordChoice\Text_select_captcha/src/model/yolo.onnx" ) img = r"C:\CodeFiles\image\wordChoice\Text_select_captcha\img\1234.jpg" pred = yolo.decect(img) data = [] for i in pred: i['content'] = '' data.append(i) from drawing import draw draw(img, data)
delta = datetime.datetime.now() - tstart print("Neighbors. Time " + str(delta.seconds) + "." + str(delta.microseconds)) #for i in range(boxes.size): # boxes[i].printbox() x1 = 2.2 y1 = 0.5 x2 = 1.2 y2 = 0.9 trajectory = di.trajectory_search(boxes, x1, y1, x2, y2) #trajectory = np.array([]) #dr.draw(boxes, trajectory, singularity) dr.draw(boxes, trajectory, singularity) #dr.draw(boxes, np.array([]), singularity) #dr.draw(boxes, np.array([]), np.array([])) print("Left -> Right") x1 = 1.1 y1 = 0.8 x2 = 2.0 y2 = 0.8 trajectory = di.trajectory_search(boxes, x1, y1, x2, y2) dr.draw(boxes, trajectory, singularity) print("Right -> Left") x1 = 2.0 y1 = 0.8 x2 = 1.1
def wt(bd): wait = True start = () end = () while wait: for event in pygame.event.get(): for i in range(0, 8): for j in range(0, 8): if (i + j) % 2 == 1: dr.boards_squares[i, j] = (dr.boards_squares[i, j][0], dr.black_soft) if (i + j) % 2 == 0: dr.boards_squares[i, j] = (dr.boards_squares[i, j][0], dr.white_soft) if event.type == pygame.MOUSEMOTION: # Record mouse position mouse_pos = event.pos for i in range(0, 8): for j in range(0, 8): if dr.boards_squares[i, j][0].collidepoint(mouse_pos): if bd[i, j] != None: if (i + j) % 2 == 1: dr.boards_squares[i, j] = ( dr.boards_squares[i, j][0], dr.black_soft) moves = bd[i, j].moves(bd, (i, j)) if (i + j) % 2 == 0: dr.boards_squares[i, j] = ( dr.boards_squares[i, j][0], dr.white_soft) moves = bd[i, j].moves(bd, (i, j)) for move in moves: for k in range(0, 8): for l in range(0, 8): if move[k, l] == bd[i, j]: if (k + l) % 2 == 0: dr.boards_squares[k, l] = ( dr.boards_squares[k, l] [0], (190, 167, 128)) else: dr.boards_squares[k, l] = ( dr.boards_squares[k, l] [0], (131, 86, 46)) if event.type == pygame.MOUSEBUTTONDOWN: # Record mouse position mouse_pos = event.pos for i in range(0, 8): for j in range(0, 8): if bd[i, j] != None and dr.boards_squares[ i, j][0].collidepoint(mouse_pos): start = (i, j) print('start') if event.type == pygame.MOUSEBUTTONUP: # Record mouse position mouse_pos = event.pos for i in range(0, 8): for j in range(0, 8): if dr.boards_squares[i, j][0].collidepoint(mouse_pos): if start != (): end = (i, j) wait = False dr.draw(bd) bd[end] = bd[start] bd[start] = None return bd