OpenVINO: How to build OpenCV with Inference Engine to enable loading models from Model Optimizer

model optimizer openvino
build opencv for openvino
openvino raspberry pi 4
openvino inference engine
openvino installation
openvino inference engine samples
openvino 2019 r2

I installed OpenVINO and want to run the following code on windows 10.

import numpy as np
import cv2
import sys

from get_face_id import face_id_getter
from check import check
from win10toast import ToastNotifier 

FP = 32

targetId = 0
toaster = None

if '-use_notifications' in sys.argv:
    toaster = ToastNotifier() 

if len(sys.argv) > 1 and '-m' in sys.argv:
    FP =  16
    targetId = cv2.dnn.DNN_TARGET_MYRIAD

cap = cv2.VideoCapture(0)

getter = None

if '-get_face_id' in sys.argv:
    getter = face_id_getter()

weights = 'face-detection-adas-0001/FP{}/face-detection-adas-0001.bin'.format(FP)
config = 'face-detection-adas-0001/FP{}/face-detection-adas-0001.xml'.format(FP)

weights_emotions, config_emotions, emotions = None, None, None

if len(sys.argv) > 1 and '-use_emotions' in sys.argv:
    weights_emotions = 'emotions-recognition-retail-0003/FP{}/emotions-recognition-retail-0003.bin'.format(FP)
    config_emotions = 'emotions-recognition-retail-0003/FP{}/emotions-recognition-retail-0003.xml'.format(FP)
framework = 'DLDT'

model = cv2.dnn.readNet(weights, config, framework)

if len(sys.argv) > 1 and '-use_emotions' in sys.argv:
    emotions = cv2.dnn.readNet(weights_emotions, config_emotions, framework)

emotions_decode = ('neutral', 'happy', 'sad', 'surprise', 'anger')

names = ["Plotnikov Egor", "Vainberg Roman", "Sataev Emil", "Unknown person"]

emotion_text = None

    ret, frame =

    blob = cv2.dnn.blobFromImage(frame, size=(672, 384), crop=False)

    have_nots = False

    ans = model.forward()
    for i in range(0, 200):
        x_min, y_min, x_max, y_max = np.array(ans[0, 0, i, 3:7]) * np.array([640, 480, 640, 480])
        if ans[0, 0, i, 2] > 0.5:
            cv2.rectangle(frame, (int(x_min), int(y_min)), (int(x_max), int(y_max)), ( 0, 255, 255))

            if len(sys.argv) > 1 and '-use_emotions' in sys.argv:
                blob_emotions = cv2.dnn.blobFromImage(frame[int(y_min):int(y_max), int(x_min):int(x_max)], size=(64, 64), crop=False)
                ans_emotions = emotions.forward()[0, : , 0 , 0]
                ans_emotions = list(map(lambda x: 1 if x > 0.5 else 0, ans_emotions))
                _t = ''.join(list(map(str,ans_emotions))).find('1')
                if _t == -1:
                    _t = 0
                emotion_text = emotions_decode[_t]

            if '-get_face_id' in sys.argv:
                _ans = getter.get_answer(frame[int(y_min):int(y_max), int(x_min):int(x_max)])

                t = check('labels.txt', _ans)
                font = cv2.FONT_HERSHEY_SIMPLEX 
                cv2.putText(frame,names[t],(int(x_min), int(y_min)), font, 1,(255,255,255),2,cv2.LINE_AA)
                if emotion_text != None:
                    cv2.putText(frame,emotion_text,(int(x_min), int(y_max)), font, 1,(255,255,255),2,cv2.LINE_AA)

            if '-use_notifications' in sys.argv and not have_nots:
                toaster.show_toast("Welcome, " + names[t],"")
                have_nots = True


    if cv2.waitKey(1) & 0xFF == ord('q'):


I want to run a pre-trained OpenVINO model, but get the error:

v\modules\dnn\src\dnn.cpp:2670: error: (-2:Unspecified error) Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'cv::dnn::dnn4_v20190122::Net::readFromModelOptimizer'

I need to build OpenCV with Inference Engine. I'm not experienced in programming and don't know what this means.

When I try this:

and try

cmake \

in the C:\Program Files (x86)\IntelSWTools\openvino_2019.1.148\opencv\samples it gives an error saying:

CMake Error: The source directory "C:/Program Files (x86)/IntelSWTools/openvino_2019.1.148/opencv/samples/..." does not appear to contain CMakeLists.txt.

even though there is a CMakeLists.txt in that folder.

Can someone please help me?

Is there any tutorial or example to show how to use Inference Engine , I have already downloaded and installed the Intel® OpenVINO™ to I tried to build the OpenCV from source with Inference Engine, but CMake was with Inference Engine to enable loading models from Model Optimizer. Question 1: I tried to build OpenCV from source with Inference Engine, but the CMake was unable to locate the Inference Engine_DIR, It will be better to also have a tutorial to show how to build, it the wiki above it is not very clear. So I was not able to load the Inference Engine pre-trained model in the OpenCV which was built by me, it has

For me, the solution was to remove the OpenCV Python libraries and install opencv-python-inference-engine

pip3 uninstall opencv-python
pip3 uninstall opencv-contrib-python
pip3 install opencv-python-inference-engine

Cannot use the openvino's pre built opencv · Issue #94 · opencv , Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'readFromModelOptimizer , when I use bin  Part of the Inference Engine shared library has been moved to the Inference Engine Legacy shared library, which contains obsolete routines needed for Intermediate Representation (IR) v7. You should link custom applications against both libraries, which is done automatically if you use the CMake* interface. Model Optimizer. Model Optimizer

You can just use OpenCV from OpenVINO. It's already compiled with Intel's Inference Engine.

openCV with openVINO..? - OpenCV Q&A Forum, error) Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'readFromModelOptimizer' will you  OpenVINO™ Toolkit - Open Model Zoo repository. This repository includes optimized deep learning models and a set of demos to expedite development of high-performance deep learning inference applications. Use these free pre-trained models instead of training your own models to speed-up the development and production deployment process.

Preparing and Optimizing Your Trained Model, Inference Engine enables deploying your network model trained with any of supported Model Optimizer loads a model into memory, reads it, builds the internal Pre-trained models contain layers that are important for training, such as the Dropout layer. After installation with OpenVINO™ toolkit or Intel® Deep Learning  Dear Peeren, Christian, Sorry that i didn't notice this earlier but it seems like you're not using Inference Engine Core API. Unfortunately, this forum is meant for Inference Engine and Model Optimizer tech support.

Optimization Guide, Tools: Intel DL Deployment Toolkit features the Model Optimizer that enables automatic You need to build your performance conclusions on reproducible data. optimization, covered by Inference Engine during the model loading time. best precision for a GPU target, you may want to always convert models to FP16 . 3.4 OpenVINO with OpenCV. While OpenCV DNN in itself is highly optimized, with the help of Inference Engine we can further increase its performance. The figure below shows the two paths we can take while using OpenCV DNN. We highly recommend using OpenVINO with OpenCV in production when it is available for your platform. 4.

openvino error YoloV2 after it is transformed on Intermediate , I have openvino R5 (2018.5.456) on windows 10For this I >/deployment_tools/​model_optimizer/extensions/front/tf and put it in a <path_to_json> folder. My original model ("cfg" from darkflow) looks like this for the [regions] part error) Build OpenCV with Inference Engine to enable loading models from  Hi, I'm new to OpenVINO. I'm trying to complete the OpenVINO installation but encountered some problems that I can't run the two demos on the

  • I just fixed it by doing something similar to this. Thanks a lot!
  • But how can I do that? Can I import it at the beginning of my python file? Can I us "pip install" to use the openvino version of opencv? This is all quite new for me. Thanks for your response!
  • Just download it from Intel's website, install, call source /opt/intel/openvino/bin/ and then use it with Python3: python3 -c "import cv2 as cv; print(cv.__file__)" gets /opt/intel/openvino_2019.1.144/python/python3.6/
  • I'm working on windows 10, so I'm trying to calculate your comment. I run the /openvino/bin/setupvars.bat file. In my PyCharm code I then try to do: import sys sys.path.append('C:/Program Files (x86)/IntelSWTools/openvino_2019.1.148/python/python3.6/cv2.cp36-win_amd64.pyd') import cv2 as cv This does not work. What am I doing wrong? Thanks a lot for your previous answer!
  • or should i go to my virtual environment/Scripts directory via the command prompt and then do something similar to python3 -c "import cv2 as cv; print(cv.__file__)" gets /opt/intel/openvino_2019.1.144/python/python3.6/
  • sys.path.append should contain just path to directory, not a file.