OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[Core] Reference implementation for RGBtoNV12 and BGRtoNV12 operations (#34437)
Mostafacae9972b614a
diff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/image/bgr-to-nv12-17.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/image/bgr-to-nv12-17.rstnew file mode 100644index 00000000000..a06f69366de--- /dev/null+++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/image/bgr-to-nv12-17.rst@@ -0,0 +1,102 @@+BGRtoNV12+=========+++.. meta::+ :description: Learn about BGRtoNV12-17 - an image processing operation, which+ can be performed to convert an image from BGR to NV12 format.++**Versioned name**: *BGRtoNV12-17*++**Category**: *Image processing*++**Short description**: *BGRtoNV12* performs image conversion from BGR to NV12 format.++**Detailed description**:++Similar to *RGBtoNV12* but the input channels for each pixel are reversed so that the first input channel is ``blue``, the second one is ``green``, the last one is ``red``. The same YUV conversion formulas are applied after remapping the channel order. See detailed conversion formulas in the :doc:`RGBtoNV12 description <rgb-to-nv12-17>`.++**Attributes:**++Same as specified for :doc:`RGBtoNV12 <rgb-to-nv12-17>` operation.++**Inputs:**++Input BGR image tensor shall have ``NHWC (also known as NYXC)`` layout. The height ``H`` and width ``W`` dimensions must be even numbers.++* **1**: Tensor of type *T*. **Required.** Dimensions:++ * ``N`` - batch dimension+ * ``H`` - height dimension of the image (must be even)+ * ``W`` - width dimension of the image (must be even)+ * ``C`` - channels dimension is equal to 3. The first channel is Blue, the second one is Green, the last one is Red++**Outputs:**++Same layout as specified for :doc:`RGBtoNV12 <rgb-to-nv12-17>` operation (single-plane or two-plane NV12 depending on the *single_plane* attribute).++**Types:**++* *T*: ``uint8`` or any supported floating-point type.+++**Examples:**++*Example 1: single-plane output*++.. code-block:: xml+ :force:++ <layer ... type="BGRtoNV12">+ <data single_plane="true"/>+ <input>+ <port id="0">+ <dim>1</dim>+ <dim>480</dim>+ <dim>640</dim>+ <dim>3</dim>+ </port>+ </input>+ <output>+ <port id="1">+ <dim>1</dim>+ <dim>720</dim>+ <dim>640</dim>+ <dim>1</dim>+ </port>+ </output>+ </layer>+++*Example 2: two-plane output*++.. code-block:: xml+ :force:++ <layer ... type="BGRtoNV12">+ <data single_plane="false"/>+ <input>+ <port id="0">+ <dim>1</dim>+ <dim>480</dim>+ <dim>640</dim>+ <dim>3</dim>+ </port>+ </input>+ <output>+ <port id="1"> <!-- Y plane -->+ <dim>1</dim>+ <dim>480</dim>+ <dim>640</dim>+ <dim>1</dim>+ </port>+ <port id="2"> <!-- UV plane -->+ <dim>1</dim>+ <dim>240</dim>+ <dim>320</dim>+ <dim>2</dim>+ </port>+ </output>+ </layer>++diff --git a/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/image/rgb-to-nv12-17.rst b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/image/rgb-to-nv12-17.rstnew file mode 100644index 00000000000..69c359576a2--- /dev/null+++ b/docs/articles_en/documentation/openvino-ir-format/operation-sets/operation-specs/image/rgb-to-nv12-17.rst@@ -0,0 +1,140 @@+RGBtoNV12+=========+++.. meta::+ :description: Learn about RGBtoNV12-17 - an image processing operation, which+ can be performed to convert an image from RGB to NV12 format.++**Versioned name**: *RGBtoNV12-17*++**Category**: *Image processing*++**Short description**: *RGBtoNV12* performs image conversion from RGB to NV12 format.++**Detailed description:**++Conversion of each pixel from RGB to NV12 (YUV) space is represented by the following formulas:++.. math::++ \begin{aligned} & Y = 0.257 \cdot R + 0.504 \cdot G + 0.098 \cdot B + 16 \\ & U = -0.148 \cdot R - 0.291 \cdot G + 0.439 \cdot B + 128 \\ & V = 0.439 \cdot R - 0.368 \cdot G - 0.071 \cdot B + 128 \end{aligned}+++Then Y, U, V values are clipped to range (0, 255].++**Attributes:**++* *single_plane*++ * **Description**: Controls whether the NV12 output is packed into a single tensor or split into separate Y and UV planes.+ * **Range of values**: ``true`` or ``false``+ * **Type**: ``bool``+ * **Default value**: ``true``+ * **Required**: *no*++**Inputs:**++Input RGB image tensor shall have ``NHWC (also known as NYXC)`` layout. The height ``H`` and width ``W`` dimensions must be even numbers. Dimensions:++* **1**: Tensor of type *T*. **Required.** Dimensions:++ * ``N`` - batch dimension+ * ``H`` - height dimension of the image (must be even)+ * ``W`` - width dimension of the image (must be even)+ * ``C`` - channels dimension is equal to 3 (Red, Green, Blue)++**Outputs:**++Output NV12 image can be represented in two ways depending on the *single_plane* attribute:++* *Single plane* (``single_plane = true``):++ * **1**: Tensor of type *T*. Dimensions:++ * ``N`` - batch dimension+ * ``H`` - height dimension is 1.5x bigger than the image height (``image_height * 3 / 2``). The first ``image_height`` rows contain the Y (luma) plane; the remaining ``image_height / 2`` rows contain interleaved U and V chroma samples+ * ``W`` - width dimension is the same as the image width+ * ``C`` - channels dimension is equal to 1 (one plane)++* *Two separate planes - Y and UV* (``single_plane = false``):++ * **1**: Tensor of type *T* representing the Y (luma) plane. Dimensions:++ * ``N`` - batch dimension+ * ``H`` - height dimension is the same as the image height+ * ``W`` - width dimension is the same as the image width+ * ``C`` - channels dimension is equal to 1 (only Y channel)++ * **2**: Tensor of type *T* representing the UV (chroma) plane. Dimensions:++ * ``N`` - batch dimension. Shall be the same as the batch dimension for the Y plane+ * ``H`` - height dimension shall be half of the image height (for example, ``image_height / 2``)+ * ``W`` - width dimension shall be half of the image width (for example, ``image_width / 2``)+ * ``C`` - channels dimension shall be equal to 2 (interleaved U channel and V channel)++**Types:**++* *T*: ``uint8`` or any supported floating-point type.+++**Examples:**++*Example 1: single-plane output*++.. code-block:: xml+ :force:++ <layer ... type="RGBtoNV12">+ <data single_plane="true"/>+ <input>+ <port id="0">+ <dim>1</dim>+ <dim>480</dim>+ <dim>640</dim>+ <dim>3</dim>+ </port>+ </input>+ <output>+ <port id="1">+ <dim>1</dim>+ <dim>720</dim>+ <dim>640</dim>+ <dim>1</dim>+ </port>+ </output>+ </layer>+++*Example 2: two-plane output*++.. code-block:: xml+ :force:++ <layer ... type="RGBtoNV12">+ <data single_plane="false"/>+ <input>+ <port id="0">+ <dim>1</dim>+ <dim>480</dim>+ <dim>640</dim>+ <dim>3</dim>+ </port>+ </input>+ <output>+ <port id="1"> <!-- Y plane -->+ <dim>1</dim>+ <dim>480</dim>+ <dim>640</dim>+ <dim>1</dim>+ </port>+ <port id="2"> <!-- UV plane -->+ <dim>1</dim>+ <dim>240</dim>+ <dim>320</dim>+ <dim>2</dim>+ </port>+ </output>+ </layer>++diff --git a/src/core/docs/operation_enabling_flow.md b/src/core/docs/operation_enabling_flow.mdindex 97f9a0252e4..6c4b7154fe2 100644--- a/src/core/docs/operation_enabling_flow.md+++ b/src/core/docs/operation_enabling_flow.md@@ -1,6 +1,6 @@# OpenVINO Operation Enabling Flow-1. Implement operation "shell" in the `src/core/[src|include]/op/`:+1. Implement operation "shell" in the `src/core/[src|include/openvino]/op/`:* Implement constructor(s)* Implement `validate_and_infer_types` method which should support dynamic input tensor(s) (with partially dynamic shapes). For more information read [OpenVINO Shape propagation guide](./shape_propagation.md)* Implement `visit_attributes` methoddiff --git a/src/core/include/openvino/op/bgr_to_nv12.hpp b/src/core/include/openvino/op/bgr_to_nv12.hppnew file mode 100644index 00000000000..9ad1cc12236--- /dev/null+++ b/src/core/include/openvino/op/bgr_to_nv12.hpp@@ -0,0 +1,51 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//+#pragma once++#include "openvino/op/util/convert_color_to_nv12_base.hpp"++namespace ov::op::v17 {+/// \brief Color conversion operation from BGR to NV12 format.+/// Input:+/// - Input BGR image in NHWC layout with shape [N, H, W, 3].+/// - Image dimensions 'H' and 'W' must be even numbers.+/// - Supported element types: u8 or any supported floating-point type.+/// Output:+/// - Output NV12 image can be represented in two ways:+/// a) Single plane (default): Height dimension is 1.5x bigger than image height.+/// Shape: [N, H * 3/2, W, 1].+/// The first H rows contain the Y plane, followed by H/2 rows of interleaved UV.+/// b) Two separate planes:+/// b1) Y plane: [N, H, W, 1]+/// b2) UV plane: [N, H/2, W/2, 2] (interleaved U and V)+///+/// \details Conversion of each pixel from BGR to NV12 (YUV) space is represented by following formulas+/// (after reversing channel order to RGB):+/// Y = 0.257 * R + 0.504 * G + 0.098 * B + 16+/// U = -0.148 * R - 0.291 * G + 0.439 * B + 128+/// V = 0.439 * R - 0.368 * G - 0.071 * B + 128+/// Then Y, U, V values are clipped to range (0, 255)+///+/// \ingroup ov_ops_cpp_api+class OPENVINO_API BGRtoNV12 : public util::ConvertColorToNV12Base {+public:+ OPENVINO_OP("BGRtoNV12", "opset17", util::ConvertColorToNV12Base);+ BGRtoNV12() = default;+ /// \brief Constructs a conversion operation from input image in BGR format.+ /// Output is single-plane NV12.+ ///+ /// \param arg Node that produces the input tensor (NHWC layout, C=3).+ explicit BGRtoNV12(const Output<Node>& arg);+ /// \brief Constructs a conversion operation from input image in BGR format+ /// with configurable output format.+ ///+ /// \param arg Node that produces the input tensor (NHWC layout, C=3).+ /// \param single_plane If true, output is single-plane NV12 [N, H*3/2, W, 1].+ /// If false, output is two planes: Y [N, H, W, 1] and UV [N, H/2, W/2, 2].+ explicit BGRtoNV12(const Output<Node>& arg, bool single_plane);++ std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;+ void validate_and_infer_types() override;+};+} // namespace ov::op::v17diff --git a/src/core/include/openvino/op/ops.hpp b/src/core/include/openvino/op/ops.hppindex da700ed58e8..c3b74102bb4 100644--- a/src/core/include/openvino/op/ops.hpp+++ b/src/core/include/openvino/op/ops.hpp@@ -20,6 +20,7 @@#include "openvino/op/avg_pool.hpp"#include "openvino/op/batch_norm.hpp"#include "openvino/op/batch_to_space.hpp"+#include "openvino/op/bgr_to_nv12.hpp"#include "openvino/op/binary_convolution.hpp"#include "openvino/op/bitwise_and.hpp"#include "openvino/op/bitwise_left_shift.hpp"@@ -162,6 +163,7 @@#include "openvino/op/result.hpp"#include "openvino/op/reverse.hpp"#include "openvino/op/reverse_sequence.hpp"+#include "openvino/op/rgb_to_nv12.hpp"#include "openvino/op/rnn_cell.hpp"#include "openvino/op/rnn_sequence.hpp"#include "openvino/op/roi_align.hpp"diff --git a/src/core/include/openvino/op/rgb_to_nv12.hpp b/src/core/include/openvino/op/rgb_to_nv12.hppnew file mode 100644index 00000000000..0ab105f3825--- /dev/null+++ b/src/core/include/openvino/op/rgb_to_nv12.hpp@@ -0,0 +1,54 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/op/util/convert_color_to_nv12_base.hpp"++namespace ov::op::v17 {+/// \brief Color conversion operation from RGB to NV12 format.+/// Input:+/// - Input RGB image in NHWC layout with shape [N, H, W, 3].+/// - Image dimensions 'H' and 'W' must be even numbers.+/// - Supported element types: u8 or any supported floating-point type.+/// Output:+/// - Output NV12 image can be represented in two ways:+/// a) Single plane (default): Height dimension is 1.5x bigger than image height.+/// Shape: [N, H * 3/2, W, 1].+/// The first H rows contain the Y plane, followed by H/2 rows of interleaved UV.+/// b) Two separate planes:+/// b1) Y plane: [N, H, W, 1]+/// b2) UV plane: [N, H/2, W/2, 2] (interleaved U and V)+///+/// \details Conversion of each pixel from RGB to NV12 (YUV) space is represented by following formulas:+/// Y = 0.257 * R + 0.504 * G + 0.098 * B + 16+/// U = -0.148 * R - 0.291 * G + 0.439 * B + 128+/// V = 0.439 * R - 0.368 * G - 0.071 * B + 128+/// Then Y, U, V values are clipped to range (0, 255)+///+/// \ingroup ov_ops_cpp_api+class OPENVINO_API RGBtoNV12 : public util::ConvertColorToNV12Base {+public:+ OPENVINO_OP("RGBtoNV12", "opset17", util::ConvertColorToNV12Base);++ RGBtoNV12() = default;++ /// \brief Constructs a conversion operation from input image in RGB format.+ /// Output is single-plane NV12.+ ///+ /// \param arg Node that produces the input tensor (NHWC layout, C=3).+ explicit RGBtoNV12(const Output<Node>& arg);++ /// \brief Constructs a conversion operation from input image in RGB format+ /// with configurable output format.+ ///+ /// \param arg Node that produces the input tensor (NHWC layout, C=3).+ /// \param single_plane If true, output is single-plane NV12 [N, H*3/2, W, 1].+ /// If false, output is two planes: Y [N, H, W, 1] and UV [N, H/2, W/2, 2].+ explicit RGBtoNV12(const Output<Node>& arg, bool single_plane);++ std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override;+ void validate_and_infer_types() override;+};+} // namespace ov::op::v17diff --git a/src/core/include/openvino/op/util/convert_color_i420_base.hpp b/src/core/include/openvino/op/util/convert_color_i420_base.hppindex 18bcb5431cf..97180676a0a 100644--- a/src/core/include/openvino/op/util/convert_color_i420_base.hpp+++ b/src/core/include/openvino/op/util/convert_color_i420_base.hpp@@ -13,7 +13,7 @@ namespace util {/// \brief Base class for color conversion operation from I420 to RGB/BGR format./// Input:/// - Operation expects input shape in NHWC layout.-/// - Input NV12 image can be represented in a two ways:+/// - Input NV12 image can be represented in two ways:/// a) Single plane: NV12 height dimension is 1.5x bigger than image height. 'C' dimension shall be 1/// b) Three separate planes: Y, U and V. In this case/// b1) Y plane has height same as image height. 'C' dimension equals to 1diff --git a/src/core/include/openvino/op/util/convert_color_nv12_base.hpp b/src/core/include/openvino/op/util/convert_color_nv12_base.hppindex 0a645de0280..7de9edc5b12 100644--- a/src/core/include/openvino/op/util/convert_color_nv12_base.hpp+++ b/src/core/include/openvino/op/util/convert_color_nv12_base.hpp@@ -13,7 +13,7 @@ namespace util {/// \brief Base class for color conversion operation from NV12 to RGB/BGR format./// Input:/// - Operation expects input shape in NHWC layout.-/// - Input NV12 image can be represented in a two ways:+/// - Input NV12 image can be represented in two ways:/// a) Single plane: NV12 height dimension is 1.5x bigger than image height. 'C' dimension shall be 1/// b) Two separate planes: Y and UV. In this case/// b1) Y plane has height same as image height. 'C' dimension equals to 1diff --git a/src/core/include/openvino/op/util/convert_color_to_nv12_base.hpp b/src/core/include/openvino/op/util/convert_color_to_nv12_base.hppnew file mode 100644index 00000000000..0f4f9483e57--- /dev/null+++ b/src/core/include/openvino/op/util/convert_color_to_nv12_base.hpp@@ -0,0 +1,60 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/op/op.hpp"++namespace ov::op::util {+/// \brief Base class for color conversion operation from RGB/BGR to NV12 format.+/// Input:+/// - Operation expects input shape in NHWC layout.+/// - Input RGB/BGR image has shape [N, H, W, 3]. H and W must be even.+/// - Supported element types: u8 or any supported floating-point type.+/// Output:+/// - Output NV12 image can be represented in two ways:+/// a) Single plane: Height dimension is 1.5x bigger than image height. 'C' dimension equals 1.+/// Shape: [N, H * 3/2, W, 1]+/// b) Two separate planes:+/// b1) Y plane has height same as image height. 'C' dimension equals 1.+/// Shape: [N, H, W, 1]+/// b2) UV plane has dimensions: 'H' = image_h / 2; 'W' = image_w / 2; 'C' = 2.+/// Shape: [N, H/2, W/2, 2]+///+/// \details Conversion of each pixel from RGB to NV12 (YUV) space is represented by following formulas:+/// Y = 0.257 * R + 0.504 * G + 0.098 * B + 16+/// U = -0.148 * R - 0.291 * G + 0.439 * B + 128+/// V = 0.439 * R - 0.368 * G - 0.071 * B + 128+/// Then Y, U, V values are clipped to range (0, 255)+/// UV plane is subsampled by averaging each 2x2 block of pixels.+///+class OPENVINO_API ConvertColorToNV12Base : public Op {+protected:+ ConvertColorToNV12Base() = default;++ /// \brief Constructs a conversion operation from input image in RGB/BGR format.+ /// Default output is single-plane NV12.+ ///+ /// \param arg Node that produces the input tensor. Input tensor represents image in RGB/BGR format (NHWC).+ explicit ConvertColorToNV12Base(const Output<Node>& arg);++ /// \brief Constructs a conversion operation from input image in RGB/BGR format with configurable output.+ ///+ /// \param arg Node that produces the input tensor. Input tensor represents image in RGB/BGR format (NHWC).+ /// \param single_plane If true, output is single-plane NV12; if false, output is Y and UV as separate planes.+ ConvertColorToNV12Base(const Output<Node>& arg, bool single_plane);++public:+ OPENVINO_OP("ConvertColorToNV12Base", "util");++ bool visit_attributes(AttributeVisitor& visitor) override;++ bool is_single_plane() const {+ return m_single_plane;+ }++protected:+ bool m_single_plane = true;+};+} // namespace ov::op::utildiff --git a/src/core/include/openvino/opsets/opset17_tbl.hpp b/src/core/include/openvino/opsets/opset17_tbl.hppindex cd9b674a750..06648b9153c 100644--- a/src/core/include/openvino/opsets/opset17_tbl.hpp+++ b/src/core/include/openvino/opsets/opset17_tbl.hpp@@ -16,3 +16,5 @@ _OPENVINO_OP_REG(ShapeOf, ov::op::v3)// New operations added in opset17_OPENVINO_OP_REG(ErfInv, ov::op::v17)_OPENVINO_OP_REG(GroupedMatMul, ov::op::v17)+_OPENVINO_OP_REG(RGBtoNV12, ov::op::v17)+_OPENVINO_OP_REG(BGRtoNV12, ov::op::v17)diff --git a/src/core/reference/include/openvino/reference/convert_color_to_nv12.hpp b/src/core/reference/include/openvino/reference/convert_color_to_nv12.hppnew file mode 100644index 00000000000..9e063798d1c--- /dev/null+++ b/src/core/reference/include/openvino/reference/convert_color_to_nv12.hpp@@ -0,0 +1,90 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include <algorithm>+#include <cmath>+#include <cstddef>+#include <tuple>++namespace ov::reference {++namespace func {++template <typename T>+T clip(double a) {+ if constexpr (std::is_integral_v<T>) {+ return static_cast<T>(std::min(std::max(std::round(a), 0.0), 255.0));+ } else {+ return static_cast<T>(std::min(std::max(a, 0.0), 255.0));+ }+}++template <typename T>+T round_cast(double a) {+ if constexpr (std::is_integral_v<T>) {+ return static_cast<T>(std::round(a));+ } else {+ return static_cast<T>(a);+ }+}++template <typename T>+std::tuple<T, T, T> rgb_pixel_to_yuv(T r_val, T g_val, T b_val) {+ const double r = static_cast<double>(r_val);+ const double g = static_cast<double>(g_val);+ const double b = static_cast<double>(b_val);+ return {clip<T>(0.257 * r + 0.504 * g + 0.098 * b + 16.0),+ clip<T>(-0.148 * r - 0.291 * g + 0.439 * b + 128.0),+ clip<T>(0.439 * r - 0.368 * g - 0.071 * b + 128.0)};+}++} // namespace func++template <typename T, bool IsRGB>+void color_convert_to_nv12(const T* rgb_ptr,+ T* out_y,+ T* out_uv,+ size_t batch_size,+ size_t image_h,+ size_t image_w,+ bool single_plane) {+ constexpr size_t r_offset = IsRGB ? 0 : 2;+ constexpr size_t b_offset = IsRGB ? 2 : 0;++ const size_t frame_size = image_w * image_h;+ const size_t stride_y = single_plane ? frame_size * 3 / 2 : frame_size;+ const size_t stride_uv = single_plane ? frame_size * 3 / 2 : frame_size / 2;+ T* uv_base = single_plane ? out_y + frame_size : out_uv;+ for (size_t batch = 0; batch < batch_size; batch++) {+ const T* rgb = rgb_ptr + batch * frame_size * 3;+ T* y_ptr = out_y + batch * stride_y;+ T* uv_ptr = uv_base + batch * stride_uv;+ for (size_t h = 0; h < image_h; h += 2) {+ for (size_t w = 0; w < image_w; w += 2) {+ double u_sum = 0.0;+ double v_sum = 0.0;+ for (size_t dh = 0; dh < 2; dh++) {+ for (size_t dw = 0; dw < 2; dw++) {+ size_t pixel_idx = (h + dh) * image_w + (w + dw);+ size_t rgb_idx = pixel_idx * 3;+ T y, u, v;+ std::tie(y, u, v) = func::rgb_pixel_to_yuv<T>(rgb[rgb_idx + r_offset],+ rgb[rgb_idx + 1],+ rgb[rgb_idx + b_offset]);+ y_ptr[pixel_idx] = y;+ u_sum += static_cast<double>(u);+ v_sum += static_cast<double>(v);+ }+ }+ size_t uv_index = (h / 2) * image_w + w;+ uv_ptr[uv_index] = func::round_cast<T>(u_sum / 4.0);+ uv_ptr[uv_index + 1] = func::round_cast<T>(v_sum / 4.0);+ }+ }+ }+}++} // namespace ov::referencediff --git a/src/core/shape_inference/include/rgb_bgr_to_nv12_shape_inference.hpp b/src/core/shape_inference/include/rgb_bgr_to_nv12_shape_inference.hppnew file mode 100644index 00000000000..d1c9e737a92--- /dev/null+++ b/src/core/shape_inference/include/rgb_bgr_to_nv12_shape_inference.hpp@@ -0,0 +1,54 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "dimension_util.hpp"+#include "openvino/op/util/convert_color_to_nv12_base.hpp"+#include "utils.hpp"++namespace ov::op {+template <class TShape, class TRShape = result_shape_t<TShape>>+std::vector<TRShape> shape_infer(const util::ConvertColorToNV12Base* op, const std::vector<TShape>& input_shapes) {+ NODE_VALIDATION_CHECK(op, input_shapes.size() == 1);+ using namespace ov::util;++ const auto& shape_rgb = input_shapes[0];+ const auto rank = shape_rgb.rank();++ NODE_SHAPE_INFER_CHECK(op, input_shapes, rank.compatible(4), "RGB/BGR input shall have 4 dimensions (N, H, W, C)");++ if (rank.is_dynamic()) {+ if (op->is_single_plane()) {+ return {TRShape{ov::Dimension::dynamic(),+ ov::Dimension::dynamic(),+ ov::Dimension::dynamic(),+ 1}}; // Y + UV planes+ } else {+ return {+ TRShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic(), 1}, // Y plane+ TRShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic(), 2}}; // UV plane+ }+ }++ NODE_SHAPE_INFER_CHECK(op,+ input_shapes,+ shape_rgb[3].compatible(3),+ "RGB/BGR input number of channels should be equal to 3");++ NODE_SHAPE_INFER_CHECK(op, input_shapes, dim::is_divisible(shape_rgb[1], 2), "Image height must be even");+ NODE_SHAPE_INFER_CHECK(op, input_shapes, dim::is_divisible(shape_rgb[2], 2), "Image width must be even");++ if (op->is_single_plane()) {+ auto out = TRShape{shape_rgb[0], shape_rgb[1], shape_rgb[2], 1};+ auto& height = out[1];+ height = height * 3 / 2;+ NODE_SHAPE_INFER_CHECK(op, input_shapes, !dim::is_empty(height), "Image height computation failed");+ return {std::move(out)};+ } else {+ return {TRShape{shape_rgb[0], shape_rgb[1], shape_rgb[2], 1}, // Y plane+ TRShape{shape_rgb[0], shape_rgb[1] / 2, shape_rgb[2] / 2, 2}}; // UV plane+ }+}+} // namespace ov::opdiff --git a/src/core/src/op/bgr_to_nv12.cpp b/src/core/src/op/bgr_to_nv12.cppnew file mode 100644index 00000000000..8aa1c67d74f--- /dev/null+++ b/src/core/src/op/bgr_to_nv12.cpp@@ -0,0 +1,44 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/bgr_to_nv12.hpp"++#include "itt.hpp"+#include "openvino/core/validation_util.hpp"+#include "rgb_bgr_to_nv12_shape_inference.hpp"+ov::op::v17::BGRtoNV12::BGRtoNV12(const Output<Node>& arg) : util::ConvertColorToNV12Base(arg) {+ constructor_validate_and_infer_types();+}+ov::op::v17::BGRtoNV12::BGRtoNV12(const Output<Node>& arg, bool single_plane)+ : util::ConvertColorToNV12Base(arg, single_plane) {+ constructor_validate_and_infer_types();+}+std::shared_ptr<ov::Node> ov::op::v17::BGRtoNV12::clone_with_new_inputs(const OutputVector& new_args) const {+ OV_OP_SCOPE(v17_BGRtoNV12_clone_with_new_inputs);+ check_new_args_count(this, new_args);+ return std::make_shared<BGRtoNV12>(new_args.at(0), m_single_plane);+}++namespace {+bool is_type_supported(const ov::element::Type& type) {+ return type.is_dynamic() || (type.is_real() && !type.is_quantized()) || type == ov::element::u8;+}+} // namespace++void ov::op::v17::BGRtoNV12::validate_and_infer_types() {+ OV_OP_SCOPE(v17_BGRtoNV12_validate_and_infer_types);++ const auto input_shapes = ov::util::get_node_input_partial_shapes(*this);+ const auto output_shapes = shape_infer(this, input_shapes);++ const auto& out_type = get_input_element_type(0);+ NODE_VALIDATION_CHECK(this,+ is_type_supported(out_type),+ "Input type shall have u8 or floating-point precision, got ",+ out_type);++ for (size_t i = 0; i < output_shapes.size(); i++) {+ set_output_type(i, out_type, output_shapes[i]);+ }+}diff --git a/src/core/src/op/rgb_to_nv12.cpp b/src/core/src/op/rgb_to_nv12.cppnew file mode 100644index 00000000000..36a35633db5--- /dev/null+++ b/src/core/src/op/rgb_to_nv12.cpp@@ -0,0 +1,47 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/rgb_to_nv12.hpp"++#include "itt.hpp"+#include "openvino/core/validation_util.hpp"+#include "rgb_bgr_to_nv12_shape_inference.hpp"++ov::op::v17::RGBtoNV12::RGBtoNV12(const Output<Node>& arg) : util::ConvertColorToNV12Base(arg) {+ constructor_validate_and_infer_types();+}++ov::op::v17::RGBtoNV12::RGBtoNV12(const Output<Node>& arg, bool single_plane)+ : util::ConvertColorToNV12Base(arg, single_plane) {+ constructor_validate_and_infer_types();+}++std::shared_ptr<ov::Node> ov::op::v17::RGBtoNV12::clone_with_new_inputs(const OutputVector& new_args) const {+ OV_OP_SCOPE(v17_RGBtoNV12_clone_with_new_inputs);+ check_new_args_count(this, new_args);+ return std::make_shared<RGBtoNV12>(new_args.at(0), m_single_plane);+}++namespace {+bool is_type_supported(const ov::element::Type& type) {+ return type.is_dynamic() || (type.is_real() && !type.is_quantized()) || type == ov::element::u8;+}+} // namespace++void ov::op::v17::RGBtoNV12::validate_and_infer_types() {+ OV_OP_SCOPE(v17_RGBtoNV12_validate_and_infer_types);++ const auto input_shapes = ov::util::get_node_input_partial_shapes(*this);+ const auto output_shapes = shape_infer(this, input_shapes);++ const auto out_type = get_input_element_type(0);+ NODE_VALIDATION_CHECK(this,+ is_type_supported(out_type),+ "Input type shall have u8 or floating-point precision, got ",+ out_type);++ for (size_t i = 0; i < output_shapes.size(); i++) {+ set_output_type(i, out_type, output_shapes[i]);+ }+}diff --git a/src/core/src/op/util/convert_color_to_nv12_base.cpp b/src/core/src/op/util/convert_color_to_nv12_base.cppnew file mode 100644index 00000000000..ba854c32ff2--- /dev/null+++ b/src/core/src/op/util/convert_color_to_nv12_base.cpp@@ -0,0 +1,18 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/op/util/convert_color_to_nv12_base.hpp"++ov::op::util::ConvertColorToNV12Base::ConvertColorToNV12Base(const Output<Node>& arg)+ : Op({arg}),+ m_single_plane(true) {}++ov::op::util::ConvertColorToNV12Base::ConvertColorToNV12Base(const Output<Node>& arg, bool single_plane)+ : Op({arg}),+ m_single_plane(single_plane) {}++bool ov::op::util::ConvertColorToNV12Base::visit_attributes(AttributeVisitor& visitor) {+ visitor.on_attribute("single_plane", m_single_plane);+ return true;+}diff --git a/src/core/src/preprocess/preprocess_impls.cpp b/src/core/src/preprocess/preprocess_impls.cppindex cc164e54730..f2a1d56fd39 100644--- a/src/core/src/preprocess/preprocess_impls.cpp+++ b/src/core/src/preprocess/preprocess_impls.cpp@@ -6,6 +6,8 @@#include "layout_utils.hpp"#include "openvino/core/descriptor_tensor.hpp"+#include "openvino/op/result.hpp"+#include "openvino/op/util/convert_color_to_nv12_base.hpp"#include "openvino/util/common_util.hpp"namespace ov {@@ -324,7 +326,7 @@ void InputInfo::InputInfoImpl::dump(std::ostream& str,}}-//----------- OutputInfoImpl ----------+//----------- OutputInfoImpl -----------void OutputInfo::OutputInfoImpl::build(ov::ResultVector& results) {auto node = m_output_node;const auto result = ov::as_type_ptr<op::v0::Result>(node.get_node_shared_ptr());@@ -348,10 +350,28 @@ void OutputInfo::OutputInfoImpl::build(ov::ResultVector& results) {// Apply post-processingnode = result->get_input_source_output(0);bool post_processing_applied = false;++ std::shared_ptr<op::util::ConvertColorToNV12Base> convert_nv12_node;+ PostprocessingContext uv_context(Layout{}); // snapshot in case NV12_TWO_PLANES is encountered+ std::vector<InternalPostprocessAction> post_nv12_explicit_actions;+for (const auto& action : get_postprocess()->actions()) {auto action_result = action.m_op({node}, context);node = std::get<0>(action_result);post_processing_applied = true;+ if (!convert_nv12_node) {+ // Check whether this action produced a two-plane NV12 node.+ if (auto nv12 = ov::as_type_ptr<op::util::ConvertColorToNV12Base>(node.get_node_shared_ptr())) {+ if (!nv12->is_single_plane()) {+ convert_nv12_node = nv12;+ uv_context = context;+ }+ }+ } else {+ // Collect every explicit action that follows the NV12 conversion;+ // in order to apply on the UV plane.+ post_nv12_explicit_actions.push_back(action);+ }}// Implicit: Convert element type + layout to user's tensor implicitlyPostStepsList implicit_steps;@@ -411,6 +431,46 @@ void OutputInfo::OutputInfoImpl::build(ov::ResultVector& results) {if (!context.layout().empty()) {result->set_layout(context.layout());}++ // Handle NV12_TWO_PLANES: apply post-NV12 explicit actions and implicit steps on UV plane.+ if (convert_nv12_node) {+ Output<Node> uv_node = convert_nv12_node->output(1);+ for (const auto& action : post_nv12_explicit_actions) {+ auto action_result = action.m_op({uv_node}, uv_context);+ uv_node = std::get<0>(action_result);+ }+ for (const auto& action : implicit_steps.actions()) {+ auto action_result = action.m_op({uv_node}, uv_context);+ uv_node = std::get<0>(action_result);+ }++ auto uv_result = std::make_shared<op::v0::Result>(uv_node);++ // Setting subnames for Y and UV planes+ auto original_names = result->get_output_tensor(0).get_names();+ auto original_friendly_name = result->get_friendly_name();+ std::unordered_set<std::string> y_names;+ std::unordered_set<std::string> uv_names;+ for (const auto& name : original_names) {+ y_names.insert(name + "/Y");+ uv_names.insert(name + "/UV");+ }+ result->get_output_tensor(0).set_names(y_names);+ result->set_friendly_name(original_friendly_name + "/Y");++ uv_result->get_output_tensor(0).set_names(uv_names);+ uv_result->set_friendly_name(original_friendly_name + "/UV");++ // Update UV result layout+ if (!context.layout().empty()) {+ uv_result->set_layout(context.layout());+ }++ auto it = std::find(results.begin(), results.end(), result);+ if (it != results.end()) {+ results.insert(std::next(it), uv_result);+ }+ }}void OutputInfo::OutputInfoImpl::dump(std::ostream& str) const {diff --git a/src/core/src/preprocess/preprocess_steps_impl.cpp b/src/core/src/preprocess/preprocess_steps_impl.cppindex 679adb913cf..e00e5773591 100644--- a/src/core/src/preprocess/preprocess_steps_impl.cpp+++ b/src/core/src/preprocess/preprocess_steps_impl.cpp@@ -9,6 +9,7 @@#include "openvino/core/node.hpp"#include "openvino/core/shape.hpp"#include "openvino/op/add.hpp"+#include "openvino/op/bgr_to_nv12.hpp"#include "openvino/op/clamp.hpp"#include "openvino/op/constant.hpp"#include "openvino/op/convert.hpp"@@ -23,6 +24,7 @@#include "openvino/op/nv12_to_rgb.hpp"#include "openvino/op/pad.hpp"#include "openvino/op/range.hpp"+#include "openvino/op/rgb_to_nv12.hpp"#include "openvino/op/round.hpp"#include "openvino/op/shape_of.hpp"#include "openvino/op/slice.hpp"@@ -806,6 +808,26 @@ void PostStepsList::add_convert_color_impl(const ColorFormat& dst_format) {auto res = reverse_channels({node}, context);context.color_format() = dst_format;return res;+ } else if ((context.color_format() == ColorFormat::RGB || context.color_format() == ColorFormat::BGR) &&+ dst_format == ColorFormat::NV12_SINGLE_PLANE) {+ std::shared_ptr<ov::Node> convert;+ if (context.color_format() == ColorFormat::RGB) {+ convert = std::make_shared<op::v17::RGBtoNV12>(node);+ } else {+ convert = std::make_shared<op::v17::BGRtoNV12>(node);+ }+ context.color_format() = dst_format;+ return std::make_tuple(Output<Node>(convert), true);+ } else if ((context.color_format() == ColorFormat::RGB || context.color_format() == ColorFormat::BGR) &&+ dst_format == ColorFormat::NV12_TWO_PLANES) {+ std::shared_ptr<ov::Node> convert;+ if (context.color_format() == ColorFormat::RGB) {+ convert = std::make_shared<op::v17::RGBtoNV12>(node, false);+ } else {+ convert = std::make_shared<op::v17::BGRtoNV12>(node, false);+ }+ context.color_format() = dst_format;+ return std::make_tuple(Output<Node>(convert, 0), true);} else {OPENVINO_THROW("Source color format '",color_format_name(context.color_format()),diff --git a/src/core/src/sources.cmake b/src/core/src/sources.cmakeindex 92101370128..9d85222fa3c 100644--- a/src/core/src/sources.cmake+++ b/src/core/src/sources.cmake@@ -65,6 +65,7 @@ set(LIBRARY_SRC${CMAKE_CURRENT_LIST_DIR}/op/avg_pool.cpp${CMAKE_CURRENT_LIST_DIR}/op/batch_norm.cpp${CMAKE_CURRENT_LIST_DIR}/op/batch_to_space.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/bgr_to_nv12.cpp${CMAKE_CURRENT_LIST_DIR}/op/binary_convolution.cpp${CMAKE_CURRENT_LIST_DIR}/op/bitwise_and.cpp${CMAKE_CURRENT_LIST_DIR}/op/bitwise_left_shift.cpp@@ -218,6 +219,7 @@ set(LIBRARY_SRC${CMAKE_CURRENT_LIST_DIR}/op/rms_norm.cpp${CMAKE_CURRENT_LIST_DIR}/op/rnn_cell.cpp${CMAKE_CURRENT_LIST_DIR}/op/rnn_sequence.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/rgb_to_nv12.cpp${CMAKE_CURRENT_LIST_DIR}/op/roi_align.cpp${CMAKE_CURRENT_LIST_DIR}/op/roi_align_rotated.cpp${CMAKE_CURRENT_LIST_DIR}/op/roi_pooling.cpp@@ -281,6 +283,7 @@ set(LIBRARY_SRC${CMAKE_CURRENT_LIST_DIR}/op/util/broadcast_base.cpp${CMAKE_CURRENT_LIST_DIR}/op/util/convert_color_i420_base.cpp${CMAKE_CURRENT_LIST_DIR}/op/util/convert_color_nv12_base.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/util/convert_color_to_nv12_base.cpp${CMAKE_CURRENT_LIST_DIR}/op/util/deformable_convolution_base.cpp${CMAKE_CURRENT_LIST_DIR}/op/util/detection_output_base.cpp${CMAKE_CURRENT_LIST_DIR}/op/util/elementwise_args.cppdiff --git a/src/core/tests/opset.cpp b/src/core/tests/opset.cppindex d1c0ab80f14..966ed66b1b1 100644--- a/src/core/tests/opset.cpp+++ b/src/core/tests/opset.cpp@@ -79,7 +79,7 @@ INSTANTIATE_TEST_SUITE_P(opset,OpsetTestParams{ov::get_opset14, 188},OpsetTestParams{ov::get_opset15, 199},OpsetTestParams{ov::get_opset16, 203},- OpsetTestParams{ov::get_opset17, 5}),+ OpsetTestParams{ov::get_opset17, 7}),OpsetTestNameGenerator{});class MyOpOld : public ov::op::Op {diff --git a/src/core/tests/preprocess.cpp b/src/core/tests/preprocess.cppindex 9758492fb15..8a248ba80b3 100644--- a/src/core/tests/preprocess.cpp+++ b/src/core/tests/preprocess.cpp@@ -2107,6 +2107,204 @@ TEST(pre_post_process, postprocess_convert_color_format_unsupported) {f = p.build(), ov::AssertFailure);}+TEST(pre_post_process, postprocess_convert_color_format_RGB_NV12_single_plane) {+ auto f = create_simple_function(element::f32, Shape{5, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_SINGLE_PLANE);+ f = p.build();++ EXPECT_EQ(f->get_results().size(), 1);+ EXPECT_EQ(f->get_result()->get_output_partial_shape(0), (PartialShape{5, 45, 20, 1}));+}++TEST(pre_post_process, postprocess_convert_color_format_RGB_NV12_two_planes) {+ auto f = create_simple_function(element::f32, Shape{5, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES);+ f = p.build();++ EXPECT_EQ(f->get_results().size(), 2);+ EXPECT_EQ(f->get_results()[0]->get_output_partial_shape(0), (PartialShape{5, 30, 20, 1}));+ EXPECT_EQ(f->get_results()[1]->get_output_partial_shape(0), (PartialShape{5, 15, 10, 2}));++ auto y_names = f->output(0).get_tensor().get_names();+ auto uv_names = f->output(1).get_tensor().get_names();+ EXPECT_EQ(y_names.count("tensor_output1/Y"), 1);+ EXPECT_EQ(uv_names.count("tensor_output1/UV"), 1);+}++TEST(pre_post_process, postprocess_convert_color_format_BGR_NV12_two_planes) {+ auto f = create_simple_function(element::f32, Shape{5, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::BGR);+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES);+ f = p.build();++ EXPECT_EQ(f->get_results().size(), 2);+ EXPECT_EQ(f->get_results()[0]->get_output_partial_shape(0), (PartialShape{5, 30, 20, 1}));+ EXPECT_EQ(f->get_results()[1]->get_output_partial_shape(0), (PartialShape{5, 15, 10, 2}));++ auto y_names = f->output(0).get_tensor().get_names();+ auto uv_names = f->output(1).get_tensor().get_names();+ EXPECT_EQ(y_names.count("tensor_output1/Y"), 1);+ EXPECT_EQ(uv_names.count("tensor_output1/UV"), 1);+}++TEST(pre_post_process, postprocess_convert_color_format_RGB_NV12_two_planes_with_element_type) {+ auto f = create_simple_function(element::f32, Shape{5, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES);+ p.output().tensor().set_element_type(element::u8);+ f = p.build();++ EXPECT_EQ(f->get_results().size(), 2);+ // Y plane: [5, 30, 20, 1] converted to u8+ EXPECT_EQ(f->get_results()[0]->get_output_partial_shape(0), (PartialShape{5, 30, 20, 1}));+ EXPECT_EQ(f->get_results()[0]->get_element_type(), element::u8);+ // UV plane: [5, 15, 10, 2] converted to u8+ EXPECT_EQ(f->get_results()[1]->get_output_partial_shape(0), (PartialShape{5, 15, 10, 2}));+ EXPECT_EQ(f->get_results()[1]->get_element_type(), element::u8);++ auto y_names = f->output(0).get_tensor().get_names();+ auto uv_names = f->output(1).get_tensor().get_names();+ EXPECT_EQ(y_names.count("tensor_output1/Y"), 1);+ EXPECT_EQ(uv_names.count("tensor_output1/UV"), 1);+}++TEST(pre_post_process, postprocess_convert_color_format_RGB_NV12_two_planes_with_layout) {+ auto f = create_simple_function(element::f32, Shape{5, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES);+ p.output().tensor().set_layout("NCHW");+ f = p.build();++ EXPECT_EQ(f->get_results().size(), 2);+ // Y plane: [5, 30, 20, 1] transposed NHWC->NCHW = [5, 1, 30, 20]+ EXPECT_EQ(f->get_results()[0]->get_output_partial_shape(0), (PartialShape{5, 1, 30, 20}));+ EXPECT_EQ(f->get_results()[0]->get_layout(), "NCHW");+ // UV plane: [5, 15, 10, 2] transposed NHWC->NCHW = [5, 2, 15, 10]+ EXPECT_EQ(f->get_results()[1]->get_output_partial_shape(0), (PartialShape{5, 2, 15, 10}));+ EXPECT_EQ(f->get_results()[1]->get_layout(), "NCHW");++ auto y_names = f->output(0).get_tensor().get_names();+ auto uv_names = f->output(1).get_tensor().get_names();+ EXPECT_EQ(y_names.count("tensor_output1/Y"), 1);+ EXPECT_EQ(uv_names.count("tensor_output1/UV"), 1);+}++TEST(pre_post_process, postprocess_convert_color_format_RGB_NV12_two_planes_with_type_and_layout) {+ auto f = create_simple_function(element::f32, Shape{5, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES);+ p.output().tensor().set_element_type(element::u8).set_layout("NCHW");+ f = p.build();++ EXPECT_EQ(f->get_results().size(), 2);+ // Y plane: [5, 30, 20, 1] -> u8, transposed NHWC->NCHW = [5, 1, 30, 20]+ EXPECT_EQ(f->get_results()[0]->get_output_partial_shape(0), (PartialShape{5, 1, 30, 20}));+ EXPECT_EQ(f->get_results()[0]->get_element_type(), element::u8);+ EXPECT_EQ(f->get_results()[0]->get_layout(), "NCHW");+ // UV plane: [5, 15, 10, 2] -> u8, transposed NHWC->NCHW = [5, 2, 15, 10]+ EXPECT_EQ(f->get_results()[1]->get_output_partial_shape(0), (PartialShape{5, 2, 15, 10}));+ EXPECT_EQ(f->get_results()[1]->get_element_type(), element::u8);+ EXPECT_EQ(f->get_results()[1]->get_layout(), "NCHW");++ auto y_names = f->output(0).get_tensor().get_names();+ auto uv_names = f->output(1).get_tensor().get_names();++ EXPECT_EQ(y_names.count("tensor_output1/Y"), 1);+ EXPECT_EQ(uv_names.count("tensor_output1/UV"), 1);+}++TEST(pre_post_process, postprocess_convert_color_format_BGR_NV12_single_plane) {+ auto f = create_simple_function(element::f32, Shape{5, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::BGR);+ p.output().postprocess().convert_color(ColorFormat::NV12_SINGLE_PLANE);+ f = p.build();++ EXPECT_EQ(f->get_results().size(), 1);+ EXPECT_EQ(f->get_result()->get_output_partial_shape(0), (PartialShape{5, 45, 20, 1}));+}++TEST(pre_post_process, postprocess_convert_color_format_RGB_NV12_dynamic_batch) {+ auto f = create_simple_function(element::f32, PartialShape{-1, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_SINGLE_PLANE);+ f = p.build();++ EXPECT_EQ(f->get_results().size(), 1);+ EXPECT_EQ(f->get_result()->get_output_partial_shape(0), (PartialShape{-1, 45, 20, 1}));+}+// Verify that two explicit steps added after convert_color(NV12_TWO_PLANES) are both+// applied to the UV plane.+TEST(pre_post_process, postprocess_nv12_two_planes_multiple_explicit_actions_mirrored_on_uv) {+ auto f = create_simple_function(element::f32, Shape{1, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output()+ .postprocess()+ .convert_color(ColorFormat::NV12_TWO_PLANES)+ .convert_element_type(element::u8)+ .convert_layout("NCHW");+ f = p.build();++ ASSERT_EQ(f->get_results().size(), 2);+ EXPECT_EQ(f->get_results()[0]->get_output_partial_shape(0), (PartialShape{1, 1, 30, 20}));+ EXPECT_EQ(f->get_results()[0]->get_element_type(), element::u8);+ EXPECT_EQ(f->get_results()[1]->get_output_partial_shape(0), (PartialShape{1, 2, 15, 10}));+ EXPECT_EQ(f->get_results()[1]->get_element_type(), element::u8);+}+// Verify that two implicit steps added after convert_color(NV12_TWO_PLANES) are both+// applied to the UV plane.+TEST(pre_post_process, postprocess_nv12_two_planes_both_implicit_steps_applied_on_uv) {+ auto f = create_simple_function(element::f32, Shape{1, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES);+ // Implicit layout and type conversions+ p.output().tensor().set_element_type(element::u8).set_layout("NCHW");+ f = p.build();++ ASSERT_EQ(f->get_results().size(), 2);+ // Y plane: shape transposed NHWC->NCHW, element type converted to u8+ EXPECT_EQ(f->get_results()[0]->get_output_partial_shape(0), (PartialShape{1, 1, 30, 20}));+ EXPECT_EQ(f->get_results()[0]->get_element_type(), element::u8);+ EXPECT_EQ(f->get_results()[0]->get_layout(), "NCHW");+ // UV plane: same two implicit steps applied+ EXPECT_EQ(f->get_results()[1]->get_output_partial_shape(0), (PartialShape{1, 2, 15, 10}));+ EXPECT_EQ(f->get_results()[1]->get_element_type(), element::u8);+ EXPECT_EQ(f->get_results()[1]->get_layout(), "NCHW");+}+// Verify the combined path: one explicit post-NV12 step followed by one implicit+// step; both must be applied to the UV plane in the correct order.+TEST(pre_post_process, postprocess_nv12_two_planes_explicit_then_implicit_step_both_applied_on_uv) {+ auto f = create_simple_function(element::f32, Shape{1, 30, 20, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ // Explicit type conversion after NV12+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES).convert_element_type(element::u8);+ // Implicit layout transpose+ p.output().tensor().set_layout("NCHW");+ f = p.build();++ ASSERT_EQ(f->get_results().size(), 2);+ // Y plane+ EXPECT_EQ(f->get_results()[0]->get_output_partial_shape(0), (PartialShape{1, 1, 30, 20}));+ EXPECT_EQ(f->get_results()[0]->get_element_type(), element::u8);+ EXPECT_EQ(f->get_results()[0]->get_layout(), "NCHW");+ // UV plane+ EXPECT_EQ(f->get_results()[1]->get_output_partial_shape(0), (PartialShape{1, 2, 15, 10}));+ EXPECT_EQ(f->get_results()[1]->get_element_type(), element::u8);+ EXPECT_EQ(f->get_results()[1]->get_layout(), "NCHW");+}+// Postprocessing - otherTEST(pre_post_process, postprocess_preserve_rt_info) {diff --git a/src/core/tests/type_prop/convert_color_to_nv12.cpp b/src/core/tests/type_prop/convert_color_to_nv12.cppnew file mode 100644index 00000000000..1a71d97a5dc--- /dev/null+++ b/src/core/tests/type_prop/convert_color_to_nv12.cpp@@ -0,0 +1,13 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "convert_color_to_nv12_base.hpp"+#include "openvino/op/bgr_to_nv12.hpp"+#include "openvino/op/rgb_to_nv12.hpp"++namespace ov::tests {+INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_rgb_to_nv12, ConvertToNV12BaseTest, ::testing::Types<ov::op::v17::RGBtoNV12>);++INSTANTIATE_TYPED_TEST_SUITE_P(type_prop_bgr_to_nv12, ConvertToNV12BaseTest, ::testing::Types<ov::op::v17::BGRtoNV12>);+} // namespace ov::testsdiff --git a/src/core/tests/type_prop/convert_color_to_nv12_base.hpp b/src/core/tests/type_prop/convert_color_to_nv12_base.hppnew file mode 100644index 00000000000..ee9727d8c7c--- /dev/null+++ b/src/core/tests/type_prop/convert_color_to_nv12_base.hpp@@ -0,0 +1,247 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gtest/gtest.h>++#include <vector>++#include "common_test_utils/type_prop.hpp"++using ::testing::ElementsAre;++namespace ov::tests {++template <class T>+class ConvertToNV12BaseTest : public TypePropOpTest<T> {};++TYPED_TEST_SUITE_P(ConvertToNV12BaseTest);++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_single_plane_default_ctor) {+ auto param_shape = ov::PartialShape{5, 4, 6, 3};+ auto symbols = set_shape_symbols(param_shape);+ auto out_shape = ov::PartialShape{5, 6, 6, 1}; // H*3/2 = 4*3/2 = 6+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, param_shape);++ auto op = this->make_op();+ op->set_argument(0, param);+ op->validate_and_infer_types();++ EXPECT_EQ(op->get_output_size(), 1);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::f32);+ EXPECT_EQ(op->output(0).get_partial_shape(), out_shape);+ EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(0)),+ ElementsAre(symbols[0], nullptr, symbols[2], nullptr));+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_single_plane) {+ auto param_shape = ov::PartialShape{1, 4, 6, 3};+ auto symbols = set_shape_symbols(param_shape);+ auto out_shape = ov::PartialShape{1, 6, 6, 1};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ auto op = this->make_op(param);+ EXPECT_EQ(op->get_output_size(), 1);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::u8);+ EXPECT_EQ(op->output(0).get_partial_shape(), out_shape);+ EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(0)),+ ElementsAre(symbols[0], nullptr, symbols[2], nullptr));+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_single_plane_explicit_true) {+ auto param_shape = ov::PartialShape{2, 8, 10, 3};+ auto out_shape = ov::PartialShape{2, 12, 10, 1};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, param_shape);+ auto op = this->make_op(param, true);+ EXPECT_EQ(op->get_output_size(), 1);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::f32);+ EXPECT_EQ(op->output(0).get_partial_shape(), out_shape);+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_single_plane_dynamic) {+ auto param_shape = ov::PartialShape::dynamic();+ auto out_shape = ov::PartialShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic(), 1};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, param_shape);+ auto op = this->make_op(param);+ EXPECT_EQ(op->get_output_size(), 1);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::f32);+ EXPECT_EQ(op->output(0).get_partial_shape(), out_shape);+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_single_plane_dynamic_dims) {+ auto param_shape = ov::PartialShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), 8, 3};+ auto out_shape = ov::PartialShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), 8, 1};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ auto op = this->make_op(param);+ EXPECT_EQ(op->output(0).get_partial_shape(), out_shape);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::u8);+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_single_plane_dynamic_type) {+ auto param_shape = ov::PartialShape{1, 4, 6, 3};+ auto out_shape = ov::PartialShape{1, 6, 6, 1};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::dynamic, param_shape);+ auto op = this->make_op(param);+ EXPECT_EQ(op->output(0).get_partial_shape(), out_shape);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::dynamic);+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_two_plane) {+ auto param_shape = ov::PartialShape{1, 480, 640, 3};+ auto y_shape = ov::PartialShape{1, 480, 640, 1};+ auto uv_shape = ov::PartialShape{1, 240, 320, 2};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ auto op = this->make_op(param, false);+ EXPECT_EQ(op->get_output_size(), 2);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::u8);+ EXPECT_EQ(op->output(0).get_partial_shape(), y_shape);+ EXPECT_EQ(op->output(1).get_element_type(), ov::element::u8);+ EXPECT_EQ(op->output(1).get_partial_shape(), uv_shape);+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_two_plane_dynamic) {+ auto param_shape = ov::PartialShape::dynamic();+ auto out_y_shape =+ ov::PartialShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic(), 1};+ auto out_uv_shape =+ ov::PartialShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), ov::Dimension::dynamic(), 2};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, param_shape);+ auto op = this->make_op(param, false);+ EXPECT_EQ(op->get_output_size(), 2);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::f32);+ EXPECT_EQ(op->output(1).get_element_type(), ov::element::f32);++ EXPECT_EQ(op->output(0).get_partial_shape(), out_y_shape);+ EXPECT_EQ(op->output(1).get_partial_shape(), out_uv_shape);+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_two_plane_small) {+ auto param_shape = ov::PartialShape{2, 4, 6, 3};+ auto y_shape = ov::PartialShape{2, 4, 6, 1};+ auto uv_shape = ov::PartialShape{2, 2, 3, 2};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, param_shape);+ auto op = this->make_op(param, false);+ EXPECT_EQ(op->get_output_size(), 2);+ EXPECT_EQ(op->output(0).get_partial_shape(), y_shape);+ EXPECT_EQ(op->output(1).get_partial_shape(), uv_shape);+}++TYPED_TEST_P(ConvertToNV12BaseTest, error_channels_not_3) {+ auto param_shape = ov::PartialShape{1, 4, 6, 1}; // C=1, not 3+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ EXPECT_THROW(std::ignore = this->make_op(param), ov::AssertFailure);+}++TYPED_TEST_P(ConvertToNV12BaseTest, error_rank_5) {+ auto param_shape = ov::PartialShape{1, 4, 6, 3, 1}; // 5 dims+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ EXPECT_THROW(std::ignore = this->make_op(param), ov::AssertFailure);+}++TYPED_TEST_P(ConvertToNV12BaseTest, error_rank_3) {+ auto param_shape = ov::PartialShape{4, 6, 3}; // 3 dims+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ EXPECT_THROW(std::ignore = this->make_op(param), ov::AssertFailure);+}++TYPED_TEST_P(ConvertToNV12BaseTest, error_height_odd) {+ auto param_shape = ov::PartialShape{1, 5, 6, 3}; // H=5 is odd+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ EXPECT_THROW(std::ignore = this->make_op(param), ov::AssertFailure);+}++TYPED_TEST_P(ConvertToNV12BaseTest, error_width_odd) {+ auto param_shape = ov::PartialShape{1, 4, 5, 3}; // W=5 is odd+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ EXPECT_THROW(std::ignore = this->make_op(param), ov::AssertFailure);+}++TYPED_TEST_P(ConvertToNV12BaseTest, error_unsupported_type_i8) {+ auto param_shape = ov::PartialShape{1, 4, 6, 3};+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::i8, param_shape);+ EXPECT_THROW(std::ignore = this->make_op(param), ov::AssertFailure);+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_single_plane_interval_dims) {+ auto param_shape = ov::PartialShape{{2, 10}, {4, 20}, 8, 3};+ auto symbols = set_shape_symbols(param_shape);+ auto out_shape = ov::PartialShape{{2, 10}, {6, 30}, 8, 1}; // H*3/2+ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ auto op = this->make_op(param);+ EXPECT_EQ(op->output(0).get_partial_shape(), out_shape);+ EXPECT_EQ(op->output(0).get_element_type(), ov::element::u8);+ EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(0)),+ ElementsAre(symbols[0], nullptr, symbols[2], nullptr));+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_two_plane_dynamic_dims) {+ auto param_shape = ov::PartialShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), 8, 3};+ auto expected_y_shape = ov::PartialShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), 8, 1};+ auto expected_uv_shape = ov::PartialShape{ov::Dimension::dynamic(), ov::Dimension::dynamic(), 4, 2};++ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);+ auto op = this->make_op(param, false);++ EXPECT_EQ(op->get_output_size(), 2);+ EXPECT_EQ(op->output(0).get_partial_shape(), expected_y_shape);+ EXPECT_EQ(op->output(1).get_partial_shape(), expected_uv_shape);+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_two_plane_interval_dims_and_symbols) {+ auto param_shape = ov::PartialShape{{2, 10}, {4, 20}, {6, 12}, 3};+ auto symbols = set_shape_symbols(param_shape);++ auto expected_y_shape = ov::PartialShape{{2, 10}, {4, 20}, {6, 12}, 1};+ auto expected_uv_shape = ov::PartialShape{{2, 10}, {2, 10}, {3, 6}, 2};++ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, param_shape);+ auto op = this->make_op(param, false);++ EXPECT_EQ(op->get_output_size(), 2);+ EXPECT_EQ(op->output(0).get_partial_shape(), expected_y_shape);+ EXPECT_EQ(op->output(1).get_partial_shape(), expected_uv_shape);++ EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(0)),+ ElementsAre(symbols[0], symbols[1], symbols[2], nullptr));++ EXPECT_THAT(get_shape_symbols(op->get_output_partial_shape(1)), ElementsAre(symbols[0], nullptr, nullptr, nullptr));+}++TYPED_TEST_P(ConvertToNV12BaseTest, shape_inference_two_plane_dynamic_type) {+ auto param_shape = ov::PartialShape{1, 480, 640, 3};+ auto out_y_shape = ov::PartialShape{1, 480, 640, 1};+ auto out_uv_shape = ov::PartialShape{1, 240, 320, 2};++ auto param = std::make_shared<ov::op::v0::Parameter>(ov::element::dynamic, param_shape);+ auto op = this->make_op(param, false);++ EXPECT_EQ(op->get_output_size(), 2);++ EXPECT_EQ(op->output(0).get_element_type(), ov::element::dynamic);+ EXPECT_EQ(op->output(1).get_element_type(), ov::element::dynamic);++ EXPECT_EQ(op->output(0).get_partial_shape(), out_y_shape);+ EXPECT_EQ(op->output(1).get_partial_shape(), out_uv_shape);+}++REGISTER_TYPED_TEST_SUITE_P(ConvertToNV12BaseTest,+ shape_inference_single_plane_default_ctor,+ shape_inference_single_plane,+ shape_inference_single_plane_explicit_true,+ shape_inference_single_plane_dynamic,+ shape_inference_single_plane_dynamic_dims,+ shape_inference_single_plane_dynamic_type,+ shape_inference_two_plane,+ shape_inference_two_plane_dynamic,+ shape_inference_two_plane_small,+ error_channels_not_3,+ error_rank_5,+ error_rank_3,+ error_height_odd,+ error_width_odd,+ error_unsupported_type_i8,+ shape_inference_single_plane_interval_dims,+ shape_inference_two_plane_dynamic_dims,+ shape_inference_two_plane_interval_dims_and_symbols,+ shape_inference_two_plane_dynamic_type);++} // namespace ov::testsdiff --git a/src/core/tests/type_prop/sources.cmake b/src/core/tests/type_prop/sources.cmakeindex 380ccaffdda..5636ca696a8 100644--- a/src/core/tests/type_prop/sources.cmake+++ b/src/core/tests/type_prop/sources.cmake@@ -37,6 +37,7 @@ set(OV_CORE_TESTS_TYPE_PROP_SRCS${CMAKE_CURRENT_LIST_DIR}/convert.cpp${CMAKE_CURRENT_LIST_DIR}/convert_color_i420.cpp${CMAKE_CURRENT_LIST_DIR}/convert_color_nv12.cpp+ ${CMAKE_CURRENT_LIST_DIR}/convert_color_to_nv12.cpp${CMAKE_CURRENT_LIST_DIR}/convert_promote_types.cpp${CMAKE_CURRENT_LIST_DIR}/convolution.cpp${CMAKE_CURRENT_LIST_DIR}/convolution_backprop_data.cppdiff --git a/src/core/tests/visitors/op/convert_color_to_nv12.cpp b/src/core/tests/visitors/op/convert_color_to_nv12.cppnew file mode 100644index 00000000000..f452725d2ca--- /dev/null+++ b/src/core/tests/visitors/op/convert_color_to_nv12.cpp@@ -0,0 +1,58 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gtest/gtest.h>++#include "openvino/op/bgr_to_nv12.hpp"+#include "openvino/op/rgb_to_nv12.hpp"+#include "visitors/visitors.hpp"++using ov::test::NodeBuilder;++namespace ov::tests {++TEST(attributes, convert_color_rgb_to_nv12_single_plane) {+ NodeBuilder::opset().insert<ov::op::v17::RGBtoNV12>();+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{3, 480, 640, 3});+ auto convert_color = std::make_shared<ov::op::v17::RGBtoNV12>(data);+ NodeBuilder builder(convert_color, {data});+ EXPECT_NO_THROW(auto g_op = ov::as_type_ptr<ov::op::v17::RGBtoNV12>(builder.create()));++ const auto expected_attr_count = 1; // single_plane attribute+ EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);+}++TEST(attributes, convert_color_rgb_to_nv12_two_planes) {+ NodeBuilder::opset().insert<ov::op::v17::RGBtoNV12>();+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{3, 480, 640, 3});+ auto convert_color = std::make_shared<ov::op::v17::RGBtoNV12>(data, false);+ NodeBuilder builder(convert_color, {data});+ EXPECT_NO_THROW(auto g_op = ov::as_type_ptr<ov::op::v17::RGBtoNV12>(builder.create()));++ const auto expected_attr_count = 1;+ EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);+}++TEST(attributes, convert_color_bgr_to_nv12_single_plane) {+ NodeBuilder::opset().insert<ov::op::v17::BGRtoNV12>();+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{3, 480, 640, 3});+ auto convert_color = std::make_shared<ov::op::v17::BGRtoNV12>(data);+ NodeBuilder builder(convert_color, {data});+ EXPECT_NO_THROW(auto g_op = ov::as_type_ptr<ov::op::v17::BGRtoNV12>(builder.create()));++ const auto expected_attr_count = 1;+ EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);+}++TEST(attributes, convert_color_bgr_to_nv12_two_planes) {+ NodeBuilder::opset().insert<ov::op::v17::BGRtoNV12>();+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{3, 480, 640, 3});+ auto convert_color = std::make_shared<ov::op::v17::BGRtoNV12>(data, false);+ NodeBuilder builder(convert_color, {data});+ EXPECT_NO_THROW(auto g_op = ov::as_type_ptr<ov::op::v17::BGRtoNV12>(builder.create()));++ const auto expected_attr_count = 1;+ EXPECT_EQ(builder.get_value_map_size(), expected_attr_count);+}+} // namespace ov::testsdiff --git a/src/core/tests/visitors/sources.cmake b/src/core/tests/visitors/sources.cmakeindex 313c5845f88..6e2f877d30f 100644--- a/src/core/tests/visitors/sources.cmake+++ b/src/core/tests/visitors/sources.cmake@@ -39,6 +39,7 @@ set(OV_CORE_TESTS_VISITORS_SRCS${CMAKE_CURRENT_LIST_DIR}/op/convert.cpp${CMAKE_CURRENT_LIST_DIR}/op/convert_color_i420.cpp${CMAKE_CURRENT_LIST_DIR}/op/convert_color_nv12.cpp+ ${CMAKE_CURRENT_LIST_DIR}/op/convert_color_to_nv12.cpp${CMAKE_CURRENT_LIST_DIR}/op/convert_like.cpp${CMAKE_CURRENT_LIST_DIR}/op/convert_promote_types.cpp${CMAKE_CURRENT_LIST_DIR}/op/convolution.cppdiff --git a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cppindex f2728b35f8b..4c03a5164fb 100644--- a/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp+++ b/src/plugins/intel_cpu/tests/functional/shared_tests_instances/skip_tests_config.cpp@@ -63,6 +63,8 @@ const std::vector<std::regex>& disabled_test_patterns() {std::regex(R"(.*OVClassQueryModelTest.*QueryModelWithDeviceID.*)"),// Issue 67214std::regex(R"(smoke_PrePostProcess.*resize_and_convert_layout_i8.*)"),+ // TODO: Implement RGBtoNV12/BGRtoNV12 in CPU plugin.+ std::regex(R"(.*smoke_PostProcess.*convert_color_(rgb|bgr)_to_nv12.*)"),// Issue: 69086// need to add support convert BIN -> FP32// if we set output precision as BIN, when we create output blob precision looks like UNSPECIFIEDdiff --git a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cppindex 62030ff531d..1add0b08c69 100644--- a/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp+++ b/src/plugins/intel_gpu/tests/functional/shared_tests_instances/skip_tests_config.cpp@@ -63,6 +63,8 @@ const std::vector<std::regex>& disabled_test_patterns() {std::regex(R"(.*smoke.*BehaviorTests.*InferFullyDynamicNetworkWith(S|G)etTensor.*)"),std::regex(R"(.*smoke.*BehaviorTests.*DynamicOutputToDynamicInput.*)"),std::regex(R"(.*smoke.*BehaviorTests.*DynamicInputToDynamicOutput.*)"),+ // TODO: Implement RGBtoNV12/BGRtoNV12 in GPU plugin.+ std::regex(R"(.*smoke_PostProcess.*convert_color_(rgb|bgr)_to_nv12.*)"),// TODO: Issue: 180519std::regex(R"(.*CoreThreadingTestsWithIter.*)"),// TODO: Issue: 145926diff --git a/src/plugins/template/backend/ops/convert_color_to_nv12.cpp b/src/plugins/template/backend/ops/convert_color_to_nv12.cppnew file mode 100644index 00000000000..8cb28d3e64f--- /dev/null+++ b/src/plugins/template/backend/ops/convert_color_to_nv12.cpp@@ -0,0 +1,97 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "openvino/reference/convert_color_to_nv12.hpp"++#include "evaluate_node.hpp"+#include "openvino/op/bgr_to_nv12.hpp"+#include "openvino/op/rgb_to_nv12.hpp"+#include "rgb_bgr_to_nv12_shape_inference.hpp"++namespace {+template <ov::element::Type_t ET, bool IsRGB>+bool evaluate_nv12(const ov::op::util::ConvertColorToNV12Base* op,+ ov::TensorVector& outputs,+ const ov::TensorVector& inputs) {+ using T = typename ov::element_type_traits<ET>::value_type;++ const auto input_shapes = ov::util::get_tensors_partial_shapes(inputs);+ const auto output_shapes = ov::op::shape_infer(op, input_shapes);+ for (size_t i = 0; i < outputs.size(); ++i)+ outputs[i].set_shape(output_shapes[i].to_shape());++ const auto& rgb_tensor = inputs[0];+ const auto batch_size = rgb_tensor.get_shape()[0];+ const auto image_h = rgb_tensor.get_shape()[1];+ const auto image_w = rgb_tensor.get_shape()[2];+ const bool single_plane = op->get_output_size() == 1;++ ov::reference::color_convert_to_nv12<T, IsRGB>(rgb_tensor.data<T>(),+ outputs[0].data<T>(),+ single_plane ? nullptr : outputs[1].data<T>(),+ batch_size,+ image_h,+ image_w,+ single_plane);+ return true;+}+} // namespace++template <ov::element::Type_t ET>+inline bool evaluate(const std::shared_ptr<ov::op::v17::RGBtoNV12>& op,+ ov::TensorVector& outputs,+ const ov::TensorVector& inputs) {+ return evaluate_nv12<ET, true>(op.get(), outputs, inputs);+}++template <ov::element::Type_t ET>+inline bool evaluate(const std::shared_ptr<ov::op::v17::BGRtoNV12>& op,+ ov::TensorVector& outputs,+ const ov::TensorVector& inputs) {+ return evaluate_nv12<ET, false>(op.get(), outputs, inputs);+}++template <>+bool evaluate_node<ov::op::v17::RGBtoNV12>(std::shared_ptr<ov::Node> node,+ ov::TensorVector& outputs,+ const ov::TensorVector& inputs) {+ const auto& element_type = node->get_output_element_type(0);++ switch (element_type) {+ case ov::element::bf16:+ return evaluate<ov::element::bf16>(ov::as_type_ptr<ov::op::v17::RGBtoNV12>(node), outputs, inputs);+ case ov::element::f16:+ return evaluate<ov::element::f16>(ov::as_type_ptr<ov::op::v17::RGBtoNV12>(node), outputs, inputs);+ case ov::element::f64:+ return evaluate<ov::element::f64>(ov::as_type_ptr<ov::op::v17::RGBtoNV12>(node), outputs, inputs);+ case ov::element::f32:+ return evaluate<ov::element::f32>(ov::as_type_ptr<ov::op::v17::RGBtoNV12>(node), outputs, inputs);+ case ov::element::u8:+ return evaluate<ov::element::u8>(ov::as_type_ptr<ov::op::v17::RGBtoNV12>(node), outputs, inputs);+ default:+ OPENVINO_THROW("Unhandled data type ", element_type, " in evaluate_node()");+ }+}++template <>+bool evaluate_node<ov::op::v17::BGRtoNV12>(std::shared_ptr<ov::Node> node,+ ov::TensorVector& outputs,+ const ov::TensorVector& inputs) {+ const auto& element_type = node->get_output_element_type(0);++ switch (element_type) {+ case ov::element::bf16:+ return evaluate<ov::element::bf16>(ov::as_type_ptr<ov::op::v17::BGRtoNV12>(node), outputs, inputs);+ case ov::element::f16:+ return evaluate<ov::element::f16>(ov::as_type_ptr<ov::op::v17::BGRtoNV12>(node), outputs, inputs);+ case ov::element::f64:+ return evaluate<ov::element::f64>(ov::as_type_ptr<ov::op::v17::BGRtoNV12>(node), outputs, inputs);+ case ov::element::f32:+ return evaluate<ov::element::f32>(ov::as_type_ptr<ov::op::v17::BGRtoNV12>(node), outputs, inputs);+ case ov::element::u8:+ return evaluate<ov::element::u8>(ov::as_type_ptr<ov::op::v17::BGRtoNV12>(node), outputs, inputs);+ default:+ OPENVINO_THROW("Unhandled data type ", element_type, " in evaluate_node()");+ }+}diff --git a/src/plugins/template/backend/ops/ops_evaluates.hpp b/src/plugins/template/backend/ops/ops_evaluates.hppindex 713b19ba6f5..23739a6229e 100644--- a/src/plugins/template/backend/ops/ops_evaluates.hpp+++ b/src/plugins/template/backend/ops/ops_evaluates.hpp@@ -542,6 +542,14 @@ extern template bool evaluate_node<ov::op::v16::ISTFT>(std::shared_ptr<ov::Node>ov::TensorVector& outputs,const ov::TensorVector& inputs);+extern template bool evaluate_node<ov::op::v17::RGBtoNV12>(std::shared_ptr<ov::Node> node,+ ov::TensorVector& outputs,+ const ov::TensorVector& inputs);++extern template bool evaluate_node<ov::op::v17::BGRtoNV12>(std::shared_ptr<ov::Node> node,+ ov::TensorVector& outputs,+ const ov::TensorVector& inputs);+extern template bool evaluate_node<ov::op::internal::AUGRUCell>(std::shared_ptr<ov::Node> node,ov::TensorVector& outputs,const ov::TensorVector& inputs);diff --git a/src/plugins/template/backend/opset_int_tbl.hpp b/src/plugins/template/backend/opset_int_tbl.hppindex 0139c1d1706..79a6c92e93e 100644--- a/src/plugins/template/backend/opset_int_tbl.hpp+++ b/src/plugins/template/backend/opset_int_tbl.hpp@@ -186,6 +186,8 @@ _OPENVINO_OP_REG(ISTFT, ov::op::v16)_OPENVINO_OP_REG(SegmentMax, ov::op::v16)_OPENVINO_OP_REG(SparseFillEmptyRows, ov::op::v16)_OPENVINO_OP_REG(OneHot, ov::op::v16)+_OPENVINO_OP_REG(RGBtoNV12, ov::op::v17)+_OPENVINO_OP_REG(BGRtoNV12, ov::op::v17)_OPENVINO_OP_REG(AUGRUCell, ov::op::internal)_OPENVINO_OP_REG(AUGRUSequence, ov::op::internal)diff --git a/src/plugins/template/tests/functional/op_reference/convert_color_to_nv12.cpp b/src/plugins/template/tests/functional/op_reference/convert_color_to_nv12.cppnew file mode 100644index 00000000000..2ca6c9f84ce--- /dev/null+++ b/src/plugins/template/tests/functional/op_reference/convert_color_to_nv12.cpp@@ -0,0 +1,398 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gtest/gtest.h>++#include "base_reference_test.hpp"+#include "functional_test_utils/skip_tests_config.hpp"+#include "openvino/core/model.hpp"+#include "openvino/op/bgr_to_nv12.hpp"+#include "openvino/op/nv12_to_bgr.hpp"+#include "openvino/op/nv12_to_rgb.hpp"+#include "openvino/op/rgb_to_nv12.hpp"++namespace ov::tests {+class ReferenceConvertColorToNV12LayerTest : public testing::Test, public reference_tests::CommonReferenceTest {+public:+ void SetUp() override {+ SKIP_IF_CURRENT_TEST_IS_DISABLED()+ abs_threshold = 2.f; // allow Y, U, V absolute deviation to 2 (of max 255)+ threshold = 1.f; // Ignore relative comparison (100%)+ }++public:+ template <typename T>+ static std::shared_ptr<ov::Model> CreateFunction(const reference_tests::Tensor& input) {+ const auto in = std::make_shared<ov::op::v0::Parameter>(input.type, input.shape);+ auto conv = std::make_shared<T>(in);+ auto res = std::make_shared<ov::op::v0::Result>(conv);+ return std::make_shared<ov::Model>(ov::ResultVector{res}, ov::ParameterVector{in});+ }++ template <typename T>+ static std::shared_ptr<ov::Model> CreateFunction2Plane(const reference_tests::Tensor& input) {+ const auto in = std::make_shared<ov::op::v0::Parameter>(input.type, input.shape);+ auto conv = std::make_shared<T>(in, false);+ auto res_y = std::make_shared<ov::op::v0::Result>(conv->output(0));+ auto res_uv = std::make_shared<ov::op::v0::Result>(conv->output(1));+ return std::make_shared<ov::Model>(ov::ResultVector{res_y, res_uv}, ov::ParameterVector{in});+ }++ template <typename NV12_to_Color, typename Color_to_NV12>+ static std::shared_ptr<ov::Model> CreateRoundTripFunction(const reference_tests::Tensor& input) {+ const auto in = std::make_shared<ov::op::v0::Parameter>(input.type, input.shape);+ auto to_color = std::make_shared<NV12_to_Color>(in);+ auto to_nv12 = std::make_shared<Color_to_NV12>(to_color->output(0));+ auto res = std::make_shared<ov::op::v0::Result>(to_nv12);+ return std::make_shared<ov::Model>(ov::ResultVector{res}, ov::ParameterVector{in});+ }+};++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_red_u8_single_rgb) {+ auto input = std::vector<uint8_t>{255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0};+ auto input_shape = ov::Shape{1, 2, 2, 3};+ auto exp_out = std::vector<uint8_t>{82, 82, 82, 82, 90, 240};+ auto out_shape = ov::Shape{1, 3, 2, 1};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::u8, input);+ inputData = {inp_tensor.data};+ function = CreateFunction<ov::op::v17::RGBtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(out_shape, ov::element::u8, exp_out);+ refOutData = {exp_tensor.data};+ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_green_f32_single_rgb) {+ auto input = std::vector<float>{0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0};+ auto input_shape = ov::Shape{1, 2, 2, 3};+ auto exp_out = std::vector<float>{145.f, 145.f, 145.f, 145.f, 54.f, 34.f};+ auto out_shape = ov::Shape{1, 3, 2, 1};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::f32, input);+ inputData = {inp_tensor.data};++ reference_tests::Tensor exp_tensor(out_shape, ov::element::f32, exp_out);+ refOutData = {exp_tensor.data};++ function = CreateFunction<ov::op::v17::RGBtoNV12>(inp_tensor);++ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_blue_u8_single_bgr) {+ auto input = std::vector<uint8_t>{255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0};+ auto input_shape = ov::Shape{1, 2, 2, 3};+ auto exp_out = std::vector<uint8_t>{41, 41, 41, 41, 240, 110};+ auto out_shape = ov::Shape{1, 3, 2, 1};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::u8, input);+ inputData = {inp_tensor.data};+ function = CreateFunction<ov::op::v17::BGRtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(out_shape, ov::element::u8, exp_out);+ refOutData = {exp_tensor.data};+ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_red_f32_two_rgb) {+ auto input = std::vector<float>{255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0};+ auto input_shape = ov::Shape{1, 2, 2, 3};++ auto exp_y = std::vector<float>{82.f, 82.f, 82.f, 82.f};+ auto exp_y_shape = ov::Shape{1, 2, 2, 1};++ auto exp_uv = std::vector<float>{90.f, 240.f};+ auto exp_uv_shape = ov::Shape{1, 1, 1, 2};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::f32, input);+ inputData = {inp_tensor.data};++ reference_tests::Tensor exp_y_tensor(exp_y_shape, ov::element::f32, exp_y);+ reference_tests::Tensor exp_uv_tensor(exp_uv_shape, ov::element::f32, exp_uv);+ refOutData = {exp_y_tensor.data, exp_uv_tensor.data};++ function = CreateFunction2Plane<ov::op::v17::RGBtoNV12>(inp_tensor);++ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_red_f32_two_bgr) {+ auto input = std::vector<float>{0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f};+ auto input_shape = ov::Shape{1, 2, 2, 3};++ auto exp_y = std::vector<float>{82.f, 82.f, 82.f, 82.f};+ auto exp_y_shape = ov::Shape{1, 2, 2, 1};++ auto exp_uv = std::vector<float>{90.f, 240.f};+ auto exp_uv_shape = ov::Shape{1, 1, 1, 2};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::f32, input);+ inputData = {inp_tensor.data};++ reference_tests::Tensor exp_y_tensor(exp_y_shape, ov::element::f32, exp_y);+ reference_tests::Tensor exp_uv_tensor(exp_uv_shape, ov::element::f32, exp_uv);+ refOutData = {exp_y_tensor.data, exp_uv_tensor.data};++ function = CreateFunction2Plane<ov::op::v17::BGRtoNV12>(inp_tensor);++ Exec();+}++// clang-format off++// Multi-batch tests (N = 2)+TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_multibatch_u8_single_rgb) {+ auto input = std::vector<uint8_t>{+ 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, // batch 0: (red)+ 0, 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, // batch 1: (green)+ };+ auto input_shape = ov::Shape{2, 2, 2, 3};+ // Single-plane shape [N, H*3/2, W, 1] = [2, 3, 2, 1]+ auto exp_out = std::vector<uint8_t>{82, 82, 82, 82, 90, 240, // batch 0+ 145, 145, 145, 145, 54, 34}; // batch 1+ auto out_shape = ov::Shape{2, 3, 2, 1};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::u8, input);+ inputData = {inp_tensor.data};+ function = CreateFunction<ov::op::v17::RGBtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(out_shape, ov::element::u8, exp_out);+ refOutData = {exp_tensor.data};+ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_multibatch_f32_two_bgr) {+ auto input = std::vector<float>{+ 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, // batch 0: (red)+ 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, // batch 1: (green)+ };+ auto input_shape = ov::Shape{2, 2, 2, 3};++ auto exp_y = std::vector<float>{82.f, 82.f, 82.f, 82.f, // batch 0+ 145.f, 145.f, 145.f, 145.f}; // batch 1+ auto exp_y_shape = ov::Shape{2, 2, 2, 1};++ auto exp_uv = std::vector<float>{90.f, 240.f, // batch 0+ 54.f, 34.f}; // batch 1+ auto exp_uv_shape = ov::Shape{2, 1, 1, 2};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::f32, input);+ inputData = {inp_tensor.data};++ reference_tests::Tensor exp_y_tensor(exp_y_shape, ov::element::f32, exp_y);+ reference_tests::Tensor exp_uv_tensor(exp_uv_shape, ov::element::f32, exp_uv);+ refOutData = {exp_y_tensor.data, exp_uv_tensor.data};++ function = CreateFunction2Plane<ov::op::v17::BGRtoNV12>(inp_tensor);+ Exec();+}++// Mixed-color 2×2 block tests+TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_mixed_colors_u8_single_rgb) {+ auto input = std::vector<uint8_t>{+ 255, 0, 0,+ 0, 255, 0,+ 0, 0, 255,+ 255, 255, 255,+ };+ auto input_shape = ov::Shape{1, 2, 2, 3};++ auto exp_out = std::vector<uint8_t>{82, 145, 41, 235, 128, 128};+ auto out_shape = ov::Shape{1, 3, 2, 1};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::u8, input);+ inputData = {inp_tensor.data};+ function = CreateFunction<ov::op::v17::RGBtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(out_shape, ov::element::u8, exp_out);+ refOutData = {exp_tensor.data};+ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_mixed_colors_u8_single_bgr) {+ auto input = std::vector<uint8_t>{+ 0, 0, 255,+ 0, 255, 0,+ 255, 0, 0,+ 255, 255, 255,+ };+ auto input_shape = ov::Shape{1, 2, 2, 3};+ auto exp_out = std::vector<uint8_t>{82, 145, 41, 235, 128, 128};+ auto out_shape = ov::Shape{1, 3, 2, 1};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::u8, input);+ inputData = {inp_tensor.data};+ function = CreateFunction<ov::op::v17::BGRtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(out_shape, ov::element::u8, exp_out);+ refOutData = {exp_tensor.data};+ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_mixed_colors_u8_two_bgr) {+ auto input = std::vector<uint8_t>{+ 0, 0, 255,+ 0, 255, 0,+ 255, 0, 0,+ 255, 255, 255,+ };+ auto input_shape = ov::Shape{1, 2, 2, 3};++ auto exp_y = std::vector<uint8_t>{82, 145, 41, 235};+ auto exp_y_shape = ov::Shape{1, 2, 2, 1};+ auto exp_uv = std::vector<uint8_t>{128, 128};+ auto exp_uv_shape = ov::Shape{1, 1, 1, 2};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::u8, input);+ inputData = {inp_tensor.data};++ reference_tests::Tensor exp_y_tensor(exp_y_shape, ov::element::u8, exp_y);+ reference_tests::Tensor exp_uv_tensor(exp_uv_shape, ov::element::u8, exp_uv);+ refOutData = {exp_y_tensor.data, exp_uv_tensor.data};++ function = CreateFunction2Plane<ov::op::v17::BGRtoNV12>(inp_tensor);+ Exec();+}++// Mixed non-primary RGB values:+// (128,64,0) -> Y=81, U=90, V=161+// (0,128,255) -> Y=106, U=203, V=63+// (200,0,128) -> Y=80, U=155, V=207+// (64,200,100) -> Y=143, U=104, V=75+// avg U = (90+203+155+104)/4 = 138, avg V = 506/4 ~= 127++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_mixed_rgb_values_u8_single_rgb) {+ auto input = std::vector<uint8_t>{+ 128, 64, 0,+ 0, 128, 255,+ 200, 0, 128,+ 64, 200, 100,+ };+ auto input_shape = ov::Shape{1, 2, 2, 3};++ auto exp_out = std::vector<uint8_t>{81, 106, 80, 143, 138, 127};+ auto out_shape = ov::Shape{1, 3, 2, 1};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::u8, input);+ inputData = {inp_tensor.data};+ function = CreateFunction<ov::op::v17::RGBtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(out_shape, ov::element::u8, exp_out);+ refOutData = {exp_tensor.data};+ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_mixed_rgb_values_u8_two_rgb) {+ auto input = std::vector<uint8_t>{+ 128, 64, 0,+ 0, 128, 255,+ 200, 0, 128,+ 64, 200, 100,+ };+ auto input_shape = ov::Shape{1, 2, 2, 3};++ auto exp_y = std::vector<uint8_t>{81, 106, 80, 143};+ auto exp_y_shape = ov::Shape{1, 2, 2, 1};+ auto exp_uv = std::vector<uint8_t>{138, 127};+ auto exp_uv_shape = ov::Shape{1, 1, 1, 2};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::u8, input);+ inputData = {inp_tensor.data};++ reference_tests::Tensor exp_y_tensor(exp_y_shape, ov::element::u8, exp_y);+ reference_tests::Tensor exp_uv_tensor(exp_uv_shape, ov::element::u8, exp_uv);+ refOutData = {exp_y_tensor.data, exp_uv_tensor.data};++ function = CreateFunction2Plane<ov::op::v17::RGBtoNV12>(inp_tensor);+ Exec();+}++// 4×4 image tests++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_4x4_f32_single_rgb) {+ auto input = std::vector<float>{+ 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, // row 0 (red)+ 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, // row 1 (red)+ 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, // row 2 (green)+ 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, // row 3 (green)+ };+ auto input_shape = ov::Shape{1, 4, 4, 3};++ auto exp_out = std::vector<float>{+ 81.535f, 81.535f, 81.535f, 81.535f, // Y row 0 (red)+ 81.535f, 81.535f, 81.535f, 81.535f, // Y row 1 (red)+ 144.52f, 144.52f, 144.52f, 144.52f, // Y row 2 (green)+ 144.52f, 144.52f, 144.52f, 144.52f, // Y row 3 (green)+ 90.26f, 239.945f, 90.26f, 239.945f, // UV row 0+ 53.795f, 34.16f, 53.795f, 34.16f, // UV row 1+ };+ auto out_shape = ov::Shape{1, 6, 4, 1};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::f32, input);+ inputData = {inp_tensor.data};+ function = CreateFunction<ov::op::v17::RGBtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(out_shape, ov::element::f32, exp_out);+ refOutData = {exp_tensor.data};+ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, CompareWithHardcodedRefs_4x4_f32_two_bgr) {+ auto input = std::vector<float>{+ 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, // row 0 (blue)+ 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, // row 1 (blue)+ 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, // row 2 (green)+ 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, 0, 255.f, 0, // row 3 (green)+ };+ auto input_shape = ov::Shape{1, 4, 4, 3};++ // Y plane [1, 4, 4, 1]+ auto exp_y = std::vector<float>{+ 40.99f, 40.99f, 40.99f, 40.99f,+ 40.99f, 40.99f, 40.99f, 40.99f,+ 144.52f, 144.52f, 144.52f, 144.52f,+ 144.52f, 144.52f, 144.52f, 144.52f,+ };+ auto exp_y_shape = ov::Shape{1, 4, 4, 1};++ auto exp_uv = std::vector<float>{+ 239.945f, 109.895f, 239.945f, 109.895f,+ 53.795f, 34.16f, 53.795f, 34.16f,+ };+ auto exp_uv_shape = ov::Shape{1, 2, 2, 2};++ reference_tests::Tensor inp_tensor(input_shape, ov::element::f32, input);+ inputData = {inp_tensor.data};++ reference_tests::Tensor exp_y_tensor(exp_y_shape, ov::element::f32, exp_y);+ reference_tests::Tensor exp_uv_tensor(exp_uv_shape, ov::element::f32, exp_uv);+ refOutData = {exp_y_tensor.data, exp_uv_tensor.data};++ function = CreateFunction2Plane<ov::op::v17::BGRtoNV12>(inp_tensor);+ Exec();+}++// clang-format on++// Round-trip tests: NV12 (single-plane) -> decode to color -> re-encode to NV12.+TEST_F(ReferenceConvertColorToNV12LayerTest, RoundTrip_red_u8_NV12toRGBtoNV12) {+ // NV12 (single-plane) for a 2×2 all-red image: Y=82, U=90, V=240.+ auto nv12_data = std::vector<uint8_t>{82, 82, 82, 82, 90, 240};+ auto nv12_shape = ov::Shape{1, 3, 2, 1}; // [N, H*3/2, W, 1]++ reference_tests::Tensor inp_tensor(nv12_shape, ov::element::u8, nv12_data);+ inputData = {inp_tensor.data};+ function = CreateRoundTripFunction<ov::op::v8::NV12toRGB, ov::op::v17::RGBtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(nv12_shape, ov::element::u8, nv12_data);+ refOutData = {exp_tensor.data};+ Exec();+}++TEST_F(ReferenceConvertColorToNV12LayerTest, RoundTrip_green_f32_NV12toBGRtoNV12) {+ // NV12 (single-plane) for a 2×2 all-green image: Y=145, U=54, V=34.+ auto nv12_data = std::vector<float>{145.f, 145.f, 145.f, 145.f, 54.f, 34.f};+ auto nv12_shape = ov::Shape{1, 3, 2, 1};++ reference_tests::Tensor inp_tensor(nv12_shape, ov::element::f32, nv12_data);+ inputData = {inp_tensor.data};+ function = CreateRoundTripFunction<ov::op::v8::NV12toBGR, ov::op::v17::BGRtoNV12>(inp_tensor);+ reference_tests::Tensor exp_tensor(nv12_shape, ov::element::f32, nv12_data);+ refOutData = {exp_tensor.data};+ Exec();+}+} // namespace ov::testsdiff --git a/src/plugins/template/tests/functional/subgraph_reference/preprocess.cpp b/src/plugins/template/tests/functional/subgraph_reference/preprocess.cppindex 689cbb5669e..1d122b8f451 100644--- a/src/plugins/template/tests/functional/subgraph_reference/preprocess.cpp+++ b/src/plugins/template/tests/functional/subgraph_reference/preprocess.cpp@@ -1195,6 +1195,96 @@ static RefPreprocessParams post_convert_color_bgr_to_rgb() {return res;}+static RefPreprocessParams post_convert_color_rgb_to_nv12_single_plane() {+ RefPreprocessParams res("post_convert_color_rgb_to_nv12_single_plane");+ res.abs_threshold = 2.f;+ res.rel_threshold = 1.f;+ res.function = []() {+ auto f = create_simple_function(element::f32, Shape{1, 2, 2, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_SINGLE_PLANE);+ p.build();+ return f;+ };++ // Pure red 2x2: R=255,G=0,B=0 -> Y=82,U=90,V=240+ res.inputs.emplace_back(Shape{1, 2, 2, 3},+ element::f32,+ std::vector<float>{255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0});+ res.expected.emplace_back(Shape{1, 3, 2, 1}, element::f32, std::vector<float>{82, 82, 82, 82, 90, 240});+ return res;+}++static RefPreprocessParams post_convert_color_bgr_to_nv12_single_plane() {+ RefPreprocessParams res("post_convert_color_bgr_to_nv12_single_plane");+ res.abs_threshold = 2.f;+ res.rel_threshold = 1.f;+ res.function = []() {+ auto f = create_simple_function(element::f32, Shape{1, 2, 2, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::BGR);+ p.output().postprocess().convert_color(ColorFormat::NV12_SINGLE_PLANE);+ p.build();+ return f;+ };++ // Pure blue via BGR: B=255,G=0,R=0 -> Y=41,U=240,V=110+ res.inputs.emplace_back(Shape{1, 2, 2, 3},+ element::f32,+ std::vector<float>{255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0});+ res.expected.emplace_back(Shape{1, 3, 2, 1}, element::f32, std::vector<float>{41, 41, 41, 41, 240, 110});+ return res;+}++static RefPreprocessParams post_convert_color_rgb_to_nv12_two_planes() {+ RefPreprocessParams res("post_convert_color_rgb_to_nv12_two_planes");+ res.abs_threshold = 2.f;+ res.rel_threshold = 1.f;+ res.function = []() {+ auto f = create_simple_function(element::f32, Shape{1, 2, 2, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES);+ p.build();+ return f;+ };++ // Pure red 2x2: R=255,G=0,B=0 -> Y=82,U=90,V=240+ res.inputs.emplace_back(Shape{1, 2, 2, 3},+ element::f32,+ std::vector<float>{255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0});+ // Y plane: [1, 2, 2, 1]+ res.expected.emplace_back(Shape{1, 2, 2, 1}, element::f32, std::vector<float>{82, 82, 82, 82});+ // UV plane: [1, 1, 1, 2]+ res.expected.emplace_back(Shape{1, 1, 1, 2}, element::f32, std::vector<float>{90, 240});+ return res;+}++static RefPreprocessParams post_convert_color_bgr_to_nv12_two_planes() {+ RefPreprocessParams res("post_convert_color_bgr_to_nv12_two_planes");+ res.abs_threshold = 2.f;+ res.rel_threshold = 1.f;+ res.function = []() {+ auto f = create_simple_function(element::f32, Shape{1, 2, 2, 3});+ auto p = PrePostProcessor(f);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::BGR);+ p.output().postprocess().convert_color(ColorFormat::NV12_TWO_PLANES);+ p.build();+ return f;+ };++ // Pure blue via BGR: B=255,G=0,R=0 -> Y=41,U=240,V=110+ res.inputs.emplace_back(Shape{1, 2, 2, 3},+ element::f32,+ std::vector<float>{255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0});+ // Y plane: [1, 2, 2, 1]+ res.expected.emplace_back(Shape{1, 2, 2, 1}, element::f32, std::vector<float>{41, 41, 41, 41});+ // UV plane: [1, 1, 1, 2]+ res.expected.emplace_back(Shape{1, 1, 1, 2}, element::f32, std::vector<float>{240, 110});+ return res;+}+static RefPreprocessParams pre_and_post_processing() {RefPreprocessParams res("pre_and_post_processing");res.function = []() {@@ -1420,6 +1510,10 @@ std::vector<RefPreprocessParams> allPreprocessTests() {post_convert_layout_by_dims_multi(),post_convert_color_rgb_to_bgr(),post_convert_color_bgr_to_rgb(),+ post_convert_color_rgb_to_nv12_single_plane(),+ post_convert_color_bgr_to_nv12_single_plane(),+ post_convert_color_rgb_to_nv12_two_planes(),+ post_convert_color_bgr_to_nv12_two_planes(),pre_and_post_processing(),rgb_to_bgr(),bgr_to_rgb(),diff --git a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cppindex 3d56e69e6c6..33496001e5f 100644--- a/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp+++ b/src/tests/functional/plugin/conformance/test_runner/op_conformance_runner/src/op_impl_check/single_op_graph.cpp@@ -1752,6 +1752,21 @@ std::shared_ptr<ov::Model> generateConvertColor(const std::shared_ptr<ov::op::Opreturn std::make_shared<ov::Model>(results, ParameterVector{params}, "ConvertColorGraph");}+std::shared_ptr<ov::Model> generateConvertColorToNV12(const std::shared_ptr<ov::op::Op> &node) {+ const auto params = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, Shape{1, 4, 2, 3});+ std::shared_ptr<ov::Node> convert;+ if (ov::is_type<ov::op::v17::RGBtoNV12>(node)) {+ convert = std::make_shared<ov::op::v17::RGBtoNV12>(params);+ } else if (ov::is_type<ov::op::v17::BGRtoNV12>(node)) {+ convert = std::make_shared<ov::op::v17::BGRtoNV12>(params);+ } else {+ return nullptr;+ }++ ov::ResultVector results{std::make_shared<ov::op::v0::Result>(convert)};+ return std::make_shared<ov::Model>(results, ParameterVector{params}, "ConvertColorToNV12Graph");+}+std::shared_ptr<ov::Model> generateMultiSubGraph(const std::shared_ptr<ov::op::Op> &node) {if (ov::is_type<ov::op::v8::If>(node)) {auto cond = std::make_shared<ov::op::v0::Parameter>(ov::element::boolean, Shape{1});@@ -2236,6 +2251,8 @@ std::shared_ptr<ov::Model> generateGraph() {} else if (ov::is_type<ov::op::util::ConvertColorNV12Base>(node) ||ov::is_type<ov::op::util::ConvertColorI420Base>(node)) {return generateConvertColor(node);+ } else if (ov::is_type<ov::op::util::ConvertColorToNV12Base>(node)) {+ return generateConvertColorToNV12(node);} else if (ov::is_type<ov::op::util::MulticlassNmsBase>(node)) {return generateMulticlassNmsBase(node);} else if (ov::is_type<ov::op::util::ReadValueBase>(node)) {diff --git a/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/preprocess_builders.hpp b/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/preprocess_builders.hppindex a844526d5d1..a5f31f710f0 100644--- a/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/preprocess_builders.hpp+++ b/src/tests/test_utils/common_test_utils/include/common_test_utils/subgraph_builders/preprocess_builders.hpp@@ -521,10 +521,32 @@ inline std::shared_ptr<Model> cvt_color_bgr_to_rgb() {return function;}+inline std::shared_ptr<Model> cvt_color_rgb_to_nv12_single_plane() {+ using namespace ov::preprocess;+ auto function = create_preprocess_1input(ov::element::f32, PartialShape{1, 20, 30, 3});+ auto p = PrePostProcessor(function);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::RGB);+ p.output().postprocess().convert_color(ColorFormat::NV12_SINGLE_PLANE);+ function = p.build();+ return function;+}++inline std::shared_ptr<Model> cvt_color_bgr_to_nv12_single_plane() {+ using namespace ov::preprocess;+ auto function = create_preprocess_1input(ov::element::f32, PartialShape{1, 20, 30, 3});+ auto p = PrePostProcessor(function);+ p.output().model().set_layout("NHWC").set_color_format(ColorFormat::BGR);+ p.output().postprocess().convert_color(ColorFormat::NV12_SINGLE_PLANE);+ function = p.build();+ return function;+}+inline std::vector<postprocess_func> generic_postprocess_functions() {return std::vector<postprocess_func>{postprocess_func(cvt_color_rgb_to_bgr, "convert_color_rgb_to_bgr", 1e-5f),postprocess_func(cvt_color_bgr_to_rgb, "convert_color_bgr_to_rgb", 1e-5f),+ postprocess_func(cvt_color_rgb_to_nv12_single_plane, "convert_color_rgb_to_nv12_single_plane", 1.f),+ postprocess_func(cvt_color_bgr_to_nv12_single_plane, "convert_color_bgr_to_nv12_single_plane", 1.f),};}