vagheshpatel commited on
Commit
3030a91
·
verified ·
1 Parent(s): 1e51c05

Sync light-level-anomaly-detection from metro-analytics-catalog

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. LICENSE +21 -0
  3. README.md +162 -0
  4. expected_output_openvino.gif +3 -0
  5. export_and_quantize.sh +35 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ expected_output_openvino.gif filter=lfs diff=lfs merge=lfs -text
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) Intel Corporation.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE
README.md ADDED
@@ -0,0 +1,162 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ license_link: LICENSE
4
+ library_name: opencv
5
+ tags:
6
+ - opencv
7
+ - intel
8
+ - light-level-anomaly
9
+ - exposure
10
+ - edge-ai
11
+ - metro
12
+ language:
13
+ - en
14
+ ---
15
+
16
+ # Light-Level Anomaly Detection
17
+
18
+ | Property | Value |
19
+ |---|---|
20
+ | **Category** | Image-Quality Analytics (classical computer vision) |
21
+ | **Base Model** | Not applicable -- uses luminance statistics |
22
+ | **Source Framework** | OpenCV |
23
+ | **Supported Precisions** | Not applicable |
24
+ | **Inference Engine** | OpenCV (CPU) |
25
+ | **Hardware** | CPU, GPU (OpenCV UMat optional) |
26
+ | **Detected Class(es)** | Underexposure, overexposure, sudden light change |
27
+
28
+ ---
29
+
30
+ ## Overview
31
+
32
+ Light-Level Anomaly Detection is a Metro Analytics use case that monitors the
33
+ overall brightness of a camera feed and flags abnormal lighting conditions:
34
+ the scene going dark (lights off, lens covered, night), the scene blowing out
35
+ (glare, headlights, overexposure), or a sudden change in light level.
36
+ It tracks the mean luminance of each frame against a rolling baseline and
37
+ raises an event when the level leaves the acceptable band or jumps sharply.
38
+
39
+ A global luminance signal is best measured directly from pixels, so this use
40
+ case intentionally avoids a neural model.
41
+ It is a strong building block for real-time alerting use cases.
42
+
43
+ Typical Metro deployments include:
44
+
45
+ - **Lighting Fault Detection** -- alert when platform or tunnel lighting fails.
46
+ - **Day/Night Transition Handling** -- switch analytics profiles by light level.
47
+ - **Exposure QA** -- flag cameras that are blown out or too dark to analyze.
48
+ - **Tamper Indicator** -- a covered lens shows up as a sudden drop in light.
49
+
50
+ ---
51
+
52
+ ## Prerequisites
53
+
54
+ - Python 3.11+
55
+ - OpenCV and NumPy
56
+
57
+ Create and activate a Python virtual environment before running the sample:
58
+
59
+ ```bash
60
+ python3 -m venv .venv
61
+ source .venv/bin/activate
62
+ pip install opencv-python numpy
63
+ ```
64
+
65
+ ---
66
+
67
+ ## Getting Started
68
+
69
+ ### Download the Sample Video
70
+
71
+ This use case does not export or quantize a model.
72
+ Run the provided script to download the sample test video:
73
+
74
+ ```bash
75
+ chmod +x export_and_quantize.sh
76
+ ./export_and_quantize.sh
77
+ ```
78
+
79
+ The script downloads `test_video.mp4` into the current directory.
80
+
81
+ ### OpenCV Sample
82
+
83
+ The sample below computes the mean luminance of each frame from the V channel
84
+ of HSV, compares it against fixed dark/bright bounds and against a rolling
85
+ baseline, and classifies each frame as `normal`, `dark`, `bright`, or
86
+ `sudden-change`.
87
+ The annotated frames are written to `output_opencv.mp4`.
88
+
89
+ ```python
90
+ import cv2
91
+ import numpy as np
92
+
93
+ INPUT_VIDEO = "test_video.mp4"
94
+ DARK_BOUND = 40.0 # mean luminance below this is underexposed
95
+ BRIGHT_BOUND = 215.0 # mean luminance above this is overexposed
96
+ JUMP_BOUND = 35.0 # frame-to-frame luminance jump that counts as sudden
97
+
98
+ cap = cv2.VideoCapture(INPUT_VIDEO)
99
+ fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
100
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
101
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
102
+ writer = cv2.VideoWriter(
103
+ "output_opencv.mp4", cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
104
+
105
+ prev_level = None
106
+ frame_idx = 0
107
+ anomalies = 0
108
+ while True:
109
+ ok, frame = cap.read()
110
+ if not ok:
111
+ break
112
+ frame_idx += 1
113
+
114
+ v = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)[:, :, 2]
115
+ level = float(np.mean(v))
116
+
117
+ status = "normal"
118
+ if level < DARK_BOUND:
119
+ status = "dark"
120
+ elif level > BRIGHT_BOUND:
121
+ status = "bright"
122
+ elif prev_level is not None and abs(level - prev_level) >= JUMP_BOUND:
123
+ status = "sudden-change"
124
+ prev_level = level
125
+
126
+ if status != "normal":
127
+ anomalies += 1
128
+ print(f"Frame {frame_idx}: LIGHT ANOMALY ({status}) level={level:.1f}",
129
+ flush=True)
130
+ color = (0, 255, 0) if status == "normal" else (0, 0, 255)
131
+ label = f"level={level:.1f} {status}"
132
+ (_, text_height), _ = cv2.getTextSize(
133
+ label, cv2.FONT_HERSHEY_SIMPLEX, 5.0, 2)
134
+ cv2.putText(frame, label, (10, text_height + 10),
135
+ cv2.FONT_HERSHEY_SIMPLEX, 5.0, color, 2)
136
+ writer.write(frame)
137
+
138
+ cap.release()
139
+ writer.release()
140
+ print(f"Light-level anomalies detected: {anomalies}", flush=True)
141
+ ```
142
+
143
+ **Device targets:**
144
+
145
+ - `"CPU"` -- default for OpenCV luminance statistics.
146
+ - `"GPU"` -- wrap frames in `cv2.UMat` to use the OpenCV transparent API on Intel GPUs.
147
+ - `"NPU"` -- not applicable; luminance statistics are not a neural workload.
148
+
149
+ #### Expected Output
150
+
151
+ ![OpenCV expected output](expected_output_openvino.gif)
152
+
153
+ ---
154
+
155
+ ## License
156
+
157
+ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
158
+
159
+ ## References
160
+
161
+ - [OpenCV Color Space Conversions](https://docs.opencv.org/4.x/d8/d01/group__imgproc__color__conversions.html)
162
+ - [OpenCV Operations on Arrays (mean)](https://docs.opencv.org/4.x/d2/de8/group__core__array.html)
expected_output_openvino.gif ADDED

Git LFS Details

  • SHA256: 4fce5e6d4f3e0a9faa88c12ca45d27fc59cdb8d2c7588ce942099ed49881a2e7
  • Pointer size: 132 Bytes
  • Size of remote file: 8.01 MB
export_and_quantize.sh ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ # SPDX-License-Identifier: MIT
3
+ # Copyright (C) Intel Corporation
4
+ #
5
+ # Download the sample video for the light-level-anomaly-detection use case.
6
+ # This use case uses classical computer vision (luminance statistics);
7
+ # no model export or quantization is required.
8
+ # Usage: ./export_and_quantize.sh
9
+
10
+ set -euo pipefail
11
+
12
+ SAMPLE_VIDEO_URL="https://www.pexels.com/download/video/1229535/"
13
+
14
+ # Ask for approval before downloading models and sample files
15
+ echo ""
16
+ echo "This script will download:"
17
+ echo " - Model weights and/or sample files"
18
+ echo ""
19
+ read -p "Continue with downloads? (yes/no): " APPROVAL
20
+ if [[ "${APPROVAL}" != "yes" ]]; then
21
+ echo "Download cancelled by user."
22
+ exit 0
23
+ fi
24
+ echo ""
25
+ echo "--- Downloading sample test video ---"
26
+ if [[ ! -f test_video.mp4 ]]; then
27
+ wget -q -O test_video.mp4 "${SAMPLE_VIDEO_URL}"
28
+ echo "Downloaded: test_video.mp4"
29
+ else
30
+ echo "Already present: test_video.mp4"
31
+ fi
32
+
33
+ echo "--- Done ---"
34
+ echo "Sample : $(pwd)/test_video.mp4"
35
+ echo "Note : This use case requires no model; run the README samples directly."