Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arguments to cv2::imshow

Edit: original title "convert numpy array to cvmat" was a mistake - OpenCV's less than useful error message and my not reading the docs!

With OpenCV 2, IPython now uses NumPy arrays by default.

cvimage = cv2.imread("image.png") #using OpenCV 2
type(cvimage)
Out: numpy.ndarray  #dtype is uint8

pltimage = plt.imread("image.png")  #using Matplotlib
type(pltimage)
Out: numpy.ndarray   #dtype is float

plt.imshow(cvimage)  # works great

cv2.imshow(cvimage)
TypeError: Required argument 'mat' (pos 2) not found

Since cv2 uses NumPy arrays by default, there is no longer any cv::Mat constructor and NumPy has no functions to convert to a cv::Mat array.

Any ideas?

like image 411
Martin Beckett Avatar asked Mar 28 '12 18:03

Martin Beckett


People also ask

What is the first argument in a call to cv2 Imshow?

Then, the image is shown using a call to the cv::imshow function. The first argument is the title of the window and the second argument is the cv::Mat object that will be shown.

Which argument is not taken by cv2 Imshow method?

Ans. One of the biggest reasons for not working on the CV2 Imshow is not using the wait key.

What is the purpose of cv2 Imshow (' image IMG function?

cv2. imshow() function takes any size of NumPy array and shows the image in the same size in the window. If the image resolution is more than a system screen resolution then it shows only those pixel which fits in the screen. Ex: Image resolution is (2000,1000) (widht, height) and screen resolution is (1000,500).


1 Answers

The function has the following docstring: imshow(winname, mat) -> None. You can see the doc string by typing cv2.imshow.__doc__ in the interpreter.

Try cv2.imshow('Image', cvimage).

tl;dr : In original question, first argument of "window name" was missing. "imshow" takes two parameters and only one was supplied.

like image 186
zarthur Avatar answered Oct 14 '22 07:10

zarthur