简体   繁体   中英

Python OpenCV- Problems reading files on Windows

I need to read a folder with a lot of .bmp files, and put all of the images on a lits of images. I do not know how to handle the adress. I was doing some thing like this:

adress = "c:/Users/My Name/Desktop/assignment/*.bmp"

imageArray = [cv2.imread(file) for file in glob.glob(adress)]

numImg = len(imageArray)

Inside the assignment folder, there is the Images folder with all the images I need. How to make this work?

Change working directory first:

If you change to the directory of interest first, it may be easier.

import glob, os
os.chdir("/mydir")

image_type = "*.bmp"

imageArray = [cv2.imread(file) for file in glob.glob(image_type)]

numImg = len(imageArray)

This LINK has some nice info about reading files in directories

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM