Reputation: 201
I have the follow method to get all the images from a dir:
def ReadImages(Path):
LabelList = list()
ImageCV = list()
classes = ["nonPdr", "pdr"]
width = 605
height = 700
dim = (width, height)
# Get all subdirectories
FolderList = os.listdir(Path)
# Loop over each directory
for File in FolderList:
if(os.path.isdir(os.path.join(Path, File))):
for Image in os.listdir(os.path.join(Path, File)):
# Convert the path into a file
ImageCV.append(cv2.imread(os.path.join(Path, File) + os.path.sep + Image))
# Add a label for each image and remove the file extension
LabelList.append(classes.index(os.path.splitext(File)[0]))
else:
ImageCV.append(cv2.imread(os.path.join(Path, File) + os.path.sep + Image))
# Add a label for each image and remove the file extension
LabelList.append(classes.index(os.path.splitext(File)[0]))
return ImageCV, LabelList
But my images are bigger and a want to reduce its wxh to 605x700, then I tried to do something like This:
imgR = cv2.resize(ImageCV[Image])
And it not works.. What can I do to resize all these images? I appreciate any help.
Upvotes: 1
Views: 1194
Reputation: 1014
You may have to pass in the shape to resize()
function of cv2
.
This will resize the image to have 605 cols (width) and 700 rows (height):
imgR = cv2.resize(ImageCV[Image], (605, 700))
For more options you can read the documentation for cv2.resize.
Also, I would suggest using python coding conventions like imgR -> img_r
, Image -> image
, ImageCV -> image_cv
etc. Hope this helps.
Upvotes: 1