How to read images from a directory with Python and OpenCV?

后端 未结 3 1049
野趣味
野趣味 2021-01-24 17:08

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.iter         


        
3条回答
  •  梦谈多话
    2021-01-24 17:15

    It is because of a hidden file in your directory. If you are sure your directory contains only images, you can ignore hidden files/folders like below.

    use

    for f in path.iterdir():
        if not f.startswith('.'):
    
          f = str(f)
    
          img=cv2.imread(f)
    
          im_height = img.shape[0]
          im_width = img.shape[1]
    

提交回复
热议问题