Skip to content

Feature: Add OpenVINO NPU support#27363

Merged
asmorkalov merged 6 commits intoopencv:4.xfrom
MRo47:openvino-npu-support
May 27, 2025
Merged

Feature: Add OpenVINO NPU support#27363
asmorkalov merged 6 commits intoopencv:4.xfrom
MRo47:openvino-npu-support

Conversation

@MRo47
Copy link
Copy Markdown
Contributor

@MRo47 MRo47 commented May 26, 2025

Why

  • OpenVINO now supports inference on integrated NPU devices in intel's Core Ultra series processors.
  • Sometimes as fast as GPU, but should use considerably less power.

How

  • The NPU plugin is now available as "NPU" in openvino ov::Core::get_available_devices().
  • Removed the guards and checks for NPU in available targets for Inference Engine backend.

Test example

Pre-requisites

Example

#include <opencv2/dnn.hpp>
#include <iostream>

int main(){
    cv::dnn::Net net = cv::dnn::readNet("../yolov8s-openvino/yolov8s.xml", "../yolov8s-openvino/yolov8s.bin");
    cv::Size net_input_shape = cv::Size(640, 480);
    std::cout << "Setting backend to DNN_BACKEND_INFERENCE_ENGINE and target to DNN_TARGET_NPU" << std::endl;
    net.setPreferableBackend(cv::dnn::DNN_BACKEND_INFERENCE_ENGINE);
    net.setPreferableTarget(cv::dnn::DNN_TARGET_NPU);

    cv::Mat image(net_input_shape, CV_8UC3);
    cv::randu(image, cv::Scalar(0, 0, 0), cv::Scalar(255, 255, 255));
    cv::Mat blob = cv::dnn::blobFromImage(
        image, 1, net_input_shape, cv::Scalar(0, 0, 0), true, false, CV_32F);
    net.setInput(blob);
    std::cout << "Running forward" << std::endl;
    cv::Mat result = net.forward();
    std::cout << "Output shape: " << result.size << std::endl; // Output shape: 1 x 84 x 6300
}

model files here

docker image used to build opencv: ghcr.io/mro47/opencv-builder

Closes #26240

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@MRo47
Copy link
Copy Markdown
Contributor Author

MRo47 commented May 26, 2025

I want to add more documentation on this feature, related to installing drivers and what the DNN_TARGET_NPU means for the DNN_BACKEND_INFERENCE_ENGINE, where should I add this?

@MRo47 MRo47 marked this pull request as ready for review May 26, 2025 16:12
@asmorkalov asmorkalov requested a review from dkurt May 27, 2025 05:42
@asmorkalov
Copy link
Copy Markdown
Contributor

https://github.com/opencv/opencv/blob/4.x/doc/tutorials/dnn/dnn_openvino/dnn_openvino.markdown

@dkurt
Copy link
Copy Markdown
Member

dkurt commented May 27, 2025

@asmorkalov Looks good, let's wait for the documentation update for the final review,

Copy link
Copy Markdown
Member

@dkurt dkurt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asmorkalov asmorkalov added this to the 4.12.0 milestone May 27, 2025
@asmorkalov asmorkalov merged commit 344f8c6 into opencv:4.x May 27, 2025
28 checks passed
@asmorkalov asmorkalov mentioned this pull request May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OpenCV DNN_TARGET_NPU not supported exception in dnn target validation

4 participants