---
# System prepended metadata

title: OpenVINO Quick Get Started on Windows 10
tags: [Windows 10, OpenVINO, '2021.4']

---

# OpenVINO Quick Get Started on Windows 10

###### tags: `OpenVINO` `2021.4` `Windows 10`

## 在 Windows 10 電腦上安裝 OpenVINO Toolkit 2021.4

- Table of Content
[ToC]

### :memo: 系統需求

硬體 :
Intel CPU 筆電/桌機/NUC ![](https://i.imgur.com/lr5Wr4q.png)

軟體 :
Microsoft Windows 10
Intel Distribution OpenVINO Toolkit 2021.4
Python 3.7.9 64-bit
Visual Studio Community 2019


![](https://i.imgur.com/sryLeuy.png)

### 下載 Intel® Distribution of OpenVINO™ Toolkit
https://software.seek.intel.com/openvino-toolkit

![](https://i.imgur.com/JGlw1fd.png)


### 安裝 Intel® Distribution of OpenVINO™ Toolkit 

![](https://i.imgur.com/VlD2lmo.png)

![](https://i.imgur.com/HdmNhRm.png)

![](https://i.imgur.com/jqXIKBE.png)

![](https://i.imgur.com/QEj0cmV.png)

![](https://i.imgur.com/2KZjX32.png)


### 下載並安裝Python 3.7.9
https://www.python.org/downloads/windows/

![](https://i.imgur.com/UDieqZD.png)

![](https://i.imgur.com/m0BzilD.png)

![](https://i.imgur.com/oSNc3c4.png)

### 安裝OpenVINO toolkit所需的Python套件

```
"c:\Program Files (x86)\Intel\openvino_2021.4.582\bin\setupvars.bat"
cd "C:\ProgramProgram Files (x86)\intel\openvino_2021.4.582\deployment_tools\model_optimizer\install_prerequisites"
install_prerequisites_tf2.bat
install_prerequisites_onnx.bat
cd "c:\Program Files (x86)\intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\"
pip install -r requirements.in
```

### 安裝OpenVINO toolkit所需的Python套件 : 使用virtualenv (建議使用,非必須)

```
pip install virtualenv
python -m venv c:\Users\Public\ov_venv
c:\Users\Public\ov_venv\Scripts\activate
"c:\Program Files (x86)\Intel\openvino_2021.4.582\bin\setupvars.bat"
pip install -r "C:\Program Files (x86)\intel\openvino_2021.4.582\deployment_tools\model_optimizer\requirements_tf2.txt"
pip install -r "C:\Program Files (x86)\intel\openvino_2021.4.582\deployment_tools\model_optimizer\requirements_onnx.txt"
pip install -r "c:\Program Files (x86)\intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\requirements.in"
```

### 使用OpenVINO Toolkit做影像辨識

使用神經網路模型執行影像辨識只要三個步驟
1. 取得神經網路模型
1. 對神經網路模型進行推論優化
1. 執行影像辨識推論 (在Intel CPU, Intel GPU以及VPU)

### 步驟1 取得神經網路模型

![](https://i.imgur.com/8AwisMg.png)

```
cd c:\Users\Public
python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\downloader.py" --name mobilenet-v2-1.0-224
```
    
### 步驟2 對神經網路模型進行推論優化

![](https://i.imgur.com/VVgopAA.png)

```
cd c:\Users\Public
python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\converter.py" --name mobilenet-v2-1.0-224
```

### 步驟3 執行影像辨識推論 (18 lines of Python code)

![](https://i.imgur.com/OIjKsmK.png)


### *** car.png 可以在C:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\demo\找到.

```
cd c:\Users\Public
copy c:\Users\Public\public\mobilenet-v2-1.0-224\FP16\* .
copy "C:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\demo\car.png" c:\Users\Public\
notepad getstarted.py # Copy and paste python below to getstarted.py code

python getstarted.py
```
### *** getstarted.py python code
```python=
import cv2
import numpy as np
from openvino.inference_engine import IENetwork, IECore
ie = IECore()
net = ie.read_network(model='mobilenet-v2-1.0-224.xml')
input_blob = next(iter(net.inputs))
out_blob = next(iter(net.outputs))
batch,channel,height,width  = net.inputs[input_blob].shape
image = cv2.imread('car.png')
cv2.imshow("input", image)
image = cv2.resize(image, (width, height))
image = image.transpose((2, 0, 1))  # Change data layout from HWC to CHW
exec_net = ie.load_network(network=net, device_name='CPU')
res = exec_net.infer(inputs={input_blob: image})
idx = np.argsort(np.squeeze(res[out_blob][0]))[::-1]
for i in range(5):
    print(idx[i]+1, res[out_blob][0][idx[i]])
cv2.waitKey(3*1000)
```

### 挑戰題 : 如何在GPU上執行影像辨識? (Python)
```
exec_net = ie.load_network(network=net, device_name='GPU')
```

### 挑戰題 :如何更改影像辨識模型
```
net = ie.read_network(model='googlenet-v3.xml')

cd c:\Users\Public

python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\downloader.py" --name googlenet-v3

python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\converter.py" --name googlenet-v3

copy c:\Users\Public\public\googlenet-v3\FP16\* .
copy "C:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\demo\car.png" .
python getstarted.py
```

### 挑戰題 : 如何使用USB WebCam執行影像物件偵測?

```
cd c:\Users\Public
python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\downloader.py" --name person-detection-0201
copy public\person-detection-0201\FP16\* .

*** notepad objectdetect_webcam.py # Copy and paste python below to objectdetect_webcam.py code ***

python objectdetect_webcam.py
```

### *** objectdetect_webcam.py python code
```python=
import cv2
import numpy as np
from openvino.inference_engine import IENetwork, IECore
threshold = 0.4
ie = IECore()
net = ie.read_network(model='person-detection-0201.xml') # Object detection model
input_blob = next(iter(net.inputs))
out_blob = next(iter(net.outputs))
batch,channel,height,width  = net.inputs[input_blob].shape
cap = cv2.VideoCapture(0) # USB WebCam
while(True):
  ret, frame = cap.read()
  image = cv2.resize(frame, (width, height))
  image = image.transpose((2, 0, 1))  # Change data layout from HWC to CHW
  exec_net = ie.load_network(network=net, device_name='CPU')
  res = exec_net.infer(inputs={input_blob: image})
  size = frame.shape[:2]
  for detection in res['detection_out'][0][0]:
    if detection[2] > threshold:
      print("detection[2]:{}".format(detection[2]))  
      xmin = max(int(detection[3]*size[0]), 0)
      ymin = max(int(detection[4]*size[1]), 0)
      xmax = min(int(detection[5]*size[0]), size[0])
      ymax = min(int(detection[6]*size[1]), size[1])
      class_id = int(detection[1])
      cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (255, 0, 0), 2) # Draw rectangle 
  cv2.imshow("detection_output", frame)
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break
cap.release()
cv2.destroyAllWindows()
```

### 挑戰題 :如何更改物件偵測模型

```
cd c:\Users\Public
python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\downloader.py" --name ssd_mobilenet_v2_coco
python “c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\converter.py” --name ssd_mobilenet_v2_coco
copy public\ssd_mobilenet_v2_coco\FP16\* .
```

```=python
import cv2
import numpy as np
from openvino.inference_engine import IENetwork, IECore
threshold = 0.6
ie = IECore()
net = ie.read_network(model='ssd_mobilenet_v2_coco.xml') # Object detection model
input_blob = next(iter(net.inputs))
out_blob = next(iter(net.outputs))
batch,channel,height,width  = net.inputs[input_blob].shape
cap = cv2.VideoCapture(0) # USB WebCam
while(True):
  ret, frame = cap.read()
  image = cv2.resize(frame, (width, height))
  image = image.transpose((2, 0, 1))  # Change data layout from HWC to CHW
  exec_net = ie.load_network(network=net, device_name='CPU')
  res = exec_net.infer(inputs={input_blob: image})
  size = frame.shape[:2]
  for detection in res['DetectionOutput'][0][0]:
    if detection[2] > threshold: 
      xmin = max(int(detection[3]*size[0]), 0)
      ymin = max(int(detection[4]*size[1]), 0)
      xmax = min(int(detection[5]*size[0]), size[0])
      ymax = min(int(detection[6]*size[1]), size[1])
      class_id = int(detection[1])
      cv2.rectangle(frame, (xmin, ymin), (xmax, ymax), (255, 0, 0), 2) # Draw rectangle 
  cv2.imshow("detection_output", frame)
  if cv2.waitKey(1) & 0xFF == ord('q'):
    break
cap.release()
cv2.destroyAllWindows()

```

### 安裝Visual Studio Community 2019
Download Visual Studio Community version, https://visualstudio.microsoft.com/zh-hant/vs/express/

![](https://i.imgur.com/rg8j8cJ.png)


只需安裝
![](https://i.imgur.com/gJGCUA1.png)

### 編譯OpenVINO C++ Demo Code

```
"c:\Program Files (x86)\Intel\openvino_2021.4.582\bin\setupvars.bat"
c:\Users\Public\ov_venv\Scripts\activate (如果使用virtualenv才需要)
pip install cmake
cd "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\inference_engine\demos"
build_demos_msvc.bat VS2019
cd c:\Users\openvino\Documents\Intel\OpenVINO\omz_demos_build\intel64\Release
```

### 使用USB WebCam 進行年齡,性別與情緒辨識

![](https://i.imgur.com/opTUqz7.gif)

```
cd c:\Users\Public
python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\downloader.py" --name face-detection-adas-0001

python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\downloader.py" --name age-gender-recognition-retail-0013

python "c:\Program Files (x86)\Intel\openvino_2021.4.582\deployment_tools\tools\model_downloader\downloader.py" --name emotions-recognition-retail-0003

cd c:\Users\openvino\Documents\Intel\OpenVINO\omz_demos_build\intel64\Release

interactive_face_detection_demo.exe -i 0 -m c:\Users\Public\intel\face-detection-adas-0001\FP16\face-detection-adas-0001.xml -m_ag  c:\Users\Public\intel\age-gender-recognition-retail-0013\FP16\age-gender-recognition-retail-0013.xml -m_em c:\Users\Public\intel\emotions-recognition-retail-0003\FP16\emotions-recognition-retail-0003.xml -d CPU
```


### 挑戰題 : 如何把物件偵測模型跑在GPU上?

```
interactive_face_detection_demo.exe -i 0 -m c:\Users\Public\intel\face-detection-adas-0001\FP16\face-detection-adas-0001.xml -m_ag  c:\Users\Public\intel\age-gender-recognition-retail-0013\FP16\age-gender-recognition-retail-0013.xml -m_em c:\Users\Public\intel\emotions-recognition-retail-0003\FP16\emotions-recognition-retail-0003.xml -d GPU
```
