def seperate_objects_by_centers(objs_data, max_dist): ''' Returns two list of objects separated by their relative distance from each other. The distance is configured by max_dist :param people_data: :param max_dist: :return: ''' # get a list of center of objects obj_centers = [] for cord in objs_data: obj_centers.append(get_center(cord[0], cord[1])) too_close = [] far = [] for i in range(0, len(obj_centers)): for j in range(0, len(obj_centers)): if i == j: continue d = euclidian_distance(obj_centers[j], obj_centers[i]) (x1, y1) = float_cords_to_int(obj_centers[j]) (x2, y2) = float_cords_to_int(obj_centers[i]) if (d <= max_dist): too_close.append(((x1, y1), (x2, y2), objs_data[j], objs_data[i])) else: far.append(((x1, y1), (x2, y2), objs_data[j], objs_data[i])) return too_close, far
def __init__(self, track, frame_id, counter_to_change_state=20, min_distance=4.0, dist_persec=1, nn_age=10, fps=25): self.track_id = track.track_id init_box = track.to_tlbr() self.boxes = [init_box] self.centers = [ get_center(init_box[0], init_box[1], init_box[2], init_box[3]) ] self.is_stopped = False self.counter = counter_to_change_state self.count_to_change_state = counter_to_change_state self.is_deleted = track.is_deleted() self.min_distance = min_distance self.dist_persec = dist_persec self.time_since_update = 0 self.nn_age = nn_age self.events = [] self.frames = [frame_id] self.fps = fps
def update(self, track, frame_id): self.time_since_update = 0 if track.is_deleted(): self.is_deleted = True elif track.is_confirmed() and track.time_since_update == 0: self.is_deleted = False self.frames.append(frame_id) bbox = track.to_tlbr() self.boxes.append(bbox) self.centers.append(get_center(bbox[0], bbox[1], bbox[2], bbox[3])) is_stopped = False p1 = self.centers[-1] p2 = self.get_first_center_before_nsec_of_last(self.dist_persec) if hypot(p1[0] - p2[0], p1[1] - p2[1]) < self.min_distance * (bbox[2] - bbox[0]): is_stopped = True if self.is_stopped is is_stopped: if self.counter < self.count_to_change_state: self.counter += 1 else: if self.counter > 0: self.counter -= 1 else: self.is_stopped = not self.is_stopped self.counter = self.count_to_change_state if self.is_stopped: self.events.append( Event(self.get_last_meet(), self.track_id, EventType.BusStopping)) else: self.events.append( Event(self.get_last_meet(), self.track_id, EventType.BusMoving))
def cumulative_center(self, frame_index, last_frames=3): centers = [] for i in range(frame_index - last_frames, frame_index): coords = self.frames.get(i) if coords is not None: centers.append(coords.center) return get_center(centers)
def update(self, track, frame_id): self.time_since_update = 0 if track.is_deleted(): self.is_confirmed = False self.is_deleted = True elif track.time_since_update == 0: bbox = track.to_tlbr() self.boxes.append(bbox) self.centers.append(get_center(bbox[0], bbox[1], bbox[2], bbox[3])) self.is_confirmed = track.is_confirmed() self.frames.append(frame_id) self.is_deleted = False
def mark_center(image_filename: str, coords_filename: str): """ Example: mark_center('p23-181.png', 'res/p23-181.txt') :return: """ im = cv2.imread(DEMO_DIR + image_filename) pts = read_points(coords_filename) center_pts = get_center(pts) for pt in center_pts: point = int(pt[0]), int(pt[1]) cv2.circle(im, point, 10, (0, 0, 255), -1) cv2.imwrite(f'mark-center.png', im)
def __init__(self, track, frame_id, nnage=10, fps=25): self.track_id = track.track_id init_box = track.to_tlbr() self.boxes = [init_box] self.centers = [ get_center(init_box[0], init_box[1], init_box[2], init_box[3]) ] self.frames = [frame_id] self.is_deleted = track.is_deleted() self.is_confirmed = track.is_confirmed self.time_since_update = 0 self.crossed = [] self.nnage = nnage self.events = [] self.fps = fps
def index(): context = { "key": keys['gmaps_key'], } form = RouteBuildForm() if form.validate_on_submit(): builder = RouteGenerate(**keys) route = builder.route_builder(form.southwest.data, form.northeast.data, form.home.data, form.distance.data) if route: context['points'] = repr( route['overview_polyline'].get('points')).replace("'", '') context['dist'] = sum([ i.get('distance').get('value') * 0.0006213712 for i in route['legs'] ]) center = utils.get_center(route) context['center_lat'] = float(center.get('lat')) context['center_lng'] = float(center.get('lng')) context['ele'] = utils.get_elevation( route['overview_polyline'].get('points')) context['x'] = list( np.arange(0, context['dist'], context['dist'] / 512)) context['gain'] = utils.get_total_gain(context['ele']) context['directions'] = utils.get_directions(route) start = route['legs'][0].get('start_location') context['start_lat'] = start.get('lat') context['start_lng'] = start.get('lng') else: context['none'] = 'No ride found! Please Try again!' return render_template('main.html', form=form, context=context)
def remove_duplicate_objects_detections(extracted_obj, epsilon): ''' Removes duplicate items. Items with distance less then epsilon are considered duplicates and are removed :param extracted_obj: :return: ''' duplicate_free = dict([]) current_frame = 0 for key in extracted_obj.keys(): duplicate_free[str(current_frame)] = [] frame = extracted_obj[key] centers = [] for item in frame: center = get_center(item[0], item[1]) centers.append((center, item)) for i in range(0, len(centers)): current_item = centers[i] is_duplicate = False for j in range(i + 1, len(centers)): other_item = centers[j] d = euclidian_distance(current_item[0], other_item[0]) if d <= epsilon: is_duplicate = True if not is_duplicate: duplicate_free[str(current_frame)].append(current_item[1]) current_frame += 1 return duplicate_free
def render(self, display: pygame.Surface): display.fill("#ecdcdf") pygame.draw.polygon(display, "#f4523b", PokeDexInfo.poly_1) pygame.draw.polygon(display, "#fa7248", PokeDexInfo.poly_2) pygame.draw.polygon(display, "#f4523b", PokeDexInfo.poly_3) utils.draw_button_info(display, **self.keys) poke = pokemon.get_pokemon(self.selected + 1) # big big_im = displayer.get_poke(PokeDex.PATH(str(poke.id_)), 3) s_x, s_y = big_im.get_size() display.blit(big_im, (250 - s_x // 2, 300 - s_y // 2)) utils.draw_split_rectangle(display, (477, 60, 530, 50), 0.4, 0.35, "#f0501e", "#000000") utils.draw_arrow(display, True, 742, 56, (255, 255, 255), size=2) utils.draw_arrow(display, False, 742, 114, (255, 255, 255), size=2) y = 62 im = displayer.get_poke(PokeDex.PATH(str(poke.id_)), 0.7) delta_x, delta_y = utils.get_first_color(im) x = 480 display.blit(im, (x, y + 30 - delta_y)) status = game.get_game_instance().get_pokedex_status(self.selected + 1) display.blit(game.FONT_24.render(f"N° {pokemon.to_3_digit(self.selected + 1)}", True, (255, 255, 255)), (x + 50, y + 10)) display.blit(game.FONT_24.render(poke.get_name(True) if poke.id_ != 0 else "???", True, (255, 255, 255)), (689, y + 10)) if status != game.POKEDEX_NEVER_SEEN: display.blit( self.white_pokeball if status == game.POKEDEX_CATCH else utils.POINT_POKEBALL, (950, y + 8) ) x, y = 530, 150 l = 424 h = 40 s = 3 pygame.draw.rect(display, "#dbdbd9", (x, y, l, h,)) display.blit(tx := game.FONT_24.render(poke.get_japan_name(), True, (0, 0, 0)), (x + (l - tx.get_size()[0]) // 2, y + (h - tx.get_size()[1]) // 2)) y += h + s tx = ("type", "size", "weight", "view") tx2 = (None, f'{poke.size} m', f'{poke.weight} Kg', str(game.get_game_instance().get_nb_view(self.selected + 1))) for i in range(4): pygame.draw.rect(display, "#dbdbd9", (x, y, l // 2, h)) pygame.draw.rect(display, "#ffffff", (x + l // 2, y, l // 2, h)) display.blit(sur := game.FONT_24.render(game.get_game_instance().get_message(tx[i]), True, (0, 0, 0)), utils.get_center(sur, (x, y, l // 2, h))) if i != 0: display.blit(sur := game.FONT_24.render(tx2[i], True, (0, 0, 0)), utils.get_center(sur, (x + l // 2 + 5, y, l // 2, h), center_x=False)) else: _x_ = x + l // 2 + 10 for ii in range(len(poke.types)): utils.draw_type(display, _x_, y + h // 2 - 8, poke.types[ii]) _x_ += 106 y += h if i != 3: pygame.draw.rect(display, "#d2d2d2", (x, y, l // 2, s)) pygame.draw.rect(display, "#f3f3f3", (x + l // 2, y, l // 2, h)) y += s pygame.draw.rect(display, "#ffffff", (x, y, l, int(h * 4.5))) x += 5 y += 10 for p_l in hud.Dialog.split(poke.get_pokedex(), 40): display.blit(game.FONT_20.render(p_l, True, (0, 0, 0)), (x, y)) y += game.FONT_SIZE_20[1] + 5