vagheshpatel commited on
Commit
85d519e
·
verified ·
1 Parent(s): fb1ba43

Update native RC1 samples and supported device documentation

Browse files
Files changed (3) hide show
  1. README.md +26 -2
  2. dlstreamer_sample.py +82 -0
  3. opencv_sample.py +56 -0
README.md CHANGED
@@ -47,9 +47,13 @@ Typical Metro deployments include:
47
 
48
  ## Prerequisites
49
 
 
 
 
 
50
  - Python 3.11+
51
  - [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
52
- - [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html) (latest version)
53
 
54
  Create and activate a Python virtual environment before running the scripts:
55
 
@@ -85,7 +89,16 @@ removes shadows and noise, groups foreground pixels into bounding boxes, and
85
  writes the annotated result to `output_opencv.mp4`.
86
  It prints one line per frame with the number of motion regions found.
87
 
 
 
 
88
  ```python
 
 
 
 
 
 
89
  import cv2
90
  import numpy as np
91
 
@@ -137,6 +150,7 @@ cap.release()
137
  writer.release()
138
  print(f"Motion detected in {motion_frames} frames", flush=True)
139
  ```
 
140
 
141
  **Device targets:**
142
 
@@ -157,7 +171,16 @@ result to `output_dlstreamer.mp4`.
157
  Using `appsink` keeps the pipeline headless-safe and avoids VA-API
158
  zero-copy elements that fail over SSH.
159
 
 
 
 
160
  ```python
 
 
 
 
 
 
161
  import gi
162
 
163
  gi.require_version("Gst", "1.0")
@@ -235,6 +258,7 @@ if writer:
235
  writer.release()
236
  print(f"Motion detected in {motion_frames} frames", flush=True)
237
  ```
 
238
 
239
  The decode stack runs on the CPU; to offload decode to an Intel GPU, install
240
  the DLStreamer VA-API plugins and prepend `vaapidecodebin` in environments that
@@ -254,5 +278,5 @@ Licensed under the MIT License. See [LICENSE](LICENSE) for details.
254
 
255
  - [OpenCV Background Subtraction Tutorial](https://docs.opencv.org/4.x/d1/dc5/tutorial_background_subtraction.html)
256
  - [OpenCV MOG2 Background Subtractor](https://docs.opencv.org/4.x/d7/d7b/classcv_1_1BackgroundSubtractorMOG2.html)
257
- - [Intel DLStreamer](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/index.html)
258
  - [OpenVINO Documentation](https://docs.openvino.ai/)
 
47
 
48
  ## Prerequisites
49
 
50
+ Target stack: Intel DLStreamer **2026.3.0 RC1** with the matching OpenVINO GenAI bundle **2026.5.0.0.dev20261030** (OpenVINO Runtime **2026.5.0.dev20261030**).
51
+ Use the [native RC1 setup](../README.md#native-rc1-runtime) before running these samples; this is a development stack, not a stable release.
52
+ See the [device validation matrix](../DEVICE_SUPPORT_MATRIX.md) for measured CPU, GPU, and NPU results.
53
+
54
  - Python 3.11+
55
  - [Install OpenVINO](https://docs.openvino.ai/2026/get-started/install-openvino.html) (latest version)
56
+ - [Install Intel DLStreamer](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/get_started/install/install_guide_ubuntu.html) (latest version)
57
 
58
  Create and activate a Python virtual environment before running the scripts:
59
 
 
89
  writes the annotated result to `output_opencv.mp4`.
90
  It prints one line per frame with the number of motion regions found.
91
 
92
+ The full sample is in [opencv_sample.py](opencv_sample.py); run it with `python3 opencv_sample.py` or copy the code below.
93
+
94
+ <!-- sample: opencv_sample.py -->
95
  ```python
96
+ # SPDX-License-Identifier: MIT
97
+ # Copyright (C) Intel Corporation
98
+ #
99
+ # Motion Detection: OpenCV sample.
100
+ # See README.md for prerequisites and inputs. Run: python3 opencv_sample.py
101
+
102
  import cv2
103
  import numpy as np
104
 
 
150
  writer.release()
151
  print(f"Motion detected in {motion_frames} frames", flush=True)
152
  ```
153
+ <!-- /sample -->
154
 
155
  **Device targets:**
156
 
 
171
  Using `appsink` keeps the pipeline headless-safe and avoids VA-API
172
  zero-copy elements that fail over SSH.
173
 
174
+ The full sample is in [dlstreamer_sample.py](dlstreamer_sample.py); run it with `python3 dlstreamer_sample.py` or copy the code below.
175
+
176
+ <!-- sample: dlstreamer_sample.py -->
177
  ```python
178
+ # SPDX-License-Identifier: MIT
179
+ # Copyright (C) Intel Corporation
180
+ #
181
+ # Motion Detection: DLStreamer pipeline sample.
182
+ # See README.md for prerequisites and inputs. Run: python3 dlstreamer_sample.py
183
+
184
  import gi
185
 
186
  gi.require_version("Gst", "1.0")
 
258
  writer.release()
259
  print(f"Motion detected in {motion_frames} frames", flush=True)
260
  ```
261
+ <!-- /sample -->
262
 
263
  The decode stack runs on the CPU; to offload decode to an Intel GPU, install
264
  the DLStreamer VA-API plugins and prepend `vaapidecodebin` in environments that
 
278
 
279
  - [OpenCV Background Subtraction Tutorial](https://docs.opencv.org/4.x/d1/dc5/tutorial_background_subtraction.html)
280
  - [OpenCV MOG2 Background Subtractor](https://docs.opencv.org/4.x/d7/d7b/classcv_1_1BackgroundSubtractorMOG2.html)
281
+ - [Intel DLStreamer](https://docs.openedgeplatform.intel.com/dev/edge-ai-libraries/dlstreamer/index.html)
282
  - [OpenVINO Documentation](https://docs.openvino.ai/)
dlstreamer_sample.py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (C) Intel Corporation
3
+ #
4
+ # Motion Detection: DLStreamer pipeline sample.
5
+ # See README.md for prerequisites and inputs. Run: python3 dlstreamer_sample.py
6
+
7
+ import gi
8
+
9
+ gi.require_version("Gst", "1.0")
10
+ from gi.repository import Gst
11
+
12
+ import numpy as np
13
+
14
+ Gst.init([])
15
+
16
+ # Import cv2 after Gst.init to avoid GStreamer re-initialization conflicts.
17
+ import cv2
18
+
19
+ INPUT_VIDEO = "test_video.mp4"
20
+ MIN_AREA = 500
21
+
22
+ # Decode with the DLStreamer/GStreamer stack and hand BGR frames to OpenCV.
23
+ pipeline_str = (
24
+ f"filesrc location={INPUT_VIDEO} ! decodebin3 ! videoconvert ! "
25
+ "video/x-raw,format=BGR ! "
26
+ "appsink name=sink emit-signals=false sync=false"
27
+ )
28
+ pipeline = Gst.parse_launch(pipeline_str)
29
+ sink = pipeline.get_by_name("sink")
30
+ pipeline.set_state(Gst.State.PLAYING)
31
+
32
+ bg = cv2.createBackgroundSubtractorMOG2(
33
+ history=200, varThreshold=25, detectShadows=True)
34
+ kernel = np.ones((3, 3), np.uint8)
35
+ writer = None
36
+ frame_idx = 0
37
+ motion_frames = 0
38
+
39
+ while True:
40
+ sample = sink.emit("pull-sample")
41
+ if sample is None:
42
+ break
43
+ buf = sample.get_buffer()
44
+ caps = sample.get_caps().get_structure(0)
45
+ width = caps.get_value("width")
46
+ height = caps.get_value("height")
47
+
48
+ ok, mapinfo = buf.map(Gst.MapFlags.READ)
49
+ if not ok:
50
+ continue
51
+ frame = np.ndarray((height, width, 3), dtype=np.uint8,
52
+ buffer=mapinfo.data).copy()
53
+ buf.unmap(mapinfo)
54
+ frame_idx += 1
55
+
56
+ fg = bg.apply(frame)
57
+ fg = cv2.threshold(fg, 200, 255, cv2.THRESH_BINARY)[1]
58
+ fg = cv2.morphologyEx(fg, cv2.MORPH_OPEN, kernel)
59
+ contours, _ = cv2.findContours(
60
+ fg, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
61
+ regions = [c for c in contours if cv2.contourArea(c) >= MIN_AREA]
62
+ if regions:
63
+ motion_frames += 1
64
+ for c in regions:
65
+ x, y, w, h = cv2.boundingRect(c)
66
+ cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
67
+ status_text = "Motion Detected" if regions else "No Motion"
68
+ status_color = (0, 0, 255) if regions else (0, 255, 0)
69
+ cv2.putText(frame, status_text, (10, 30),
70
+ cv2.FONT_HERSHEY_SIMPLEX, 0.9, status_color, 2)
71
+
72
+ if writer is None:
73
+ writer = cv2.VideoWriter(
74
+ "output_dlstreamer.mp4", cv2.VideoWriter_fourcc(*"mp4v"),
75
+ 30.0, (width, height))
76
+ writer.write(frame)
77
+ print(f"Frame {frame_idx}: motion regions={len(regions)}", flush=True)
78
+
79
+ pipeline.set_state(Gst.State.NULL)
80
+ if writer:
81
+ writer.release()
82
+ print(f"Motion detected in {motion_frames} frames", flush=True)
opencv_sample.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: MIT
2
+ # Copyright (C) Intel Corporation
3
+ #
4
+ # Motion Detection: OpenCV sample.
5
+ # See README.md for prerequisites and inputs. Run: python3 opencv_sample.py
6
+
7
+ import cv2
8
+ import numpy as np
9
+
10
+ INPUT_VIDEO = "test_video.mp4"
11
+ MIN_AREA = 500 # ignore motion blobs smaller than this many pixels
12
+
13
+ cap = cv2.VideoCapture(INPUT_VIDEO)
14
+ fps = cap.get(cv2.CAP_PROP_FPS) or 30.0
15
+ width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
16
+ height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
17
+
18
+ bg = cv2.createBackgroundSubtractorMOG2(
19
+ history=200, varThreshold=25, detectShadows=True)
20
+ writer = cv2.VideoWriter(
21
+ "output_opencv.mp4", cv2.VideoWriter_fourcc(*"mp4v"), fps, (width, height))
22
+ kernel = np.ones((3, 3), np.uint8)
23
+
24
+ frame_idx = 0
25
+ motion_frames = 0
26
+ while True:
27
+ ok, frame = cap.read()
28
+ if not ok:
29
+ break
30
+ frame_idx += 1
31
+
32
+ fg = bg.apply(frame)
33
+ # MOG2 marks shadows as 127; keep only strong foreground (255).
34
+ fg = cv2.threshold(fg, 200, 255, cv2.THRESH_BINARY)[1]
35
+ fg = cv2.morphologyEx(fg, cv2.MORPH_OPEN, kernel)
36
+
37
+ contours, _ = cv2.findContours(
38
+ fg, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
39
+ regions = [c for c in contours if cv2.contourArea(c) >= MIN_AREA]
40
+ if regions:
41
+ motion_frames += 1
42
+ for c in regions:
43
+ x, y, w, h = cv2.boundingRect(c)
44
+ cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 0, 255), 2)
45
+ status_text = "Motion Detected" if regions else "No Motion"
46
+ status_color = (0, 0, 255) if regions else (0, 255, 0)
47
+ cv2.putText(frame, status_text, (10, 30),
48
+ cv2.FONT_HERSHEY_SIMPLEX, 0.9, status_color, 2)
49
+ cv2.putText(frame, f"Motion regions: {len(regions)}", (10, 60),
50
+ cv2.FONT_HERSHEY_SIMPLEX, 0.8, (0, 0, 255), 2)
51
+ print(f"Frame {frame_idx}: motion regions={len(regions)}", flush=True)
52
+ writer.write(frame)
53
+
54
+ cap.release()
55
+ writer.release()
56
+ print(f"Motion detected in {motion_frames} frames", flush=True)