I wrote the following code:
import os
import cv2
import random
from pathlib import Path
path = Path(__file__).parent
path = "../img_folder"
for f in path.iterdir():
f = str(f)
img=cv2.imread(f)
im_height = img.shape[0]
im_width = img.shape[1]
But when I run this code, I get the following error:
AttributeError: 'NoneType' object has no attribute 'shape' in im_height = img.shape[0].
I think I cannot access images, so I wrote print(img) and print(type(omg)) and None& is returned. img_folder is a folder that has 10 images. When I print out f, I get:
../img_folder/.DS_Store
I do not know why .DS_Store is contained because img_folder has only images. How should I fix this? What should I write this? Why can't I access images?
print fand post the output. And if the folder does not contain a lot of images, why not just use os.listdir ?.DS_Storefiles in every directory for settings by default. To the OP, you should filter only for images matching aglobpattern, for example,*.jpg.