user13429019
user13429019

Reputation:

Using simple OpenCV code but get no output

Im using Visual Studio and Windows 10. The code gives no error, but gives no output either.

import cv2
import matplotlib.pyplot as plt

img_raw = cv2.imread(r'C:\Users\zach5\OneDrive\Documents\Kivy_Projects\IMG_20210106_152434.png')

type(img_raw)
np.ndarray

img_raw.shape
(1300, 1950, 3)

plt.imshow(img_raw)

I don't know what is wrong, any help is greatly appreciated.

Upvotes: 1

Views: 149

Answers (2)

venkatesh
venkatesh

Reputation: 162

As you are importing plot from matplotlib and by using

   plt.imshow(img_raw)

you are plotting in on a plot but you always need to explicitly specify to show it on gui by using

  plt.show()

that makes the plot visible on gui

Upvotes: 0

Red
Red

Reputation: 27577

You'll need to add plt.show() at the end:

import cv2
import matplotlib.pyplot as plt

img_raw = cv2.imread(r'C:\Users\zach5\OneDrive\Documents\Kivy_Projects\IMG_20210106_152434.png')

plt.imshow(img_raw)
plt.show()

Upvotes: 0

Related Questions