def get_best_license_plate(self, license_plates, image_original, resize_width=400):
     '''
     Get best license plate.
     '''
     best_license_plate = None
     
     # Detect characters in license plate.
     for license_plate in license_plates:
         character_validator = CharacterValidator()
         image = image_original.crop(Point(license_plate.x, license_plate.y), Point(license_plate.x + license_plate.w, license_plate.y + license_plate.h))
         image = image.resize(resize_width, resize_width * image.height / image.width)
         image = pre_process_license_plate_image(image, adaptative=False)
         license_plate.image = image
         license_plate.subrects = image.compute_rectangles_for_characters()
         character_validator.remove_wrong_characters(license_plate)
         
         # If not enough characters detected, binarize image using adaptative method. 
         if len(license_plate.subrects) < 2:
             image = image_original.crop(Point(license_plate.x, license_plate.y), Point(license_plate.x + license_plate.w, license_plate.y + license_plate.h))
             image = image.resize(resize_width, resize_width * image.height / image.width)
             image = pre_process_license_plate_image(image, True)
             license_plate.image = image
             license_plate.subrects = image.compute_rectangles_for_characters()
             character_validator.remove_wrong_characters(license_plate)
     
     # Find best license plate by total of characters and area. 
     if len(license_plates) > 0:
         license_plates = sorted(license_plates, key=lambda x: len(x.subrects) -math.tanh(x.h*x.w*1.0/(x.image.width*x.image.height)))
         license_plates = license_plates[::-1] 
         best_license_plate = license_plates[0]
         
         filtera = FilterCharacters()
         best_license_plate.subrects = filtera.filter_characters_by_color(best_license_plate.subrects, best_license_plate.image)
         
     return best_license_plate
    def get_calf_points(front: Person,
                        side: Person) -> Tuple[Point, Point, Point, Point]:
        # calf_left_c = get_max_coord_with_min(front.leg.calf.right)
        # calf_right_c = front.leg.calf.right[1].min()
        # calf_left_col = np.where(front.leg.calf.right[1] == calf_left_c)
        # calf_left_r = calf_right_r = front.leg.calf.right[0][calf_left_col[0].max()]

        calf_back_c = side.leg.calf.right[1].min()
        calf_front_c = get_max_coord_with_min(side.leg.calf.right)
        calf_height_row = np.where(side.leg.calf.right[1] == calf_back_c)
        calf_height = side.leg.calf.right[0][calf_height_row[0].max()]

        calf_height_ratio = (calf_height - side.all[0].min()) / (
            side.all[0].max() - side.all[0].min())
        calf_front_height = int(
            ((front.all[0].max() + front.leg.calf.right[0].max()) / 2 - front.all[0].min()) * calf_height_ratio) + \
                            front.all[0].min()
        calf_row = np.where(front.leg.calf.right[0] == calf_front_height)
        # print(calf_row[0])
        calf_left_c = front.leg.calf.right[1][calf_row[0].max()]
        calf_right_c = front.leg.calf.right[1][calf_row[0].min()]

        calf_left = Point(calf_left_c, calf_front_height)
        calf_right = Point(calf_right_c, calf_front_height)
        calf_back = Point(calf_back_c, calf_height)
        calf_front = Point(calf_front_c, calf_height)

        return calf_left, calf_right, calf_back, calf_front
    def get_hip_points(
            front: Person, side: Person, crotch: Point,
            above_pelvis: Point) -> Tuple[Point, Point, Point, Point]:
        hip_r = (crotch[1] + above_pelvis[1]) // 2
        hip_row = np.where(front.hip[0] == hip_r)
        hip_left_c = front.hip[1][hip_row[0].max()]
        hip_right_c = front.hip[1][hip_row[0].min()]

        hip_left = Point(hip_left_c, hip_r)
        hip_right = Point(hip_right_c, hip_r)
        # hip_left_c = front[1].max()
        # hip_left_row = np.where(front[1] == front[1].max())
        # hip_left_r = front[0][hip_left_row[0].max()]
        # hip_left = (hip_left_c, hip_left_r)
        # hip_right_c = front[1].min()
        # hip_right_row = np.where(front[1] == front[1].min())
        # hip_right_r = front[0][hip_right_row[0].min()]
        # hip_right = (hip_right_c, hip_right_r)
        hip_back_c = side.hip[1].min()
        hip_back_col = np.where(side.hip[1] == hip_back_c)
        hip_back_r = side.hip[0][hip_back_col[0].min()]
        hip_back = Point(hip_back_c, hip_back_r)
        hip_front_col = np.where(side.hip[1] == hip_back_c)
        hip_front_r = side.hip[0][hip_front_col[0][0]]
        hip_front_row = np.where(side.all[0] == hip_front_r)
        hip_front_c = side.all[1][hip_front_row[0].max()]
        # hip_front_c = get_max_coord_with_min(side)
        # hip_front_col = np.where(side[1] == hip_front_c)
        # hip_front_r = side[0][hip_front_col[0].max()]
        hip_front = Point(hip_front_c, hip_front_r)

        return hip_left, hip_right, hip_back, hip_front
    def get_shoulder_points(front: Person) -> Tuple[Point, Point]:
        front_shoulder_left = Point(front.arm.left.upper[1][0],
                                    front.arm.left.upper[0][0])
        front_shoulder_right = Point(front.arm.right.upper[1][0],
                                     front.arm.right.upper[0][0])

        return front_shoulder_left, front_shoulder_right
Пример #5
0
def main():
    point_a = Point(2, 3)
    point_b = Point(5, 5)

    print('El punto a es:')
    point_a.__str__()

    print('El punto b es:')
    point_b.__str__()

    print('El punto a se encuentra en: {}'.format(point_a.quadrant()))
    print('El punto b se encuentra en: {}'.format(point_b.quadrant()))

    vector_a, vector_b = point_a.vector(point_b.axis_x, point_b.axis_y)
    print('El vector resultante: ({}, {})'.format(vector_a, vector_b))

    vector_a, vector_b = point_b.vector(point_a.axis_x, point_a.axis_y)
    print('El vector resultante: ({}, {})'.format(vector_a, vector_b))

    print('La distancia entre los puntos es: {}'.format(
        point_a.distance(point_b.axis_x, point_b.axis_y)))

    rectangle = Rectangle(point_a, point_b)

    print('La base del rectangulo es {}'.format(rectangle.base))
    print('La altura del rectangulo es {}'.format(rectangle.height))
    print('El area del rectangulo es igual a {}'.format(rectangle.area()))
    def _correct_dot_character(self, license_plate, image_original, width,
                               height, m, c, x_interval):
        '''
        Move dot character to other position.   
        '''
        found_dot = False
        characters = []

        for character in license_plate.subrects:
            if character.x < 0:
                character.x = 0

            if character.y < 0:
                character.y = 0

            if character.x > license_plate.image.width - 1:
                character.x = license_plate.image.width - 1

            if character.y > license_plate.image.height - 1:
                character.y = license_plate.image.height - 1

            if character.x + character.w > license_plate.image.width - 1:
                character.w = license_plate.image.width - 1 - character.x

            if character.y + character.h > license_plate.image.height - 1:
                character.y = license_plate.image.height - 1 - character.y

            if not found_dot:
                character_image = license_plate.image.crop(
                    Point(character.x, character.y),
                    Point(character.x + character.w - 1,
                          character.y + character.h - 1))

                if character_image.data.size > 0 and character_image.data is not None:
                    mean_value = np.mean(character_image.data)
                else:
                    mean_value = 0

                if mean_value > 200:
                    found_dot = True
                else:
                    characters.append(character)

            else:
                characters.append(character)

        if found_dot:
            # Remove dot character and add new character.
            license_plate.subrects = characters

            # Insert new character.
            license_plate, inserted, width, height, m, c, x_interval = self._insert_between_characters(
                license_plate, image_original, width, height, m, c, x_interval)

            if not inserted:
                license_plate, width, height, m, c, x_interval = self._insert_in_limits(
                    license_plate, image_original, width, height, m, c,
                    x_interval)

        return license_plate
Пример #7
0
def create_room_reflections(current_room: Room, reflections_list: List[Room]):
    left_reflection = deepcopy(current_room)
    left_reflection.move_room_left()
    switch_coefficient(left_reflection.left_wall, left_reflection.right_wall)

    left_reflection_transmitter_x = \
        left_reflection.left_wall.start_point.x + current_room.length - abs(left_reflection.transmitter.x - left_reflection.left_wall.start_point.x)
    left_reflection_transmitter_y = left_reflection.transmitter.y
    left_ref_transmitter = Point(left_reflection_transmitter_x,
                                 left_reflection_transmitter_y)
    left_reflection.transmitter = left_ref_transmitter

    top_reflection = deepcopy(current_room)
    top_reflection.move_room_up()
    switch_coefficient(top_reflection.top_wall, top_reflection.down_wall)

    top_ref_transmitter_x = top_reflection.transmitter.x
    top_ref_transmitter_y = \
        top_reflection.left_wall.start_point.y + current_room.height - abs(top_reflection.transmitter.y - top_reflection.left_wall.start_point.y)
    top_ref_transmitter = Point(top_ref_transmitter_x, top_ref_transmitter_y)
    top_reflection.transmitter = top_ref_transmitter

    right_reflection = deepcopy(current_room)
    right_reflection.move_room_right()
    switch_coefficient(right_reflection.left_wall, right_reflection.right_wall)

    right_reflection_transmitter_x = \
        right_reflection.left_wall.start_point.x + current_room.length - abs(right_reflection.transmitter.x - right_reflection.left_wall.start_point.x)
    right_reflection_transmitter_y = right_reflection.transmitter.y
    right_ref_transmitter = Point(right_reflection_transmitter_x,
                                  right_reflection_transmitter_y)
    right_reflection.transmitter = right_ref_transmitter

    down_reflection = deepcopy(current_room)
    down_reflection.move_room_down()
    switch_coefficient(down_reflection.top_wall, down_reflection.down_wall)

    down_ref_transmitter_x = down_reflection.transmitter.x
    down_ref_transmitter_y = \
        down_reflection.left_wall.start_point.y + current_room.height - abs(down_reflection.transmitter.y - down_reflection.left_wall.start_point.y)
    down_ref_transmitter = Point(down_ref_transmitter_x,
                                 down_ref_transmitter_y)
    down_reflection.transmitter = down_ref_transmitter

    if left_reflection not in reflections_list:
        reflections_list.append(left_reflection)

    if top_reflection not in reflections_list:
        reflections_list.append(top_reflection)

    if right_reflection not in reflections_list:
        reflections_list.append(right_reflection)

    if down_reflection not in reflections_list:
        reflections_list.append(down_reflection)
    def get_neck_points(front: Person,
                        side: Person) -> Tuple[Point, Point, Point, Point]:
        body_middle = (front.body[1].max() + front.body[1].min()) // 2
        body_left_coords = np.where(
            front.body[1] > (front.body[1].max() + 9 * body_middle) / 10)
        # body_left_coords = np.where(front.body[1] > body_middle)
        body_right_coords = np.where(
            front.body[1] < (front.body[1].min() + 9 * body_middle) / 10)
        # body_right_coords = np.where(front.body[1] < body_middle)
        neck_left_row = np.where(
            front.body[0] == front.body[0][body_left_coords[0]].min())
        neck_right_row = np.where(
            front.body[0] == front.body[0][body_right_coords[0]].min())

        neck_start = side.body[0][0]
        neck_row = np.where(side.face.all[0] == neck_start)

        side_coord = side.body
        side_row_arr = []
        side_col_arr = []

        for i in range(side_coord[1].max(), side_coord[1].min(), -1):
            col = np.where(side_coord[1] == i)

            if col[0].shape[0] == 0:
                continue

            side_row_arr.append(side_coord[0][col[0][0]])
            side_col_arr.append(side_coord[1][col[0][0]])

        i = 0
        # print(side_row_arr)
        # print(side_col_arr)

        while True:
            if side_row_arr[i] >= side_row_arr[i + 1]:
                i += 1
                continue

            else:
                break
        # print(side_row_arr[i], side_col_arr[i])

        front_neck_left_point = Point(front.body[1][neck_left_row[0].max()],
                                      front.body[0][body_left_coords[0]].min())
        front_neck_right_point = Point(
            front.body[1][neck_right_row[0].min()],
            front.body[0][body_right_coords[0]].min())
        side_neck_left_point = Point(side.face.all[1][neck_row[0].min()],
                                     neck_start)
        # side_neck_right_point = (side.face.all[1][neck_row[0].max()], neck_start)
        side_neck_right_point = Point(side_col_arr[i], side_row_arr[i])

        return front_neck_left_point, front_neck_right_point, side_neck_left_point, side_neck_right_point
def normalize_characters_character_height(license_plate,
                                          image_original,
                                          character_height,
                                          m,
                                          c,
                                          recrop=True):
    '''
    Normalize height of characters.
    '''
    origin = Point(0, 0)
    end = Point(license_plate.image.width - 1, license_plate.image.height - 1)
    changed_image = False

    for index in range(len(license_plate.subrects)):
        new_y = int(license_plate.subrects[index].x * m + c)

        if abs(new_y - license_plate.subrects[index].y) > 5:
            license_plate.subrects[index].y = new_y

            if license_plate.subrects[index].y < origin.y:
                origin.y = license_plate.subrects[index].y
                changed_image = True

        license_plate.subrects[index].h = character_height

        if license_plate.subrects[index].h + license_plate.subrects[
                index].y - 1 > end.y:
            end.y = license_plate.subrects[index].y + license_plate.subrects[
                index].h - 1 + 50
            changed_image = True

    if changed_image and recrop:
        # Recrop image and compute rectangles again.
        license_plate = recrop_license_plate_image(license_plate, origin, end,
                                                   image_original)
        character_validator = models.character_validator.CharacterValidator()
        backup_image = Image(image=license_plate.image.data)
        image = pre_process_license_plate_image(license_plate.image,
                                                adaptative=False)
        license_plate.subrects = image.compute_rectangles_for_characters()
        character_validator.remove_wrong_characters(license_plate)

        # If not enough characters detected, binarize image using adaptative method.
        if len(license_plate.subrects) < 2:
            image = pre_process_license_plate_image(backup_image, True)
            license_plate.subrects = image.compute_rectangles_for_characters()
            character_validator.remove_wrong_characters(license_plate)

        validator = models.character_validator.CharacterValidator()
        m, c = validator.get_least_squares(license_plate)
        license_plate, m, c = normalize_characters_character_height(
            license_plate, image_original, character_height, m, c, False)

    return license_plate, m, c
    def get_sole_points(front: Person, side: Person) -> Tuple[Point, Point]:
        front_sole_row = (front.leg.calf.right[0].max() +
                          front.all[0].max()) // 2
        front_sole_cols = np.where(front.all[0] == front_sole_row)
        front_sole_col = front.all[1][front_sole_cols[0].min()]

        side_sole_row = side.all[0].max()
        side_sole_cols = np.where(side.all[0] == side.all[0].max())
        side_sole_col = side.all[1][side_sole_cols[0].min()]

        front_sole_point = Point(front_sole_col, front_sole_row)
        side_sole_point = Point(side_sole_col, side_sole_row)

        return front_sole_point, side_sole_point
    def get_arm_points(front: Person) -> Tuple[Point, Point]:
        try:
            shoulder_point = Point(front.arm.right.upper[1][0],
                                   front.arm.right.upper[0][0])

        except:
            raise MeasureKeypointsFailedException('front.shoulder_point')

        try:
            right_inner_wrist_point = Point(front.arm.right.lower[1][-1],
                                            front.arm.right.lower[0][-1])

        except:
            raise MeasureKeypointsFailedException('front.wrist_right_in')

        return shoulder_point, right_inner_wrist_point
Пример #12
0
 def cell_is_free(self, x, y):
     try:
         if self.grid[y][x] == "*":
             raise WrongMove("This cell is a part of the board grid.")
         return Point(x, y)
     except KeyError:
         raise WrongMove("This cell is outside of the board grid.")
def normalize_characters_character_width(license_plate,
                                         image_original,
                                         character_width,
                                         recrop=True):
    '''
    Normalize width of characters.
    '''

    origin = Point(0, 0)
    end = Point(license_plate.image.width - 1, license_plate.image.height - 1)
    changed_image = False

    for character in license_plate.subrects:
        if character.w < character_width:
            character.x = character.x - (character_width - character.w) / 2

            if character.x < origin.x:
                origin.x = character.x
                changed_image = True

        character.w = character_width

        if character.w + character.x - 1 > end.x:
            end.x = character.x + character.w - 1 + 50
            changed_image = True

    if changed_image and recrop:
        # Recrop image and compute rectangles again.
        license_plate = recrop_license_plate_image(license_plate, origin, end,
                                                   image_original)
        character_validator = models.character_validator.CharacterValidator()
        backup_image = Image(image=license_plate.image.data)
        image = pre_process_license_plate_image(license_plate.image,
                                                adaptative=False)
        license_plate.subrects = image.compute_rectangles_for_characters()
        character_validator.remove_wrong_characters(license_plate)

        # If not enough characters detected, binarize image using adaptative method.
        if len(license_plate.subrects) < 2:
            image = pre_process_license_plate_image(backup_image, True)
            license_plate.subrects = image.compute_rectangles_for_characters()
            character_validator.remove_wrong_characters(license_plate)

        license_plate = normalize_characters_character_width(
            license_plate, image_original, character_width, False)

    return license_plate
    def get_crotch_points(front: Person) -> Point:
        crotch_r = front.body[0].max()
        crotch_row = np.where(front.body[0] == crotch_r)
        crotch_c = front.body[1][crotch_row[0].min()]

        crotch_point = Point(crotch_c, crotch_r)

        return crotch_point
    def get_above_pelvis_points(front: Person) -> Tuple[Point, Point]:
        right_above_pelvis_r = front.leg.thigh.right[0].min()
        right_above_pelvis_column = np.where(
            front.leg.thigh.right[0] == right_above_pelvis_r)
        right_above_pelvis_c = front.leg.thigh.right[1][
            right_above_pelvis_column[0].min()]

        left_above_pelvis_r = front.leg.thigh.left[0].min()
        left_above_pelvis_column = np.where(
            front.leg.thigh.left[0] == left_above_pelvis_r)
        left_above_pelvis_c = front.leg.thigh.left[1][
            left_above_pelvis_column[0].max()]

        right_above_pelvis = Point(right_above_pelvis_c, right_above_pelvis_r)
        left_above_pelvis = Point(left_above_pelvis_c, left_above_pelvis_r)

        return left_above_pelvis, right_above_pelvis
Пример #16
0
 def __init__(self, array):
     self.x = int(array[0])
     self.y = int(array[1])
     self.w = int(array[2])
     self.h = int(array[3])
     self.haar_recognized = True
     self.a = self.w * self.h
     self.center = Point(self.x + self.w / 2.0, self.y + self.h / 2.0)
    def get_head_top_points(front: Person,
                            side: Person) -> Tuple[Point, Point]:
        front_top_row = front.all[0].min()
        front_top_cols = np.where(front.all[0] == front.all[0].min())
        front_top_col = front.all[1][front_top_cols[0][0]]

        # if len(front_top_row) == 0:
        #     raise PointExtractFailedException('front.head-top')

        side_top_row = side.all[0].min()
        side_top_cols = np.where(front.all[0] == front.all[0].min())
        side_top_col = side.all[1][side_top_cols[0][0]]

        front_head_top = Point(front_top_col, front_top_row)
        side_head_top = Point(side_top_col, side_top_row)

        return front_head_top, side_head_top
Пример #18
0
 def __init__(self):
     self.ball_in_pallet = True
     self.clock = pygame.time.Clock()
     self.point: Point = Point()
     self.live: Live = Live()
     self.ball: Ball = Ball()
     self.pallet: Pallet = Pallet()
     self.wall: Wall = Wall()
     self.window = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
Пример #19
0
def getPointWithCurve(p):
    curve, x = getRandomCurveAndX(p)

    while (curve.delta() % p == 0 or not curve.quadrTest(x)):
        curve, x = getRandomCurveAndX(p)

    y = curve.calculateY(x)
    point = Point(curve, x, y)

    return point
    def predict(self, license_plate):
        plate = ""

        if len(license_plate.subrects) == 7:
            for index in range(3):
                character = license_plate.subrects[index]
                character_image = license_plate.image.crop(
                    Point(character.x, character.y),
                    Point(character.x + character.w - 1,
                          character.y + character.h - 1))

                if character_image.data.size > 0 and character_image.data is not None:
                    letter = self.letter_recognizer.predict(
                        character_image, True)

                    if isalpha(letter):
                        plate += letter
                    else:
                        plate += "a"
                else:
                    plate += "a"

            for index in range(3, 7):
                character = license_plate.subrects[index]
                character_image = license_plate.image.crop(
                    Point(character.x, character.y),
                    Point(character.x + character.w - 1,
                          character.y + character.h - 1))

                if character_image.data.size > 0 and character_image.data is not None:
                    digit = self.number_recognizer.predict(character_image)

                    if isdigit(digit):
                        plate += digit
                    else:
                        plate += str(1)
                else:
                    plate += str(1)

        else:
            plate = "AAA1111"

        return plate
def get_license_plate_quadrilateral(best_license_plate):
    '''
    Get license plate with quadrilateral.
    '''

    license_plate = copy.deepcopy(best_license_plate)

    # Reescale crop parameters.
    scale = license_plate.w * 1.0 / license_plate.image.width
    license_plate.subrects = sorted(license_plate.subrects,
                                    key=lambda character: character.x)
    character_validator = models.character_validator.CharacterValidator()

    # Adjust positions of character.
    for character in license_plate.subrects:
        character.x = int(character.x * scale + 0.5) + license_plate.x
        character.y = int(character.y * scale + 0.5) + license_plate.y
        character.h = int(character.h * scale + 0.5)
        character.w = int(character.w * scale + 0.5)

    quadrilateral = Quadrilateral()
    quadrilateral.add_point(
        Point(
            license_plate.subrects[0].x - license_plate.subrects[0].w * 2 / 4,
            license_plate.subrects[0].y - license_plate.subrects[0].h * 4 / 5))
    quadrilateral.add_point(
        Point(
            license_plate.subrects[6].x + license_plate.subrects[0].w * 6 / 4,
            license_plate.subrects[6].y - license_plate.subrects[0].h * 4 / 5))
    quadrilateral.add_point(
        Point(
            license_plate.subrects[6].x + license_plate.subrects[0].w * 6 / 4,
            license_plate.subrects[6].y + license_plate.subrects[0].h * 5 / 4))
    quadrilateral.add_point(
        Point(
            license_plate.subrects[0].x - license_plate.subrects[0].w * 2 / 4,
            license_plate.subrects[0].y + license_plate.subrects[0].h * 5 / 4))
    best_license_plate.quadrilateral = quadrilateral

    return best_license_plate
 def filter_using_svm(self, license_plates, image, svm_detector, image_width, image_height):
     '''
     Filter misclassified license plates using SVM.
     '''
     filtered_license_plates = []
     
     for license_plate in license_plates:
         license_plate_image = image.crop(Point(license_plate.x, license_plate.y), \
                                          Point(license_plate.x + license_plate.w, \
                                                license_plate.y + license_plate.h))
         license_plate_image = license_plate_image.resize(image_width, image_height)
         
         if svm_detector.predict(license_plate_image) > 0:
             filtered_license_plates.append(license_plate)
         else:
             license_plate_image_old = Image(image=license_plate_image.data)
             license_plate_image_old.filter_median(size=3)
             
             if svm_detector.predict(license_plate_image_old) > 0:
                 filtered_license_plates.append(license_plate)
                 
     return filtered_license_plates
    def _calculate_mean_caracter_values(self, license_plate):
        '''
        Calculate mean of caracter values.
        '''

        mean_value = 0
        size = 0

        for character in license_plate.subrects:
            character_image = license_plate.image.crop(
                Point(character.x, character.y),
                Point(character.x + character.w - 1,
                      character.y + character.h - 1))

            if character_image.data.size > 0 and character_image.data is not None:
                mean_value += np.mean(character_image.data)
                size += 1

        if size > 0:
            mean_value = int(mean_value / size)

        return mean_value
    def get_bust_points(front: Person,
                        side: Person) -> Tuple[Point, Point, Point, Point]:
        right_upper_arm = front.arm.right.upper
        left_upper_arm = front.arm.left.upper
        # print(np.where(right_upper_arm[1] == front.body[1]))
        front_right_armpit_row, front_right_armpit_col = get_right_armpit(
            right_upper_arm)
        front_left_armpit_row, front_left_armpit_col = get_left_armpit(
            left_upper_arm)

        side_row = front2side(
            (front_right_armpit_row + front_left_armpit_row) // 2, front.body,
            side.body)
        y_coord = np.where(side.body[0] == side_row)
        side_armpit = side.body[1][y_coord[0]]

        bust_left = Point(front_left_armpit_col, front_left_armpit_row)
        bust_right = Point(front_right_armpit_col, front_right_armpit_row)
        bust_back = Point(side_armpit.min(), side_row)
        bust_front = Point(side_armpit.max(), side_row)

        return bust_left, bust_right, bust_back, bust_front
    def get_thigh_points(front: Person,
                         side: Person) -> Tuple[Point, Point, Point, Point]:
        thigh_left_c = front.leg.thigh.right[1].max()
        thigh_left_row = np.where(front.leg.thigh.right[1] == thigh_left_c)
        thigh_left_r = front.leg.thigh.right[0][thigh_left_row[0].max()]
        thigh_right_col = np.where(front.leg.thigh.right[0] == thigh_left_r)
        thigh_right_c = front.leg.thigh.right[1][thigh_right_col[0].min()]
        # thigh_right_r = front.leg.thigh.right[0][thigh_right_row[0].min()]

        thigh_height = int(
            thigh_left_r * (side.all[0].max() - side.all[0].min()) / (front.all[0].max() - front.all[0].min())) + \
                       side.all[0].min()
        thigh_side_row = np.where(side.all[0] == thigh_height)
        thigh_front_c = side.all[1][thigh_side_row[0]].max()
        thigh_back_c = side.all[1][thigh_side_row[0]].min()

        thigh_left = Point(thigh_left_c, thigh_left_r)
        thigh_right = Point(thigh_right_c, thigh_left_r)
        thigh_back = Point(thigh_back_c, thigh_height)
        thigh_front = Point(thigh_front_c, thigh_height)

        return thigh_left, thigh_right, thigh_back, thigh_front
Пример #26
0
def __get_points(feature):
    # try:
    geometry = feature['geometry']
    points_list = []
    if geometry:
        coord_list = geometry['coordinates']

        for point in coord_list:
            for item in point:
                tmp_point = Point(item[0], item[1], item[2])
                points_list.append(tmp_point)

    return points_list
Пример #27
0
    def filter_characters_by_color(self, characters, image):
        '''
        Filter characters by color.
        '''
        filtered_characters = []

        if len(characters) > 0:
            for character in characters:
                x = character.x - abs(character.w - character.h) / 2
                character_image = image.crop(
                    Point(x, character.y),
                    Point(character.x + character.h - 1,
                          character.y + character.h - 1))

                if len(character_image.data) > 0:
                    color_mean = np.mean(character_image.data)

                    if color_mean > 75 and color_mean < 200:
                        filtered_characters.append(character)
        else:
            filtered_characters = characters

        return filtered_characters
    def get_bicep_points(front: Person,
                         side: Person) -> Tuple[Point, Point, Point, Point]:
        right_upper_arm = front.arm.right.upper
        left_upper_arm = front.arm.left.upper
        front_right_armpit_row, front_right_armpit_col = get_right_armpit(
            right_upper_arm)
        front_left_armpit_row, front_left_armpit_col = get_left_armpit(
            left_upper_arm)
        bicep_row = np.where(
            front.arm.right.upper[0] == front_right_armpit_row)
        side_armpit_row = front2side(
            (front_right_armpit_row + front_left_armpit_row) // 2, front.body,
            side.body)
        y_coord = np.where(side.arm.right.upper[0] == side_armpit_row)
        side_armpit = side.arm.right.upper[1][y_coord[0]]

        bicep_left = Point(front_right_armpit_col, front_right_armpit_row)
        bicep_right = Point(right_upper_arm[1][bicep_row[0].min()],
                            front_right_armpit_row)
        bicep_back = Point(side_armpit.min(), side_armpit_row)
        bicep_front = Point(side_armpit.max(), side_armpit_row)

        return bicep_left, bicep_right, bicep_back, bicep_front
Пример #29
0
def add_point(lesson_id):
    form = request.form
    d = dict(
        name=form.get('name', ''),
        target=form.get('target', ''),
        content=form.get('content', ''),
        created_time=timestamp(),
        updated_time=timestamp(),
    )
    point = Point(**d)
    point.save()
    lesson = Lesson.objects.get(id=lesson_id)
    print('debug', lesson.id)

    lesson.insert_point(point)

    # return redirect(url_for('.write_point', lesson_id=point.lesson_id))
    return redirect(url_for('.write_point', lesson_id=lesson_id))
    def read_data(self):
        '''
        Read config data from file.
        '''
        self.license_plates = []
        self.license_plates_text = ""
        self.quadrilaterals.clean()
        self._logger.log(Logger.INFO,
                         "Reading configuration data from " + self.save_path)

        if os.path.isfile(self.save_path):
            f = open(self.save_path, "r")
            read_data = []

            for line in f:
                read_data.append(line.rstrip('\n'))

            if not (len(read_data) == 1 and read_data == "None"
                    or len(read_data) == 0):
                for index_line in range(len(read_data)):
                    line = read_data[index_line]

                    data_list = [x.strip() for x in line.split(',')]

                    total = len(data_list)
                    if total == 9:
                        quadrilateral = self.quadrilaterals.add_quadrilateral()

                        for data_index in range(4):
                            quadrilateral.add_point(
                                Point(int(data_list[data_index * 2]),
                                      int(data_list[data_index * 2 + 1])))

                        self.license_plates.append(data_list[8])

                        if index_line == 0:
                            self.license_plates_text = data_list[8]
                        else:
                            self.license_plates_text += "," + data_list[8]
            f.close()