General engineering
AuraScore 81/100

Crane Zone Safety Video Pipeline Automation Script

Automate CCTV stream sampling, spatial zone masking, and frame export for construction safety monitoring.

Use this template when setting up computer vision preprocessing pipelines on active construction jobsites. It produces an automated frame sampling script that enforces shift schedules and crops high-risk work zones.

Template

Role: Senior Site Automation Engineer with deep expertise in edge computer vision pipelines for high-rise developments.

Context

  • Camera Stream Endpoint: {{camera_rtsp_stream}}
  • Frame Sampling Interval: {{target_frame_rate}}
  • Critical Exclusion Polygon: {{bounding_zone_polygon}}
  • Cloud Object Storage: {{storage_bucket_uri}}
  • Hardware Acceleration ID: {{gpu_device_id}}
  • Active Site Shift Hours: {{site_shift_schedule}}

Task

Write a Python automation script using OpenCV to ingest construction site RTSP camera streams, verify active shift operating hours, apply spatial masking to restricted crane swing zones, and upload sampled frames to object storage for automated safety inspection.

Method

  1. Initialize hardware configuration binding to {{gpu_device_id}} and validating OpenCV video capture backend drivers.
  2. Parse active shift boundaries from {{site_shift_schedule}} and set up a schedule check to pause execution during off-hours.
  3. Open a stable video stream loop connecting to {{camera_rtsp_stream}} with automatic reconnect handling on timeout.
  4. Sample frames selectively based on {{target_frame_rate}} rather than decoding every raw video frame to save compute.
  5. Convert {{bounding_zone_polygon}} coordinates into a spatial mask and extract the designated high-risk region of interest.
  6. Normalize and compress extracted region frames into JPEG format with standardized metadata headers.
  7. Batch upload compressed frames to {{storage_bucket_uri}} using asynchronous cloud client operations.
  8. Log throughput performance, frame drop counts, and connection latency on a recurring 5-minute schedule.

Constraints

  • The script MUST drop corrupted video packets without blocking the main event thread.
  • Frame uploads MUST include ISO-8601 timestamps and camera identifiers embedded in object key naming.
  • CPU utilization MUST NOT exceed 40% when hardware acceleration via {{gpu_device_id}} is enabled.
  • Raw full-resolution frames MUST NOT be saved to local gateway storage to avoid disk exhaustion.

Output format

Provide the complete response structured under these headings:

  1. Dependency Configuration (required packages and OpenCV GPU compilation flags).
  2. Complete Python Processing Pipeline (production-ready script with inline logging).
  3. Operational Monitoring Commands (commands to verify pipeline health and test RTSP connectivity).

Self-review

  • Confirm that {{bounding_zone_polygon}} handling accounts for varying stream resolutions dynamically.
  • Ensure all 6 context variables ({{camera_rtsp_stream}}, {{target_frame_rate}}, {{bounding_zone_polygon}}, {{storage_bucket_uri}}, {{gpu_device_id}}, {{site_shift_schedule}}) are consumed.
  • Verify stream reconnect logic implements exponential backoff to avoid flooding site network switches.
AuraScore breakdown
81/100Provisional
Instruction clarity15/15 · Strong

Explicit role, a named task, and discrete steps the model can follow.

Context architecture12/12 · Strong

Background, inputs and variables the model needs before it starts.

Constraint engineering12/12 · Strong

Hard boundaries — what the model must and must not do.

Output specification6/14 · Thin

A named, field-level shape for the response.

Reasoning structure10/10 · Strong

Ordered work items that force analysis before an answer.

Model compatibility10/10 · Strong

Length and structure that travel across frontier models.

Token efficiency5/10 · Thin

Signal density — instruction weight without padding.

Reusability7/7 · Strong

Documented variables so the scaffold adapts to new inputs.

Robustness3/5 · Adequate

Quality bar, assumptions and behaviour when inputs are thin.

Observed performance1/5 · Thin

How much real usage the template has behind it.

developers
developers-general
real-estate-construction
opencv
python
video-streaming