Read Multiple images on a folder in OpenCv (python)

前端 未结 6 1318
孤独总比滥情好
孤独总比滥情好 2021-01-31 06:15

I want to read multiple images on a same folder using opencv (python). To do that do I need to use for loop or while loop with imread func

6条回答
  •  死守一世寂寞
    2021-01-31 06:21

    import cv2
    from pathlib import Path
    
    path=Path(".")
    
    path=path.glob("*.jpg")
    
    images=[]`
    
    
    for imagepath in path.glob("*.jpg"):
    
            img=cv2.imread(str(imagepath))
            img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)                         
            img=cv2.resize(img,(200,200))
            images.append(img)
    print(images)
    

提交回复
热议问题