You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import cv2
import sys
image = cv2.imread("pic.png")
#imshow() is the function that displays the image on the screen.
cv2.imshow("OpenCV Image Reading", image) #first arg is the title, second is the image that is already read
cv2.waitKey(0) #like getch() in Turbo C, wait for a key to get pressed by the user
another package, imageio
import imageio
im = imageio.imread('my_image.png')
print(im.shape)
#op: (342, 548, 3)
#image have attributes like size, dtype, shape,
#shape give you the demin of the image, returns a tuple of No. of (rows,col,channel);
#if RBG channels will be 3; if grayscale only rows and cols will be returned.
Loading image to numpy array
#here using for in, you can load multiple images.
#glob package is used for traversing the dir paths
from scipy import misc
import glob
for image_path in glob.glob("pic_folder/*.png"):
image = misc.imread(image_path)
print image.shape
print image.dtype
Using pillow lib
from PIL import Image
import numpy as np
im_frame = Image.open('pic.png')
np_frame = np.array(im_frame.getdata())
print(str(np_frame))