SREE LAKSHMI
SREE LAKSHMI

Reputation: 59

FileNotFoundError: [WinError 3] The system cannot find the path specified

Code:

import os
import cv2
folder = ['test images', 'ALB', 'BET', 'DOL', 'LAG', 'NoF', 'OTHER', 
'SHARK', 'YFT' ]
Path = r'D:\ncfm\train'

for i in range(9):
    listing = os.listdir(path+'/'+folder[i])
    folder[i+1] = np.array([np.array(cv2.imread(path+'/'+folder[i]+'/'+file)).flatten()
for file in listing])

Error:

FileNotFoundError                         Traceback (most recent call 
last)
<ipython-input-152-d8f8c2149488> in <module>
      5 
      6 for i in range(9):
----> 7     listing = os.listdir(path+'/'+folder[i])
      8     folder[i+1] = 
np.array([np.array(cv2.imread(path+'/'+folder[i]+'/'+file)).flatten()
      9     for file in listing])

FileNotFoundError: [WinError 3] The system cannot find the path specified: 
'Users\\USER\\Desktop\\ncfmtrain\\YFT\\*.jpg/test images'

i have tried to rectify this many times. but the problem still exist. then i tried this code which worked for me.

import os
from os import listdir

for i in range(9):
    for fld in folders:
        index = folders.index(fld)
        print('Load folders {} (Index: {})'.format(fld, index))
        path = os.path.join('Users', 'USER' , 'Desktop','ncfm' 'train', fld, '*.jpg')
        L.append(len(path))


    break

This is working fine for me. But then comes the following error:

ValueError: Found input variables with inconsistent numbers of samples: [8, 3777]

I guess these are related.

Upvotes: 0

Views: 5561

Answers (1)

abhilb
abhilb

Reputation: 5757

Use pathlib for filesystem access.

from pathlib import Path

jpeg_images = list(Path('D:/ncfm/train').glob('**/*.jpg'))
print(jpeg_images)
np.array([np.array(cv2.imread(str(file))).flatten() for file in jpeg_images])

Update:

Test One File

  • Use the entire path to your file, including the drive letter.
file = Path(r'C:\Users\USER\Desktop\ncfmtrain\YFT\image_name.jpg')
print(cv2.imread(str(file))).flatten())

Upvotes: 1

Related Questions