[英]why am I getting output as none? and not the images in the code below
image_path=r'D:\\data\\Coding_round_images'
def loadImages(path):
image_files = sorted(os.listdir(path))
images=[]
for i in image_files:
images.append(i)
return images
file=loadImages(image_path)
print(file)
images=[]
for f in file:
images.append(cv2.imread(f,cv2.IMREAD_UNCHANGED))
print(images)
確保您在圖像的同一文件夾中執行代碼
└── data
└── Coding_round_images
├── lemon1.jpg
├── lemon2.jpg
├── lemon3.jpg
└── load_lemons.py
或者,如果不相同,請在cv2.imread
命令中添加帶有圖像路徑的前綴。
...
...
for f in file:
images.append(cv2.imread(os.path.join(image_path,f),cv2.IMREAD_UNCHANGED))
因為如果路徑或圖像不存在, cv2.imread不會返回任何錯誤指示。
即使圖片路徑錯誤,也不會拋出任何錯誤,但是print img會給你None
In [135]: x = cv2.imread("NON_EXISTING_IMAGE")
In [136]: type(x)
Out[136]: NoneType
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.