martinzink commented on code in PR #2258:
URL: https://github.com/apache/nifi-minifi-cpp/pull/2258#discussion_r4102811266
##########
minifi_rust/extensions/minifi_tensor/src/processors/draw_bounding_box.rs:
##########
@@ -0,0 +1,168 @@
+use crate::utils::bounding_box::{BoundingBox, BoundingBoxes};
+use image::Rgb;
+use minifi_native::macros::ComponentIdentifier;
+use minifi_native::{
+ FlowFileTransform, GetAttribute, GetControllerService, GetId, GetProperty,
InputStream, Logger,
+ MinifiError, OutputAttribute, ProcessError, ProcessorDefinition,
ProcessorInputRequirement,
+ Property, PropertyConstraints, PropertyType, Relationship, RouteErrorExt,
Schedule,
+ TransformedFlowFile,
+};
+use minifi_native::{PropertyDefinition, PropertySchema, property_definitions};
+use std::io::Cursor;
+
+pub(crate) const SUCCESS: Relationship = Relationship {
+ name: "success",
+ description: "Flowfiles are routed here after drawing the bounding boxes",
+};
+
+pub(crate) const FAILURE: Relationship = Relationship {
+ name: "failure",
+ description: "Invalid FlowFiles are routed here",
+};
+
+pub(crate) const BOUNDING_BOXES: Property<BoundingBoxes> = Property::new(
+ "Bounding boxes",
+ "JSON array of bounding boxes to draw onto the image (fields class_id,
confidence, x_min, \
+ y_min, x_max, y_max; coordinates normalised to [0,1] against the image).
Typically the \
+ attribute produced by an upstream DetectObject or FilterBoundingBoxes
processor.",
+)
+.with_default("${enrichment.value}")
+.supports_expression_language();
+
+const LINE_THICKNESS: Property<u32> = Property::new(
+ "Line thickness",
+ "Thickness in pixels of the drawn box outline.",
+)
+.with_default("5");
+
+const LINE_COLOR: Property<LineColor> = Property::new(
+ "Line color",
+ "Outline colour as '[R, G, B]' u8 channels (0-255).",
+)
+.with_default("[0, 255, 0]");
+
+#[derive(Debug, ComponentIdentifier)]
+pub(crate) struct DrawBoundingBox {}
+
+impl Schedule for DrawBoundingBox {
+ fn schedule<Ctx: GetProperty, L: Logger>(
+ _context: &Ctx,
+ _logger: &L,
+ ) -> Result<Self, MinifiError>
+ where
+ Self: Sized,
+ {
+ Ok(Self {})
+ }
+}
+
+struct LineColor {}
+
+impl PropertySchema for LineColor {
+ const CONSTRAINT: Option<PropertyConstraints> = None;
+ const IS_REQUIRED: bool = false;
+}
+
+impl PropertyType for LineColor {
+ type Output = Rgb<u8>;
+
+ fn parse(s: &str) -> Result<Self::Output, MinifiError> {
+ let clean_str = s.trim().trim_matches(|c| c == '[' || c == ']');
+ let mut iter = clean_str.split(',');
+
+ let mut next_channel = || {
+ iter.next()
+ .ok_or_else(|| MinifiError::validation("expected R,G,B color
channels"))?
+ .trim()
+ .parse::<u8>()
+ .map_err(MinifiError::from)
+ };
+
+ Ok(Rgb::<u8>([
+ next_channel()?,
+ next_channel()?,
+ next_channel()?,
+ ]))
Review Comment:
good catch, and Ive changed my mind about this format its better to just
allow hexcodes how about? [LineColor
changes](https://github.com/apache/nifi-minifi-cpp/pull/2258/commits/28c90348254dab7c307b6876061816620c3a044e)
--
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]