Python 2.7 Opening Multiple Files From Non-default Directory (for Opencv)
I'm using python 2.7 on 64 bit win7 and have opencv 2.4.x. When I write cv2.imread('pic') it opens pic in my default python path which is C:\Users\Myname. But how I will manage to
Solution 1:
Is this what you are looking for? I recommend looking for some tutorials that show basic os and os.path usage. They are very useful tools. Here is the first one I found.
import os
import cv2
mypath = os.path.join('c:\\', 'asdf', 'jkl')
images = list()
for item in os.listdir(mypath):
if '.jpg' in item: # this could be more correctly done with os.path.splitext
image = cv2.imread(os.path.join(mypath, item))
if image is not None:
images.append(image)
Post a Comment for "Python 2.7 Opening Multiple Files From Non-default Directory (for Opencv)"