| #!/usr/bin/env bash |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| set -euo pipefail |
|
|
| |
| OMZ_BASE="https://storage.openvinotoolkit.org/repositories/open_model_zoo/2023.0/models_bin/1" |
|
|
| echo "--- Installing dependencies ---" |
| pip install -qU openvino opencv-python numpy |
|
|
| |
| |
| download_omz_model() { |
| local model="$1" |
| local precision="$2" |
| local dest="intel/${model}/${precision}" |
| mkdir -p "${dest}" |
| local ext |
| for ext in xml bin; do |
| if [[ ! -f "${dest}/${model}.${ext}" ]]; then |
| wget -q -O "${dest}/${model}.${ext}" \ |
| "${OMZ_BASE}/${model}/${precision}/${model}.${ext}" |
| fi |
| done |
| } |
|
|
| |
| echo "" |
| echo "This script will download:" |
| echo " - Model weights and/or sample files" |
| echo "" |
| read -p "Continue with downloads? (yes/no): " APPROVAL |
| if [[ "${APPROVAL}" != "yes" ]]; then |
| echo "Download cancelled by user." |
| exit 0 |
| fi |
| echo "" |
|
|
| echo "--- Downloading person-detection-retail-0013 (FP16) ---" |
| download_omz_model person-detection-retail-0013 FP16 |
| echo "Ready: person-detection-retail-0013" |
|
|
| echo "--- Downloading person-reidentification-retail-0287 (FP16) ---" |
| download_omz_model person-reidentification-retail-0287 FP16 |
| echo "Ready: person-reidentification-retail-0287" |
|
|
| echo "--- Downloading sample surveillance video ---" |
| if [[ ! -f test_video.mp4 ]]; then |
| wget -q -O test_video.mp4 \ |
| "https://github.com/open-edge-platform/edge-ai-resources/raw/main/videos/VIRAT_S_000101.mp4" |
| echo "Downloaded: test_video.mp4" |
| else |
| echo "Already present: test_video.mp4" |
| fi |
|
|
| echo "--- Capturing the reference person from the Camera A enrollment window ---" |
| if [[ ! -f person_a.jpg ]]; then |
| python3 - <<'PY' |
| import cv2 |
| import numpy as np |
| import openvino as ov |
|
|
| DET = "intel/person-detection-retail-0013/FP16/person-detection-retail-0013.xml" |
| core = ov.Core() |
| det = core.compile_model(core.read_model(DET), "CPU") |
| inp = det.input(0) |
| det_h, det_w = inp.shape[2], inp.shape[3] |
|
|
|
|
| def detect_persons(frame, thr=0.6): |
| """Return [(x1, y1, x2, y2), ...] for every person detected in the frame.""" |
| h, w = frame.shape[:2] |
| blob = cv2.resize(frame, (det_w, det_h)) |
| blob = blob.transpose(2, 0, 1)[np.newaxis, ...].astype(np.float32) |
| out = det([blob])[det.output(0)][0][0] |
| boxes = [] |
| for d in out: |
| if float(d[2]) < thr: |
| continue |
| x1 = max(0, int(d[3] * w)) |
| y1 = max(0, int(d[4] * h)) |
| x2 = min(w, int(d[5] * w)) |
| y2 = min(h, int(d[6] * h)) |
| if x2 > x1 and y2 > y1: |
| boxes.append((x1, y1, x2, y2)) |
| return boxes |
|
|
|
|
| |
| |
| |
| cap = cv2.VideoCapture("test_video.mp4") |
| best = {"crop": None, "area": 0} |
| for frame_idx in range(0, 300, 15): |
| cap.set(cv2.CAP_PROP_POS_FRAMES, frame_idx) |
| ok, frame = cap.read() |
| if not ok: |
| break |
| for x1, y1, x2, y2 in detect_persons(frame): |
| area = (x2 - x1) * (y2 - y1) |
| if area > best["area"]: |
| best["area"] = area |
| best["crop"] = frame[y1:y2, x1:x2].copy() |
| cap.release() |
|
|
| if best["crop"] is None or best["crop"].size == 0: |
| raise SystemExit("Could not capture a reference person from the enrollment window") |
| cv2.imwrite("person_a.jpg", best["crop"]) |
| print("Captured person_a.jpg (reference identity from the Camera A enrollment window)") |
| PY |
| else |
| echo "Already present: person_a.jpg" |
| fi |
|
|
| echo "--- Done ---" |
| echo "Detector : intel/person-detection-retail-0013/FP16/person-detection-retail-0013.xml" |
| echo "ReID : intel/person-reidentification-retail-0287/FP16/person-reidentification-retail-0287.xml" |
| echo "Reference : person_a.jpg (identity captured from the Camera A enrollment window)" |
| echo "Scene : test_video.mp4 (wide-area surveillance clip split into two virtual cameras)" |
|
|