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) ...
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?