1

I am trying to accomplish hand detection on webcam feed using mediapipe, but when I run the code I get the following error:

**File "D:\HandTracking\handtracking.py", line 9, in <module>
    hands = mpHands.Hands()**

  **File "C:\Users\Θανάσης\AppData\Local\Programs\Python\Python39\lib\site-packages\mediapipe\python\solutions\hands.py", line 109, in __init__
    super().__init__(**

  **File "C:\Users\Θανάσης\AppData\Local\Programs\Python\Python39\lib\site-packages\mediapipe\python\solution_base.py", line 237, in __init__
    validated_graph.initialize(
FileNotFoundError: The path does not exist.**

**[ WARN:0] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-1i5nllza\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback**

The code is:

import cv2 as cv
import mediapipe as mp

capture = cv.VideoCapture(0)
mpHands = mp.solutions.hands
hands = mpHands.Hands()

while True:
    isTrue, frame = capture.read()
    frameRGB = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
    results = hands.process(frameRGB)
    cv.imshow("Frame", frame)

    if cv.waitKey(20) & 0xFF == ord('d'):
        break

capture.release()
cv.destroyAllWindows()
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61

3 Answers3

2

This error occurs when there are non-unicode characters in the path of the project. It is not only related with the username, but with all the characters included in the pathname. For example, if you have characters in the pathname of your project like "ç", "ş", "ü", "ğ", "ı", "ö", etc you will have this error.

In order to eliminate this error, build your project in a folder that does not have "non-unicode" characters.

It really worked for me...

BodeG
  • 36
  • 6
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jan 04 '22 at 19:47
0

I solved the problem by using here. I think the problem is the path encoding on the pathname.

So the main idea is to change the user folder name to English.

Microsoft provided the method to change the user folder for your reference.

  1. Log in by using another administrative account.

Note : You may need create a new administrative account at first.

  1. Go to the C:\users\ folder and rename the sub folder with the original user name to the new user name.
  2. Go to registry and modify the registry value ProfileImagePath to the new path name. HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\ProfileList<User SID>\

Note : Replace with the new name you want to change to your user account.

  1. Log out and log in again by using the user whose name is changed, and the user should use the previous profile with new path name.
0

It worked for me too...

"This error occurs when there are non-unicode characters in the path of the project. It is not only related with the username, but with all the characters included in the pathname. For example, if you have characters in the pathname of your project like "ç", "ş", "ü", "ğ", "ı", "ö", etc you will have this error."

leinylson
  • 1
  • 2