Skip to content

Commit 5ac0c41

Browse files
authored
Calculate font size dynamically (#23)
1 parent ba2c354 commit 5ac0c41

File tree

4 files changed

+462
-50
lines changed

4 files changed

+462
-50
lines changed

README.md

Lines changed: 74 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,21 @@ Properties:
540540
- Color of the text in RGB format
541541
- Range: 0 - 4294967295
542542
- Default: white (0xFFFFFF)
543+
- If set to default white, automatic brightness-based color selection is used
543544

544-
3. `text-font` (string):
545+
3. `background-color` (unsigned integer):
546+
- Color of the text background in RGB format
547+
- Range: 0 - 4294967295
548+
- Default: black (0x000000)
549+
550+
4. `text-font` (string):
545551
- Font family to use for text rendering
546552
- Default: "Sans"
547553

548-
4. `text-font-size` (unsigned integer):
549-
- Size of the text font in pixels
550-
- Range: 0 - 4294967295
551-
- Default: 14
554+
5. `font-size-percentage` (double):
555+
- Font size as percentage of output image height
556+
- Range: 0.0 - 1.0 (0% - 100%, where 0.1 = 10%)
557+
- Default: 0.09 (9%)
552558

553559
Example pipeline:
554560
```bash
@@ -558,7 +564,7 @@ gst-launch-1.0 avfvideosrc ! \
558564
videoscale ! \
559565
video/x-raw,format=RGB,width=384,height=384 ! \
560566
edgeimpulsevideoinfer ! \
561-
edgeimpulseoverlay stroke-width=3 text-font-size=20 text-color=0x00FF00 ! \
567+
edgeimpulseoverlay stroke-width=3 font-size-percentage=0.12 text-color=0x00FF00 background-color=0x000000 ! \
562568
autovideosink sync=false
563569

564570
# EIM mode (legacy)
@@ -567,7 +573,7 @@ gst-launch-1.0 avfvideosrc ! \
567573
videoscale ! \
568574
video/x-raw,format=RGB,width=384,height=384 ! \
569575
edgeimpulsevideoinfer model-path=<path-to-model> ! \
570-
edgeimpulseoverlay stroke-width=3 text-font-size=20 text-color=0x00FF00 ! \
576+
edgeimpulseoverlay stroke-width=3 font-size-percentage=0.12 text-color=0x00FF00 background-color=0x000000 ! \
571577
autovideosink sync=false
572578
```
573579

@@ -678,6 +684,15 @@ cargo run --example video_inference \
678684
--threshold "5.min_score=0.6" \
679685
--threshold "4.min_anomaly_score=0.35"
680686

687+
# With custom overlay settings
688+
cargo run --example video_inference \
689+
--width 224 \
690+
--height 224 \
691+
--font-size-percentage 0.12 \
692+
--stroke-width 3 \
693+
--text-color 0x00FF00 \
694+
--background-color 0x000000
695+
681696
# EIM mode (legacy)
682697
cargo run --example video_inference -- --model path/to/your/model.eim
683698
```
@@ -755,6 +770,58 @@ Grid cells:
755770

756771
The element will automatically detect the model type and emit appropriate messages. Thresholds can be set for both object detection (`min_score`) and anomaly detection (`min_anomaly_score`) blocks. See [Public API](#public-api-inference-output) for output details.
757772

773+
### Image Inference
774+
Run the image inference example to process a single image file:
775+
```bash
776+
# Basic usage (FFI mode - default)
777+
cargo run --example image_inference -- --image <path-to-image>
778+
779+
# With custom dimensions and overlay settings
780+
cargo run --example image_inference \
781+
--image input.jpg \
782+
--width 224 \
783+
--height 224 \
784+
--font-size-percentage 0.12 \
785+
--stroke-width 3 \
786+
--text-color 0x00FF00 \
787+
--background-color 0x000000
788+
789+
# Save output with overlay
790+
cargo run --example image_inference \
791+
--image input.jpg \
792+
--output output_with_overlay.png \
793+
--font-size-percentage 0.10
794+
795+
# EIM mode (legacy)
796+
cargo run --example image_inference \
797+
--model path/to/your/model.eim \
798+
--image input.jpg
799+
```
800+
801+
This will process a single image and display inference results. The example supports:
802+
- **Input formats**: JPEG, PNG, and other formats supported by GStreamer
803+
- **Output options**: Display with overlay or save to file with overlay
804+
- **Overlay customization**: Font size percentage, stroke width, and text color
805+
- **Model thresholds**: Same threshold support as video inference
806+
807+
Example output:
808+
```
809+
🚀 Starting Edge Impulse Image Inference
810+
📁 Input image: input.jpg
811+
📐 Image dimensions: 224x224
812+
🎨 Format: RGB
813+
🔧 Debug mode: false
814+
▶️ Setting pipeline state to Playing...
815+
🧠 Inference result: {
816+
"classification": {
817+
"cat": 0.85,
818+
"dog": 0.15
819+
}
820+
}
821+
✅ End of stream reached
822+
✅ Image inference completed successfully!
823+
```
824+
758825
### Audio Ingestion
759826
Run the audio ingestion example:
760827
```bash

0 commit comments

Comments
 (0)