Reputation: 37
import os
import cv2
import numpy as np
from google.colab.patches import cv2_imshow
from PIL import Image
train_path_positive = "/content/Dataset_P5/Train/Positive"
positive_patches = []
for filename in os.listdir(train_path_positive):
image = cv2.imread(train_path_positive + "/" +filename,0)
image = cv2.resize(image, (500,500))
print(image.shape)
positive_patches.append(image)
positive_patches_array = np.array(positive_patches)
I have 15 pictures in jpg format
When i try to print the shape, I got (15,)
and
I was trying to input those picture and store it on array with the format (15, 500,500)
Upvotes: 1
Views: 262
Reputation: 4633
You need to preallocate a numpy array
# Use your required dtype in below line
positive_patches_array = np.empty((15,500,500), dtype='uint16')
for num, filename in enumerate(os.listdir(train_path_positive)):
image = cv2.imread(train_path_positive + "/" +filename,0)
image = cv2.resize(image, (500,500))
positive_patches_array[num, :, :] = image
Upvotes: 1