def crop(self, bbox: BoundingBox, boundary_circle_center_coord: Coordinate, boundary_circle_rad: int): """ @TODO 이 부분 뺄 것 """ circle_crop_helper = CircleCropHelper(img_object=self.img_object, center_coord=Coordinate( 1205, 1062), rad=757) circle_crop_helper.crop_circle(inverse=True) outer_circle_img_object = circle_crop_helper.cropped_img_object rectangle_crop_helper = RectangleCropHelper( img_object=outer_circle_img_object) rectangle_img_list = list() rectangle_crop_helper.crop_rectangle(bbox=bbox) cropped_img_object = rectangle_crop_helper.cropped_img_object # Checking defect for defect in self.defect_list: defect: Defect # Crop C 에서 defect 가 있을 때 if defect.is_defect_in_cropped_img( img_center_coord=boundary_circle_center_coord, margin_min=boundary_circle_rad, margin_max=2200): if defect.is_defect_in_bounding_box(bbox=bbox): rectangle_crop_helper.relocate_defect( img_object=cropped_img_object, defect=defect) rectangle_img_list.append(cropped_img_object) return rectangle_img_list
def crop(self, bbox_list: list, angle_list: list, boundary_circle_center_coord: Coordinate, boundary_circle_rad: int): """ @TODO 이 부분 뺄 것 """ circle_crop_helper = CircleCropHelper(img_object=self.img_object, center_coord=Coordinate( 1205, 1062), rad=757) circle_crop_helper.crop_circle(inverse=True) outer_circle_img_object = circle_crop_helper.cropped_img_object rectangle_crop_helper = RectangleCropHelper( img_object=outer_circle_img_object) rectangle_img_list = list() for bbox, angle in zip(bbox_list, angle_list): bbox: BoundingBox rectangle_crop_helper.crop_rectangle(bbox=bbox) cropped_img_object = rectangle_crop_helper.cropped_img_object # Checking Defect for defect in self.defect_list: defect: Defect # Crop D 에서 defect 가 있을 때 if defect.is_defect_in_cropped_img( img_center_coord=boundary_circle_center_coord, margin_min=boundary_circle_rad, margin_max=2200): if defect.is_defect_in_bounding_box(bbox=bbox): rectangle_crop_helper.relocate_defect( img_object=cropped_img_object, defect=defect) # Rotate with angle cropped_img_object_width = cropped_img_object.img.shape[1] cropped_img_object_height = cropped_img_object.img.shape[0] cropped_img_object_center_coord = Coordinate( x=cropped_img_object_width // 2, y=cropped_img_object_height // 2) rotate_cropped_img = cv2.warpAffine( cropped_img_object.img, cv2.getRotationMatrix2D(cropped_img_object_center_coord.value, angle, scale=1), (cropped_img_object_width, cropped_img_object_height)) cropped_img_object.img = rotate_cropped_img rectangle_img_list.append(cropped_img_object) return rectangle_img_list
def crop(self, bbox_list: list, boundary_circle_center_coord: Coordinate, boundary_circle_rad: int, flip_index: int = 0): """ @TODO 이 부분 뺄 것 """ circle_crop_helper = CircleCropHelper(img_object=self.img_object, center_coord=Coordinate( 1205, 1062), rad=757) circle_crop_helper.crop_circle(inverse=True) outer_circle_img_object = circle_crop_helper.cropped_img_object rectangle_crop_helper = RectangleCropHelper( img_object=outer_circle_img_object) rectangle_img_list = list() for idx, bbox in enumerate(bbox_list): rectangle_crop_helper.crop_rectangle(bbox=bbox) cropped_img_object = rectangle_crop_helper.cropped_img_object # Checking defect for defect in self.defect_list: defect: Defect # Crop C 에서 defect 가 있을 때 if defect.is_defect_in_cropped_img( img_center_coord=boundary_circle_center_coord, margin_min=boundary_circle_rad, margin_max=2200): if defect.is_defect_in_bounding_box(bbox=bbox): rectangle_crop_helper.relocate_defect( img_object=cropped_img_object, defect=defect) # Flip the image if idx == flip_index: flipped_cropped_img = cv2.flip(cropped_img_object.img, 1) # 1 은 좌우 반전 cropped_img_object.img = flipped_cropped_img rectangle_img_list.append(cropped_img_object) return rectangle_img_list
def crop(self, inner_circle_rad: int, inner_circle_center_coord: Coordinate, outer_circle_rad: int, outer_circle_center_coord: Coordinate, ring_small_rad: int, angle: int): inner_circle_crop_helper = CircleCropHelper( img_object=self.img_object, center_coord=inner_circle_center_coord, rad=inner_circle_rad) inner_circle_crop_mask = inner_circle_crop_helper.get_circle_mask( inverse=True) outer_circle_crop_helper = CircleCropHelper( img_object=self.img_object, center_coord=outer_circle_center_coord, rad=outer_circle_rad) outer_circle_crop_mask = outer_circle_crop_helper.get_circle_mask( inverse=False) crop_ring_mask = inner_circle_crop_mask * outer_circle_crop_mask ring_crop_helper = RingCropHelper(img_object=self.img_object, big_rad=outer_circle_rad, small_rad=ring_small_rad) # Switching image img_original = self.img_object.img self.img_object.img = self.img_object.img * crop_ring_mask ring_crop_helper.crop_ring(center_coord=outer_circle_center_coord) crop_rotate_ring_piece_list = ring_crop_helper.get_crop_rotate_ring_piece_list( angle=angle) self.img_object.img = img_original # Checking defect for defect in self.defect_list: # Crop C 바깥에 위치한 경우 is_first_circle_outside = defect.is_defect_in_cropped_img( img_center_coord=inner_circle_center_coord, margin_min=inner_circle_rad, margin_max=2000 # Temp ) # Crop D 외곽 반지름 안에 위치한 경우 is_second_circle_inside = defect.is_defect_in_cropped_img( img_center_coord=outer_circle_center_coord, margin_min=1, # Temp margin_max=outer_circle_rad) if is_first_circle_outside and is_second_circle_inside: for crop_rotate_ring_piece in crop_rotate_ring_piece_list: ring_crop_helper.relocate_defect( img_object=crop_rotate_ring_piece, defect=defect) return crop_rotate_ring_piece_list
def crop(self, rad: int, center_coord: Coordinate): circle_crop_helper = CircleCropHelper(img_object=self.img_object, center_coord=center_coord, rad=rad) circle_crop_helper.crop_circle(inverse=False) cropped_img_object = circle_crop_helper.cropped_img_object for defect in self.defect_list: if defect.is_defect_in_cropped_img(img_center_coord=center_coord, margin_min=0, margin_max=rad): circle_crop_helper.relocate_defect( img_object=cropped_img_object, defect=defect) return [cropped_img_object]
def crop(self, rad: int, center_coord: Coordinate): circle_crop_helper = CircleCropHelper(img_object=self.img_object, center_coord=center_coord, rad=rad) circle_crop_helper.crop_circle(inverse=True) cropped_img_object = circle_crop_helper.cropped_img_object # Checking defect for defect in self.defect_list: defect: Defect # Crop D 에서 defect 가 있을 때 if defect.is_defect_in_cropped_img(img_center_coord=center_coord, margin_min=rad, margin_max=2200): circle_crop_helper.relocate_defect( img_object=cropped_img_object, defect=defect) return [cropped_img_object]