1

I have built OpenCV with OpenVino. And I have code which has to run an OpenVino model:

#include <iostream>
#include <vector>
#include <opencv2\opencv.hpp>

using namespace std;
using namespace cv;
using namespace dnn;

void TestOpenVinoModel()
{   
    // Another model
    string mapping_path = "C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.mapping";
    string xml_path = "C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.xml";
    string bin_path = "C:\\ROOT1\\opencv_build_test\\files_openvino_2\\ssdlite_mobilenet_v2.bin";

    Net openvino_model = readNetFromModelOptimizer(xml_path, bin_path);
    openvino_model.setPreferableTarget(DNN_TARGET_CPU);
    Mat img = imread("C:\\ROOT1\\opencv_build_test\\car_300x300.jpg");
    Mat blob = blobFromImage(img, 0.007843f, Size(300, 300), Scalar(127.5f, 127.5f, 127.5f), false);

    openvino_model.setInput(blob);
    Mat detections = openvino_model.forward();
    Mat detections_reshaped = detections.reshape(1, detections.total() / 7);

    for (int i = 0; i < detections_reshaped.rows; ++i) {
        float confidence = detections_reshaped.at<float>(i, 2);
        if (confidence > 0.5) {
            int x_left = static_cast<int>(detections_reshaped.at<float>(i, 3) * img.cols);
            int y_top = static_cast<int>(detections_reshaped.at<float>(i, 4) * img.rows);
            int x_right = static_cast<int>(detections_reshaped.at<float>(i, 5) * img.cols);
            int y_bottom = static_cast<int>(detections_reshaped.at<float>(i, 6) * img.rows);

            rectangle(img, Point(x_left, y_top), Point(x_right, y_bottom), Scalar(0, 0, 255), 2);
        }
    }

    imshow("Image", img);
    waitKey();
}

int main()
{
    TestOpenVinoModel();

    return 0;
}

But it crashes after the string

Mat detections = openvino_model.forward();

on

void CNNNetwork::reshape(const std::map<std::string, std::vector<size_t> >& shapes) ...

enter image description here

Can anybody help me?

I have built OpenCV with the following flags:


-DBUILD_SHARED_LIBS=OFF -DOPENCV_ENABLE_NONFREE=ON -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DWITH_OPENVINO=ON -DBUILD_opencv_gapi=OFF -DOPENCV_DNN_OPENVINO=ON -DBUILD_WITH_STATIC_CRT=OFF

Maybe I built incorrectly?

tridjam
  • 21
  • 2

1 Answers1

0

In OpenVINO's latest release (2022.3 or 2022.1) version, OpenCV is not included with the installation package. Below are the steps to build OpenCV.

  1. Download and install OpenVINO version of 2022.3 or 2022.1.

  2. Download OpenCV from opencv/opencv repository.

    git clone --recurse-submodules -b 4.5.5-openvino-2022.1.0 https://github/opencv/opencv.git

  3. Setup environment variables to detect Inference Engine.

    <INSTALL_DIR>\setupvars.bat

  4. Create build directory and navigate to build directory.

    cd opencv

    mkdir build && cd build

  5. Compile and install OpenCV with minimal set of compilation flags.

    cmake -DCMAKE_BUILD_TYPE=Release -DWITH_OPENVINO=ON ..

Additional information, In OpenVINO 2021.4 version, OpenCV is included.

Aznie_Intel
  • 101
  • 3