vagheshpatel commited on
Commit
007b9e4
·
verified ·
1 Parent(s): 4ce3d4b

Sync license-plate-recognition from metro-analytics-catalog

Browse files
Files changed (3) hide show
  1. LICENSE +21 -56
  2. README.md +40 -29
  3. expected_output_dlstreamer.gif +2 -2
LICENSE CHANGED
@@ -1,56 +1,21 @@
1
- This directory contains two categories of content under different licenses.
2
-
3
-
4
- Scripts and Documentation
5
- -------------------------
6
-
7
- The scripts (export_and_quantize.sh) and documentation (README.md) in this
8
- directory are original works by Intel Corporation, licensed under the
9
- MIT License.
10
-
11
- Copyright (C) Intel Corporation
12
-
13
- Permission is hereby granted, free of charge, to any person obtaining a copy
14
- of this software and associated documentation files (the "Software"), to deal
15
- in the Software without restriction, including without limitation the rights
16
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17
- copies of the Software, and to permit persons to whom the Software is
18
- furnished to do so, subject to the following conditions:
19
-
20
- The above copyright notice and this permission notice shall be included in
21
- all copies or substantial portions of the Software.
22
-
23
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
29
- THE SOFTWARE.
30
-
31
-
32
- License Plate Detector Model (yolov8_license_plate_detector)
33
- ------------------------------------------------------------
34
-
35
- The YOLOv8 license plate detector weights are distributed by the Intel Edge
36
- AI Resources project and are based on the Ultralytics YOLOv8 framework,
37
- licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
38
-
39
- Source: https://github.com/open-edge-platform/edge-ai-resources
40
- Upstream framework: https://github.com/ultralytics/ultralytics
41
- License: https://github.com/ultralytics/ultralytics/blob/main/LICENSE
42
- Docs: https://docs.ultralytics.com/models/yolov8/
43
-
44
- Users must comply with the AGPL-3.0 license terms when using, modifying,
45
- or distributing the YOLOv8 model weights or Ultralytics software.
46
- For commercial licensing options, see https://www.ultralytics.com/license.
47
-
48
-
49
- OCR Model (ch_PP-OCRv4_rec_infer)
50
- ---------------------------------
51
-
52
- The PaddleOCR PP-OCRv4 recognition model is developed by PaddlePaddle and
53
- licensed under the Apache License, Version 2.0.
54
-
55
- Source: https://github.com/PaddlePaddle/PaddleOCR
56
- License: https://github.com/PaddlePaddle/PaddleOCR/blob/main/LICENSE
 
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 CHANGED
@@ -1,5 +1,5 @@
1
  ---
2
- license: other
3
  license_link: LICENSE
4
  library_name: openvino
5
  pipeline_tag: object-detection
@@ -10,6 +10,7 @@ tags:
10
  - paddleocr
11
  - license-plate-recognition
12
  - ocr
 
13
  - edge-ai
14
  - metro
15
  - dlstreamer
@@ -21,7 +22,7 @@ language:
21
 
22
  | Property | Value |
23
  |---|---|
24
- | **Category** | Object Detection + Optical Character Recognition |
25
  | **Source Framework** | PyTorch (Ultralytics YOLOv8), PaddlePaddle (PP-OCRv4) |
26
  | **Supported Precisions** | FP32 |
27
  | **Inference Engine** | OpenVINO |
@@ -111,8 +112,9 @@ The PaddleOCR recognizer ships inside the same archive:
111
 
112
  > **Note:** PaddleOCR PP-OCRv4 is a CTC sequence model. DLStreamer 2026.0+
113
  > auto-derives the CTC decoder for the bundled `ch_PP-OCRv4_rec_infer` IR
114
- > and exposes the decoded plate string as `tensor.label()` on each
115
- > classified ROI -- no external `model-proc` is required for this sample.
 
116
  > For other PaddleOCR variants or non-Latin character sets, supply a custom
117
  > `model-proc` (see
118
  > [DLStreamer model_proc reference](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/dev_guide/model_proc_file.html))
@@ -127,8 +129,8 @@ It mirrors the structure of the upstream
127
  sample: `decodebin3 ! queue ! gvadetect ! queue ! videoconvert ! gvaclassify ! queue ! gvawatermark ! ...`.
128
  The `gvadetect` element runs the license plate detector;
129
  `gvaclassify` then runs the PaddleOCR recognizer on each detected plate region.
130
- A buffer probe extracts the recognized text from the inference metadata
131
- attached to each frame.
132
  The input is `ParkingVideo.mp4`, the short parking-lot clip downloaded by
133
  `export_and_quantize.sh` into the current directory.
134
  The annotated stream is muxed into `output_dlstreamer.mp4` with H.264 (OpenH264).
@@ -139,11 +141,11 @@ import os
139
  import gi
140
 
141
  gi.require_version("Gst", "1.0")
142
- gi.require_version("GstVideo", "1.0")
143
- from gi.repository import Gst
144
- from gstgva import VideoFrame
145
 
146
- Gst.init(None)
147
 
148
  MODELS_DIR = os.path.abspath("./models/yolov8_license_plate_detector")
149
  DETECTOR_XML = (
@@ -163,9 +165,10 @@ pipeline_str = (
163
  f"gvadetect model={DETECTOR_XML} device={DEVICE} ! queue ! "
164
  f"videoconvert ! "
165
  f"gvaclassify model={OCR_XML} device={DEVICE} ! queue ! "
166
- f"gvawatermark ! videoconvert ! video/x-raw,format=I420 ! "
 
167
  f"openh264enc ! h264parse ! "
168
- f"mp4mux ! filesink name=sink location=output_dlstreamer.mp4"
169
  )
170
 
171
  pipeline = Gst.parse_launch(pipeline_str)
@@ -173,28 +176,36 @@ pipeline = Gst.parse_launch(pipeline_str)
173
 
174
  def on_buffer(pad, info):
175
  buf = info.get_buffer()
176
- caps = pad.get_current_caps()
177
- frame = VideoFrame(buf, caps=caps)
178
- for region in frame.regions():
179
- rect = region.rect()
 
 
 
 
180
  text = ""
181
- for tensor in region.tensors():
182
- if tensor.is_detection():
183
- continue
184
- try:
185
- text = tensor.label() or ""
186
- except RuntimeError:
187
- continue
188
- if text:
189
- break
190
  if text:
191
- print(f"Plate: {text} bbox=({rect.x},{rect.y})", flush=True)
 
 
 
 
 
192
  return Gst.PadProbeReturn.OK
193
 
194
 
195
- sink = pipeline.get_by_name("sink")
196
- sink_pad = sink.get_static_pad("sink")
197
- sink_pad.add_probe(Gst.PadProbeType.BUFFER, on_buffer)
 
198
 
199
  pipeline.set_state(Gst.State.PLAYING)
200
  bus = pipeline.get_bus()
 
1
  ---
2
+ license: mit
3
  license_link: LICENSE
4
  library_name: openvino
5
  pipeline_tag: object-detection
 
10
  - paddleocr
11
  - license-plate-recognition
12
  - ocr
13
+ - gstanalytics
14
  - edge-ai
15
  - metro
16
  - dlstreamer
 
22
 
23
  | Property | Value |
24
  |---|---|
25
+ | **Category** | Object Detection + Optical Character Recognition (GstAnalytics) |
26
  | **Source Framework** | PyTorch (Ultralytics YOLOv8), PaddlePaddle (PP-OCRv4) |
27
  | **Supported Precisions** | FP32 |
28
  | **Inference Engine** | OpenVINO |
 
112
 
113
  > **Note:** PaddleOCR PP-OCRv4 is a CTC sequence model. DLStreamer 2026.0+
114
  > auto-derives the CTC decoder for the bundled `ch_PP-OCRv4_rec_infer` IR
115
+ and exposes the decoded plate string as a `GstAnalytics.ClsMtd` entry
116
+ (with `CONTAIN` relation to the detection) -- no external `model-proc`
117
+ is required for this sample.
118
  > For other PaddleOCR variants or non-Latin character sets, supply a custom
119
  > `model-proc` (see
120
  > [DLStreamer model_proc reference](https://docs.openedgeplatform.intel.com/2026.0/edge-ai-libraries/dlstreamer/dev_guide/model_proc_file.html))
 
129
  sample: `decodebin3 ! queue ! gvadetect ! queue ! videoconvert ! gvaclassify ! queue ! gvawatermark ! ...`.
130
  The `gvadetect` element runs the license plate detector;
131
  `gvaclassify` then runs the PaddleOCR recognizer on each detected plate region.
132
+ A buffer probe reads the `GstAnalytics` classification metadata
133
+ attached to each detection to extract the recognized plate text.
134
  The input is `ParkingVideo.mp4`, the short parking-lot clip downloaded by
135
  `export_and_quantize.sh` into the current directory.
136
  The annotated stream is muxed into `output_dlstreamer.mp4` with H.264 (OpenH264).
 
141
  import gi
142
 
143
  gi.require_version("Gst", "1.0")
144
+ gi.require_version("GstAnalytics", "1.0")
145
+ gi.require_version("DLStreamerWatermarkMeta", "1.0")
146
+ from gi.repository import Gst, GLib, GstAnalytics, DLStreamerWatermarkMeta
147
 
148
+ Gst.init([])
149
 
150
  MODELS_DIR = os.path.abspath("./models/yolov8_license_plate_detector")
151
  DETECTOR_XML = (
 
165
  f"gvadetect model={DETECTOR_XML} device={DEVICE} ! queue ! "
166
  f"videoconvert ! "
167
  f"gvaclassify model={OCR_XML} device={DEVICE} ! queue ! "
168
+ f"identity name=probe ! "
169
+ f"gvawatermark displ-cfg=show-labels=false ! videoconvert ! video/x-raw,format=I420 ! "
170
  f"openh264enc ! h264parse ! "
171
+ f"mp4mux ! filesink location=output_dlstreamer.mp4"
172
  )
173
 
174
  pipeline = Gst.parse_launch(pipeline_str)
 
176
 
177
  def on_buffer(pad, info):
178
  buf = info.get_buffer()
179
+ new_buf = buf.copy_deep()
180
+ rmeta = GstAnalytics.buffer_get_analytics_relation_meta(new_buf)
181
+ if not rmeta:
182
+ info.set_buffer(new_buf)
183
+ return Gst.PadProbeReturn.OK
184
+ for od in rmeta.iter_on_type(GstAnalytics.ODMtd):
185
+ _, x, y, w, h, _ = od.get_location()
186
+ # OCR result is attached as ClsMtd with CONTAIN relation
187
  text = ""
188
+ for cls in od.iter_direct_related(
189
+ GstAnalytics.RelTypes.CONTAIN, GstAnalytics.ClsMtd
190
+ ):
191
+ if cls.get_length() > 0:
192
+ q = cls.get_quark(0)
193
+ text = GLib.quark_to_string(q) if q else ""
194
+ break
 
 
195
  if text:
196
+ DLStreamerWatermarkMeta.text_meta_add(
197
+ new_buf, x=int(x), y=max(0, int(y) - 10),
198
+ text=text, font_scale=0.6, font_type=0,
199
+ r=0, g=255, b=0, thickness=1, draw_bg=True)
200
+ print(f"Plate: {text} bbox=({x},{y})", flush=True)
201
+ info.set_buffer(new_buf)
202
  return Gst.PadProbeReturn.OK
203
 
204
 
205
+ probe = pipeline.get_by_name("probe")
206
+ probe.get_static_pad("src").add_probe(
207
+ Gst.PadProbeType.BUFFER, on_buffer
208
+ )
209
 
210
  pipeline.set_state(Gst.State.PLAYING)
211
  bus = pipeline.get_bus()
expected_output_dlstreamer.gif CHANGED

Git LFS Details

  • SHA256: 9e302c9ad03530af0ebe3a8bd030718c48268f39a1933e18f088a731da1e279d
  • Pointer size: 132 Bytes
  • Size of remote file: 7.09 MB

Git LFS Details

  • SHA256: 6b01138ea1aeefcd2a08337e986a64d6de3cd2e14edc8dff801b3a693190095f
  • Pointer size: 132 Bytes
  • Size of remote file: 1.57 MB