Skip to content

refactor: eliminate duplicated helpers in zm_detect.py by using pyzm APIs #20

@pliablepixels

Description

@pliablepixels

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions