Using OpenVINO Inference Engine with OpenCV

In the previous section, we discussed how to run the interactive face detection demo. That's all good, but the question that still remains is how to harness the power of OpenVINO with your already existing OpenCV codes. Note that, here, we are emphasizing the utilization of the strength of OpenVINO with minimal changes in the code. This is very important because OpenVINO was not present in the earlier versions of OpenCV, including the more commonly used version 3.4.3. As a good developer, it's your job to make sure that your program supports the maximum number of systems and libraries. 

Luckily for us, all it takes is just one line of code to start using OpenVINO Inference Engine for your OpenCV model's inference code, as shown in the following snippet:

cv::dnn::setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE); // C++
setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE) # Python

And that's it! In a complete working example, this is how you will be using it:

net = cv2.dnn.readNetFromCaffe(prototxt,model)
net.setPreferableBackend(cv2.dnn.DNN_BACKEND_INFERENCE_ENGINE)

Here, you can use any other method of reading your neural network. In this case, we are reading a Caffe model from the .prototxt and .caffemodel files.

Similarly, in the case of C++, this is how we can use it:

Net net = readNetFromCaffe(prototxt, model);
net.setPreferableBackend(DNN_BACKEND_INFERENCE_ENGINE);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.67.27