-1

The code:

import numpy as np
import cv2

img = cv2.imread('/home/pi/Downloads/download.jpg',0)
cv2.imshow(img)

cv2.waitkey(0)
cv2.destroyAllWindows()

Its throwing an error:

Traceback (most recent call last):
  File "/home/pi/Exp/opcv.py", line 5, in <module>
    cv2.imshow(img)
TypeError: Required argument 'mat' (pos 2) not found

Just trying to open a image using opencv and python. But it shows that funky error. Also i'm very new to both programming and opencv.

Thanks

Vaibhav Jha
  • 27
  • 2
  • 9

2 Answers2

1

The OpenCV's cv2.imshow() expects two parameters:

  1. The name of the window to show;
  2. The image itself.

So, what your error TypeError: Required argument 'mat' (pos 2) not found is saying, is that the second parameter is missing, since the function is interpreting your img variable as the window name.

Besides that, cv2.waitkey(0) will also generate an error, the right function name is cv2.waitKey(0) (With capital K).

So the right code will be:

import numpy as np
import cv2

img = cv2.imread('/home/pi/Downloads/download.jpg',0)
cv2.imshow('My window',img)

cv2.waitKey(0)
cv2.destroyAllWindows()
Jean Vitor
  • 893
  • 1
  • 18
  • 24
0

You need to pass a window name in the first parameter of cv2.imshow() like cv2.imshow('image',img)

Rifat Bin Reza
  • 2,601
  • 2
  • 14
  • 29