Intel® Distribution of OpenVINO™ Toolkit
Community assistance about the Intel® Distribution of OpenVINO™ toolkit, OpenCV, and all aspects of computer vision-related on Intel® platforms.
6503 Discusiones

Problem with Windows 10 + OpenCV + Python and NCS2

Toppel__Peter
Novato
4.929 Vistas

Hi there,

I am currently trying to get an NCS2 to run on a Windows 10 computer with Python and OpenCV. I did it under Rasperry and now I wanted to run the same network + Python script on the Windows 10 PC. Unfortunately, nothing works. Have already changed the environment variables etc. and reinstalled everything.

I'm now testing with Python versions 3.7 and 3.6. Not that this would have worked.
I always get this message:

error: (-215:Assertion failed) preferableBackend != DNN_BACKEND_OPENCV || preferableTarget == DNN_TARGET_CPU || preferableTarget == DNN_TARGET_OPENCL || preferableTarget == DNN_TARGET_OPENCL_FP16 in function 'cv::dnn::dnn4_v20190902::Net::Impl::setUpNet'

or

Build OpenCV with Inference Engine to enable loading models from Model Optimizer. in function 'cv::dnn::dnn4_v20190902::Net::readFromModelOptimizer'

 

And the version print from Python for OpenCV is always 4.1.2 (without OpenVino)

 

Can someone give me a tip, or does Python and the stick only work under Linux?
 

Thanks a lot

 

Peter

0 kudos
1 Solución
Maksim_S_Intel
Empleados
4.929 Vistas

You are using OpenCV from system (or pip). To enable OpenCV from OpenVINO you should prepend directory "<openvino>/python/python3" to the PYTHONPATH. "print(cv2.__version__)" should output something like "4.1.2-openvino". Perhaps you've disabled OpenCV component during OpenVINO installation.

Ver la solución en mensaje original publicado

4 Respuestas
Maksim_S_Intel
Empleados
4.929 Vistas

Did you run setupvars.bat before executing the script? What had it print? Check contents of PYTHONPATH environment variable: "echo %PYTHONPATH%"

Toppel__Peter
Novato
4.929 Vistas

Hello,
yes I have executed the batch.

With thtis command I get the following feedback:
C:\Program Files (x86)\IntelSWTools\openvino\python\python3.7

 

 

UPDATE:

It's this correct?

import cv2 as cv
print(cv.__file__)

>>> C:\Python\Python37\lib\site-packages\cv2\cv2.cp37-win_amd64.pyd

 

And this fond i in the Python Shell in the Path Browser

2020-01-23 19_44_05-Window.jpg

Peter

Maksim_S_Intel
Empleados
4.930 Vistas

You are using OpenCV from system (or pip). To enable OpenCV from OpenVINO you should prepend directory "<openvino>/python/python3" to the PYTHONPATH. "print(cv2.__version__)" should output something like "4.1.2-openvino". Perhaps you've disabled OpenCV component during OpenVINO installation.

Toppel__Peter
Novato
4.929 Vistas

Hello,
thank you for the tip, I've changed the path in the environment variable..and it works now :-)

For all who are interested, here is the code I use now in Python.  Works under Windows 10 and Rasp 3 with the NCS2

import time
import cv2 as cv

cap = cv.VideoCapture(0)
cap.set (cv.CAP_PROP_BUFFERSIZE,1)


net = cv.dnn.readNet('person-detection-retail-0013.xml', 'person-detection-retail-0013.bin')

net.setPreferableTarget(cv.dnn.DNN_TARGET_MYRIAD)

while(True):
    ret, frame = cap.read()
    start = time.time()

    
         
    # Prepare input blob and perform an inference
    blob = cv.dnn.blobFromImage(frame, size=(640, 480), ddepth=cv.CV_8U)
    net.setInput(blob)
    out = net.forward()


    end = time.time()
    
    print("Time: "+format(end - start)+" Second")

         
    # Draw detected person 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.25:
            cv.rectangle(frame, (xmin, ymin), (xmax, ymax), color=(0, 255, 0))


    # Show image
    cv.imshow('frame',frame)


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

 

 

 

 

THANK YOU for the great support

Peter

Responder