Small improvements and fixes.

This commit is contained in:
Daniel
2025-01-17 16:24:37 +01:00
parent 1bd58deede
commit 8a249a2f16
3 changed files with 40 additions and 11 deletions

View File

@ -189,9 +189,15 @@ class BoxCrop:
self.fill_value = fill_value
def calc_params(self, ishape, bbox):
start_x, start_y, end_x, end_y = bbox[0], bbox[1], bbox[2], bbox[3]
img_h, img_w = ishape[:2]
target_h, target_w = self.target_size
# Round the bounding box coordinates
start_x = math.floor(bbox[0])
start_y = math.floor(bbox[1])
end_x = math.ceil(bbox[2])
end_y = math.ceil(bbox[3])
# Calculate original bounding box center
center_x = (start_x + end_x) / 2.0
center_y = (start_y + end_y) / 2.0
@ -231,8 +237,8 @@ class BoxCrop:
# Define the new box coordinates
new_start_x = max(0, start_x)
new_start_y = max(0, start_y)
new_end_x = min(ishape[1] - 1, end_x)
new_end_y = min(ishape[0] - 1, end_y)
new_end_x = min(img_w - 1, end_x)
new_end_y = min(img_h - 1, end_y)
new_box = [new_start_x, new_start_y, new_end_x, new_end_y]
# Calculate resized crop size
@ -344,7 +350,6 @@ class RTMDet(BaseModel):
return np.array([])
# Drop boxes with too small area
boxes = boxes.astype(np.float32)
areas = (boxes[:, 2] - boxes[:, 0]) * (boxes[:, 3] - boxes[:, 1])
keep = areas >= self.min_area
boxes = boxes[keep]
@ -386,10 +391,7 @@ class RTMPose(BaseModel):
def preprocess(self, image: np.ndarray, bboxes: np.ndarray):
cutouts = []
for i in range(len(bboxes)):
bbox = np.asarray(bboxes[i])[0:4]
bbox += np.array([-0.5, -0.5, 0.5 - 1e-8, 0.5 - 1e-8])
bbox = bbox.round().astype(np.int32)
region = self.boxcrop.crop_resize_box(image, bbox)
region = self.boxcrop.crop_resize_box(image, bboxes[i])
tensor = np.asarray(region).astype(self.input_types[0], copy=False)
cutouts.append(tensor)