Skip to content

Commit

Permalink
feat: add bbox thickness option
Browse files Browse the repository at this point in the history
  • Loading branch information
oatiz committed Jun 20, 2024
1 parent 6c72374 commit fe13994
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions src/core/annotator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub struct Annotator {
without_bboxes_name: bool,
without_bboxes_text_bg: bool,
bboxes_text_color: Rgba<u8>,
bboxes_thickness: u8,

// About keypoints
without_keypoints: bool,
Expand Down Expand Up @@ -71,6 +72,7 @@ impl Default for Annotator {
without_bboxes_conf: false,
without_bboxes_name: false,
bboxes_text_color: Rgba([0, 0, 0, 255]),
bboxes_thickness: 1,
without_bboxes_text_bg: false,
without_mbrs: false,
without_mbrs_conf: false,
Expand Down Expand Up @@ -136,6 +138,11 @@ impl Annotator {
self
}

pub fn withbboxes_thickness(mut self, thickness: u8) -> Self {
self.bboxes_thickness = thickness;
self
}

pub fn without_keypoints(mut self, x: bool) -> Self {
self.without_keypoints = x;
self
Expand Down Expand Up @@ -362,12 +369,32 @@ impl Annotator {
pub fn plot_bboxes(&self, img: &mut RgbaImage, bboxes: &[Bbox]) {
for bbox in bboxes.iter() {
// bbox
imageproc::drawing::draw_hollow_rect_mut(
img,
imageproc::rect::Rect::at(bbox.xmin().round() as i32, bbox.ymin().round() as i32)
if self.bboxes_thickness <= 1 {
imageproc::drawing::draw_hollow_rect_mut(
img,
imageproc::rect::Rect::at(
bbox.xmin().round() as i32,
bbox.ymin().round() as i32,
)
.of_size(bbox.width().round() as u32, bbox.height().round() as u32),
image::Rgba(self.get_color(bbox.id() as usize).into()),
);
image::Rgba(self.get_color(bbox.id() as usize).into()),
);
} else {
for i in 0..self.bboxes_thickness {
imageproc::drawing::draw_hollow_rect_mut(
img,
imageproc::rect::Rect::at(
(bbox.xmin().round() as i32) - (i as i32),
(bbox.ymin().round() as i32) - (i as i32),
)
.of_size(
(bbox.width().round() as u32) + (2 * i as u32),
(bbox.height().round() as u32) + (2 * i as u32),
),
image::Rgba(self.get_color(bbox.id() as usize).into()),
);
}
}

// label
if !self.without_bboxes_name || !self.without_bboxes_conf {
Expand Down

0 comments on commit fe13994

Please sign in to comment.