0

i have error for run this code in The IPython Notebook. my code:

  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)

error:

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

1 Answer 1

1

You reassign the img array with the output of cv2.line function, yet according to the reference its output is None.

This version would give you the desired result:

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.