简体   繁体   中英

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

I have tried many times but this filenotfound error still comes. I have saved the file in a folder as stated in the code but even though this error occurs. Whenever I try to run the code I get the same error, please tell me where this code needs correction.

```

    def TrainImages():
        recognizer = cv2.face_LBPHFaceRecognizer.create()
        harcascadePath = "I:\\opencv\\build\\etc\\haarcascades\\haarcascade_frontalface_default.xml"
        detector=cv2.CascadeClassifier(harcascadePath)
        Path = "I:\Attendence Project\TrainingImageLabel\Trainner.yml"
        face, Id = getImagesAndLabels(Path)                            "error line 127"
        recognizer.train(faces, np.array(Id))
        recognizer.save("TrainingImageLabel\Trainner.yml")
        res = "Image Trained"
        message.configure(text=res)

    def getImagesAndLabels(path):
        imagePaths = [os.path.join(path,f) for f in os.listdir(path)]  "error line 134"
        faces = []
        Ids = []
        for imagePath in imagePaths:
            pilImage = Image.open(imagePath).convert('L')
            imageNp = np.array(pilImage,'uint8')
            Id=int(os.path.split(imagePath)[-1].split(".")[1])
            faces.append(imageNp)
            Ids.append(Id)
        return faces, Ids

```

**Error occured**

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\pc\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
    return self.func(*args)
  File "I:/Attendence Project/Attendence.py", line 127, in TrainImages
    face, Id = getImagesAndLabels(Path)
  File "I:/Attendence Project/Attendence.py", line 134, in getImagesAndLabels
    imagePaths = [os.path.join(path,f) for f in os.listdir(path)]
FileNotFoundError: [WinError 3] The system cannot find the path specified: 'I:\\Attendence Project\\TrainingImageLabel\\Trainner.yml'

First of all, is it a typo? Should the file-name be "Trainer.yml" instead of "Trainner.yml"? Anyway, if it isn't that -

It looks like you're using a mapped Windows Drive for your project. Is it possible that you are running your Python IDE or the built script as a different user or an administrator account that does not have that drive mapped? This can cause that file path to not be valid and you will get this error.

Try like the following:

"\\PATH_TO_I\Attendence Project\TrainingImageLabel\Trainner.yml"

Or if the escape characters are the problem, try this:

Path = r"I:\Attendence Project\TrainingImageLabel\Trainner.yml"

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