martinzink commented on code in PR #2258:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2258#discussion_r3989478034
##########
minifi_rust/extensions/minifi_tensor/src/utils/bounding_box.rs:
##########
@@ -0,0 +1,181 @@
+use image::{Rgb, RgbImage};
+use minifi_native::{MinifiError, PropertyConstraints, PropertySchema,
PropertyType};
+use serde::{Deserialize, Serialize};
+
+#[derive(Serialize, Deserialize, Clone, Debug)]
+pub struct BoundingBox {
+ pub(crate) class_id: usize,
+ pub(crate) confidence: f32,
+ pub(crate) x_min: f32,
+ pub(crate) y_min: f32,
+ pub(crate) x_max: f32,
+ pub(crate) y_max: f32,
+}
+
+fn draw_thick_rect(
+ img: &mut RgbImage,
+ left: u32,
+ top: u32,
+ right: u32,
+ bottom: u32,
+ thickness: u32,
+ color: Rgb<u8>,
+) {
+ let box_width = right.saturating_sub(left);
+ let box_height = bottom.saturating_sub(top);
+
+ for t in 0..thickness {
+ if box_width > 2 * t && box_height > 2 * t {
+ let rect = imageproc::rect::Rect::at((left + t) as i32, (top + t)
as i32)
+ .of_size(box_width - 2 * t, box_height - 2 * t);
+ imageproc::drawing::draw_hollow_rect_mut(img, rect, color);
+ }
+ }
+}
+
+impl BoundingBox {
+ pub fn class_id(&self) -> usize {
+ self.class_id
+ }
+ pub fn confidence(&self) -> f32 {
+ self.confidence
+ }
+
+ pub(crate) fn calculate_intersection_over_union(box1: &BoundingBox, box2:
&BoundingBox) -> f32 {
+ let x_left = box1.x_min.max(box2.x_min);
+ let y_top = box1.y_min.max(box2.y_min);
+ let x_right = box1.x_max.min(box2.x_max);
+ let y_bottom = box1.y_max.min(box2.y_max);
+
+ if x_right < x_left || y_bottom < y_top {
+ return 0.0;
+ }
+
+ let intersection_area = (x_right - x_left) * (y_bottom - y_top);
+ let box1_area = (box1.x_max - box1.x_min) * (box1.y_max - box1.y_min);
+ let box2_area = (box2.x_max - box2.x_min) * (box2.y_max - box2.y_min);
Review Comment:
👍 [fix 0/0 in
IoU](https://github.com/apache/nifi-minifi-cpp/pull/2258/commits/a21fc1c18ef1e017075a37c1917b214ad2f90dee)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]