Search code examples
pythonopencvpgmimread

OpenCV Python - Reading pgm files


I'm trying to read a bunch of pgm files for a facial recognition project.

These files lie in an overall folder called "negative" and within the negative folder are subfolders. This portion of my script is supposed to go into all of the directories, store the filenames in an array, and store the "image file" in another array using OpenCV.

os.chdir("../negative")
dirnames = os.listdir(".")
neg_names = []
for i in dirnames:                                              
    if os.path.isdir(i): 
        os.chdir(i)   
        neg_names.append(os.listdir("."))  
        os.chdir("..")
        face = cv2.imread(i,-1)
        faces_negatives.append(face)
print faces_negatives

For some reason when it prints the array I get NONE in every index (there are 40 of them). From my understanding I should be getting binary values from this. This code works file with jpg files.


Solution

  • Just in case anyone else runs into this issue, I found a solution:

    I figured out the issue I was having had to do with the path that I was sending into the function "imread". The full path of the file needs to be passed into the function in order for it to read properly. The issue was resolved when I entered in the full path of the image