0

The error that I have gotten is:

cv2.error: OpenCV(4.5.1) /private/var/folders/nz/vv4_9tw56nv9k3tkvyszvwg80000gn/T/pip-req-build-yaf6rry6/opencv/modules/dnn/src/dnn.cpp:3901: error: (-2:Unspecified error) Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'readFromModelOptimizer'

The complete code that calls the function of the OpenVINO kit is:

import cv2 as cv

// Check the path of the package

print(cv.__file__)
print(cv.getBuildInformation())

// Load the model

net = cv.dnn.readNet('face-detection-adas-0001.xml', 'face-detection-adas-0001.bin')

// Specify target device (CPU)

net.setPreferableTarget(cv.dnn.DNN_TARGET_CPU)
     
// Read an image

frame = cv.imread('faces.jpg')
     
// Prepare input blob 

blob = cv.dnn.blobFromImage(frame, size=(672, 384), ddepth=cv.CV_8U)

// Perform inference (face detection)

net.setInput(blob)
out = net.forward()
     
// Draw detected faces on the frame

for detection in out.reshape(-1, 7):

    confidence = float(detection[2])
    
    xmin = int(detection[3] * frame.shape[1])
    ymin = int(detection[4] * frame.shape[0])
    xmax = int(detection[5] * frame.shape[1])
    ymax = int(detection[6] * frame.shape[0])

    if confidence > 0.2:
        cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))

// Save the frame to an image file

cv.imwrite('output_02.png', frame)

where the declaration of face-detection-adas-0001.xml' and 'face-detection-adas-0001.bin' is literally the model of MobileNet as the default settings of OpenVINO inference engine includes.

May I wonder if I was wrong in any way to deal with the architecture of the neural network or there is some kind of issue of my hardware setup? I am using a Macbook Pro (13-inch, 2020, 3-thunderbolt ports) with Catalina 10.15.7.

Thanks!~

Veysel Olgun
  • 552
  • 1
  • 3
  • 15
Qiyu Zhong
  • 74
  • 6
  • I did reconfigure the whole pipeline and they did work. Main source of the issue comes from the configuration of the OpenCV library since it seems that there are options of re-install OpenVINO with the OCV library configured in the mean time. Thanks. – Qiyu Zhong Oct 20 '22 at 13:16

1 Answers1

1

How have you installed OpenCV (and OpenVINO) on your machine?

Have you built OpenCV from source-code or installed a pre-built, pre-packaged version?

You might want to check e.g. this post: OpenVINO: How to build OpenCV with Inference Engine to enable loading models from Model Optimizer

Few options:

  • build OpenCV from source-code, and add -DWITH_INF_ENGINE=ON to the call to cmake
  • using OpenCV via the OpenVINO installation (in older versions of OpenVINO, OpenCV was already contained as a pre-built version; in newer versions OpenCV is not included but can be downloaded via a helper-script shipping with the OpenVINO installation)
  • checking whether your application simply cannot find the OpenVINO libraries (like missing search-paths)
markusbr
  • 118
  • 8