Problem
zm_detect.py inlines several helper functions that duplicate or work around pyzm functionality. This creates maintenance burden, fragile patterns, and DRY violations across both repos.
What needs fixing
1. _draw_bbox() should use DetectionResult.annotate() (HIGH)
zm_detect.py:49-76 inlines a 28-line OpenCV drawing function that closely mirrors pyzm's DetectionResult.annotate(). The code destructures result.to_dict() into parallel arrays, then passes them into the inlined function — defeating pyzm's structured API.
Fix (pyzm): Extend DetectionResult.annotate() with:
polygons param for zone polygon overlay
write_conf param (bool) to toggle confidence display
poly_color / poly_thickness params
Fix (zmeventnotification): Replace _draw_bbox(...) call with result.annotate(...). Remove _draw_bbox function.
2. Event.save_objdetect() for writing detection artifacts (MEDIUM)
zm_detect.py:207-222 manually constructs paths and calls cv2.imwrite / json.dump to write objdetect.jpg and objects.json to the event directory. Writing objdetect.jpg is a ZM convention — it belongs alongside Event.update_notes() and Event.tag().
Fix (pyzm): Add Event.save_objdetect(image, metadata) method.
Fix (zmeventnotification): Replace manual path construction + cv2.imwrite + json.dump with ev.save_objdetect(...). Debug image writing stays in zm_detect.py (not a ZM convention).
3. Recursive secret resolution in process_config (MEDIUM)
process_config() resolves !token secrets for flat config values but skips nested dicts (ml_sequence, stream_sequence). This forces zm_detect.py:119-123 to re-load the secrets file and apply a fragile str() → regex → ast.literal_eval() workaround.
Fix (zmeventnotification): Make _resolve_secret recursive so it walks nested dicts/lists. Then remove _read_config(), _template_fill(), and the double secret loading from zm_detect.py.
Related
Problem
zm_detect.pyinlines several helper functions that duplicate or work around pyzm functionality. This creates maintenance burden, fragile patterns, and DRY violations across both repos.What needs fixing
1.
_draw_bbox()should useDetectionResult.annotate()(HIGH)zm_detect.py:49-76inlines a 28-line OpenCV drawing function that closely mirrors pyzm'sDetectionResult.annotate(). The code destructuresresult.to_dict()into parallel arrays, then passes them into the inlined function — defeating pyzm's structured API.Fix (pyzm): Extend
DetectionResult.annotate()with:polygonsparam for zone polygon overlaywrite_confparam (bool) to toggle confidence displaypoly_color/poly_thicknessparamsFix (zmeventnotification): Replace
_draw_bbox(...)call withresult.annotate(...). Remove_draw_bboxfunction.2.
Event.save_objdetect()for writing detection artifacts (MEDIUM)zm_detect.py:207-222manually constructs paths and callscv2.imwrite/json.dumpto writeobjdetect.jpgandobjects.jsonto the event directory. Writingobjdetect.jpgis a ZM convention — it belongs alongsideEvent.update_notes()andEvent.tag().Fix (pyzm): Add
Event.save_objdetect(image, metadata)method.Fix (zmeventnotification): Replace manual path construction + cv2.imwrite + json.dump with
ev.save_objdetect(...). Debug image writing stays in zm_detect.py (not a ZM convention).3. Recursive secret resolution in
process_config(MEDIUM)process_config()resolves!tokensecrets for flat config values but skips nested dicts (ml_sequence,stream_sequence). This forceszm_detect.py:119-123to re-load the secrets file and apply a fragilestr()→ regex →ast.literal_eval()workaround.Fix (zmeventnotification): Make
_resolve_secretrecursive so it walks nested dicts/lists. Then remove_read_config(),_template_fill(), and the double secret loading fromzm_detect.py.Related