2017-07-23 2 views
0

J'ai une erreur pour exécuter ce code dans IPython Notebook. mon code:Erreur Python OpenCV dans le bloc-notes IPython

import numpy as np 
    import cv2 
    # Create a black image 
    img = np.zeros((512,512,3), np.uint8) 
    # Draw a diagonal blue line with thickness of 5 px 
    img = cv2.line(img,(0,0),(511,511),(255,0,0),5) 
    cv2.imshow('image',img) 
    cv2.waitKey(0) 

erreur:

error          Traceback (most recent call last) 
<ipython-input-12-dc7e5a608b64> in <module>() 
     6 # Draw a diagonal blue line with thickness of 5 px 
     7 img = cv2.line(img,(0,0),(511,511),(255,0,0),5) 
----> 8 cv2.imshow('image',img) 
     9 cv2.waitKey(0) 

error: ..\..\..\modules\highgui\src\window.cpp:261: error: (-215) size.width>0 && size.height>0 in function cv::imshow 

Répondre

1

Vous réattribuer le tableau img avec la sortie de cv2.line fonction, mais selon la reference sa sortie est None.

Cette version vous donnera le résultat souhaité:

import numpy as np 
import cv2 
# Create a black image 
img = np.zeros((512,512,3), np.uint8) 
# Draw a diagonal blue line with thickness of 5 px 
cv2.line(img,(0,0),(511,511),(255,0,0),5) 
cv2.imshow('image',img) 
cv2.waitKey(0)