Skip to content

fix: PPE detection order and exclusion zone counting in safety_app - #22

Merged
codelion merged 1 commit into
securade:mainfrom
Emart29:claude/happy-curie-4ygv4i
Oct 10, 2026
Merged

codelion merged 1 commit into
securade:mainfrom
Emart29:claude/happy-curie-4ygv4i

Conversation

@Emart29

@Emart29 Emart29 commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Fixes the three behaviours marked xfail in #21, and the duplicate detect_zone in singleinference_yolov7.py.

  1. detect_ppe depends on detection order. flag was reassigned for every person, so only the last person in box_list decided the result. It now reports a violation if any person matches.
  2. detect_zone and an empty polygon. A policy saved without a drawn zone reached detect_zone as [] and raised IndexError. A missing polygon, or one with fewer than three points (which shapely also rejects), now means there is no zone to check: safety_app.detect_zone returns False, and SingleInference_YOLOV7.detect_zone returns the unannotated image instead of None, which the Exclusion Zones page passed to st.image.
  3. max_allowed counts the whole frame. It is now compared with the number of objects of that class whose box intersects the zone, in both copies.

The xfail markers are removed. The PPE test now checks both detection orders, and the empty-polygon test covers None, [] and a two-point polygon. All 83 unit tests pass; the updated tests fail against the previous safety_app.py.

The singleinference_yolov7.py change isn't covered by the unit job since that module needs torch. I checked its detect_zone with fixed detections: with max_allowed=1, one person inside and one outside is no longer drawn red, and an empty polygon returns the image instead of failing in cv2.fillPoly.

detect_ppe overwrote its result for every person, so only the last
person in the frame decided whether a violation was reported. Keep the
result if any person matches.

detect_zone compared max_allowed with the number of objects in the
whole frame; count only objects whose box intersects the zone. A
missing polygon, or one with fewer than three points, now means no
zone to check instead of raising an error. The same zone fixes are
applied to SingleInference_YOLOV7.detect_zone, which returns the
unannotated image when there is no polygon.

Drop the xfail markers from the tests that covered these.
@codelion
codelion merged commit e3587dc into securade:main Oct 10, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants