EP09_06 — 🔴 Integrated Pipeline: From Detection to Real-World Measurement
9.10.6 EP09_06 🔴 Integrated Pipeline: From Detection to Real-World Measurement
This final exercise integrates the two detection exercises and the principle of photogrammetry presented in the section “Photogrammetry and Scale Reference” — exactly the same calculation implemented in the scale-reference measurement figure in this chapter. The scenario reproduces a realistic situation: a detector (Faster R-CNN or YOLO) generates several overlapping candidate boxes for the same object of interest; after filtering them by NMS, the surviving box with the highest confidence is used, together with a reference box of known real width (such as the \(8.56\) cm card), to estimate the real dimensions of the detected object.
9.10.6.1 📋 Implementation Guidelines
Known reference: Read the real value \(L_{ref}\) (real width of the reference object, in cm) and then the four real values \(x_1\ y_1\ x_2\ y_2\) of its bounding box in pixels (already known, with no need for detection).
Candidates of the object to measure: Read the integer \(N\) (number of candidate boxes produced by the detector for the object of interest) and the real threshold \(\tau\); then read the \(N\) lines of candidate boxes, each with \(x_1\ y_1\ x_2\ y_2\ \text{score}\).
Step 1 — NMS: Apply exactly the Non-Maximum Suppression algorithm from EP09_04 to the \(N\) candidate boxes, using the threshold \(\tau\), to eliminate redundant detections of the same object.
Step 2 — Final box selection: After NMS, the box with the highest score among those retained is the final detection of the object (the input guarantees that all candidate boxes correspond to a single physical object, so the first box selected by NMS is already the final result).
Step 3 — Scale-reference measurement: Calculate the ratio \(\text{cm/pixel} = L_{ref} / \text{reference width in pixels}\) and apply it to both the width and height (in pixels) of the final object box, obtaining its estimated real dimensions in centimeters.
Output: First, one line per box retained after NMS (same format as EP09_04): index score. Then the line Total kept: X. Finally, the line Object: L x A cm, where \(L\) and \(A\) are the estimated width and height of the object, each with 2 decimal places.
9.10.6.2 📌 Computational Constraints
Reuse the NMS from EP09_04 in full — same tie-breaking rule, same suppression criterion (\(\text{IoU} > \tau\)).
The reference does not undergo NMS: its box is given directly, without competing candidates.
Single ratio for width and height: just as in the photogrammetry figure in the chapter, the same cm/pixel ratio (derived from the reference width) is applied to both the width and height of the object — there is no separate vertical calibration.
9.10.6.3 🧠 Theoretical Foundation
Step
Chapter concept
Multiple candidate boxes
Raw output of a detector such as Faster R-CNN or YOLO, before post-processing
NMS (EP09_04)
Filters redundant detections, keeping only the most confident one for the object
Known scale reference
Same principle as the \(8.56\) cm card used in the section “Photogrammetry and Scale Reference”
Pixel → centimeter conversion
Simple rule of three: \(\text{cm/pixel} = L_{ref} / w_{ref\_px}\), applied to the final object box
9.10.6.4 🧩 morph.py Methods That May Help
mm.IoU(boxA, boxB) — the same function suggested in EP09_04, here reused within the NMS step of this integrated pipeline (remember the format conversion: \(w = x_2-x_1\), \(h = y_2-y_1\)).
If you have already solved EP09_04 by encapsulating NMS in your own function, this is the ideal time to reuse that code — integrating modules that have already been tested individually is exactly the engineering practice this exercise aims to reinforce.
9.10.6.5 📦 Input and Output Specification (VPL)
Input:
Line 1: Real \(L_{ref}\).
Line 2: \(x_1\ y_1\ x_2\ y_2\) of the reference box.
Line 3: Integer \(N\) and real \(\tau\).
Next \(N\) lines: \(x_1\ y_1\ x_2\ y_2\ \text{score}\) of the candidate boxes for the object.