I keep getting this error:
Traceback (most recent call last):
File "c:\Users\essam\Desktop\break\gear\mouse_tracking.py", line 2, in <module>
from cvzone.HandTrackingModule import HandDetector
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\cvzone\HandTrackingModule.py", line 10, in <module>
import mediapipe as mp
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\mediapipe\__init__.py", line 17, in <module>
import mediapipe.tasks.python as tasks
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\mediapipe\tasks\python\__init__.py", line 17, in <module>
from . import audio
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\mediapipe\tasks\python\audio\__init__.py", line 18, in <module>
import mediapipe.tasks.python.audio.audio_classifier
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\mediapipe\tasks\python\audio\audio_classifier.py", line 26, in <module>
from mediapipe.tasks.python.audio.core import base_audio_task_api
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\mediapipe\tasks\python\audio\core\base_audio_task_api.py", line 25, in <module>
from mediapipe.tasks.python.core.optional_dependencies import doc_controls
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\mediapipe\tasks\python\core\optional_dependencies.py", line 20, in <module>
from tensorflow.tools.docs import doc_controls
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\tensorflow\__init__.py", line 45, in <module>
from tensorflow.python import tf2 as _tf2
File "C:\Users\essam\AppData\Roaming\Python\Python311\site-packages\tensorflow\python\tf2.py", line 21, in <module>
from tensorflow.python.platform import _pywrap_tf2
ImportError: DLL load failed while importing _pywrap_tf2: A dynamic link library (DLL) initialization routine failed.
I tried pip uninstall tensorflow then installing it again pip install tensorflow. I tried updating tensorflow pip install tensorflow --upgrade and uninstalling again using pip uninstall tensorflow tensorboard tensorboard-plugin-wit tensorflow-estimator tensorflow-tensorboard.
after multiple tries of testing and removing the package and using import tensorflow as tf &
print(tf.version) to check if the problem is in the code or in tensorflow. I checked tensorflow install and downloaded Microsoft Visual C++ Redistributable from here.
still got the module error after all that so I started searching for solutions online and found these 2 links similar to my issue:
- ImportError: DLL load failed: A dynamic link library (DLL) initialization routine failed
- https://discuss.tensorflow.org/t/dll-load-failed-while-importing-pywrap-tensorflow-internal-a-dynamic-link-library-dll-initialization-routine-failed/17179
but they ultimately did not help, I'm starting to think I should just uninstall and reinstall everything since this isn't the only package error I'm getting. I'm also having issues with openpyxl, I installed it using pip yet its not getting recognized. "openpyxl" is not accessed Pylance, could not be resolved from source. how can I fix these problems?
Code:
import cv2
from cvzone.HandTrackingModule import HandDetector
import mouse
import threading
import numpy as np
import time
frameR = 100
cam_w, cam_h = 640, 480
cap = cv2.VideoCapture(0) # Update camera index as per your system configuration
cap.set(3, cam_w)
cap.set(4, cam_h)
detector = HandDetector(detectionCon=0.9, maxHands=1)
l_delay = 0
r_delay = 0
double_delay = 0
def l_clk_delay():
global l_delay
global l_clk_thread
time.sleep(1)
l_delay = 0
l_clk_thread = threading.Thread(target=l_clk_delay)
def r_clk_delay():
global r_delay
global r_clk_thread
time.sleep(1)
r_delay = 0
r_clk_thread = threading.Thread(target=r_clk_delay)
def double_clk_delay():
global double_delay
global double_clk_thread
time.sleep(2)
double_delay = 0
double_clk_thread = threading.Thread(target=double_clk_delay)
l_clk_thread = threading.Thread(target=l_clk_delay)
r_clk_thread = threading.Thread(target=r_clk_delay)
double_clk_thread = threading.Thread(target=double_clk_delay)
while True:
success, img = cap.read()
if success:
img = cv2.flip(img, 1)
hands, img = detector.findHands(img, flipType=False)
cv2.rectangle(img, (frameR, frameR), (cam_w - frameR, cam_h - frameR), (255, 0, 255), 2)
if hands:
lmlist = hands[0]['lmList']
ind_x, ind_y = lmlist[8][0], lmlist[8][1]
mid_x, mid_y = lmlist[12][0], lmlist[12][1]
cv2.circle(img, (ind_x, ind_y), 5, (0, 255, 255), 2)
cv2.circle(img, (mid_x, mid_y), 5, (0, 255, 255), 2)
fingers = detector.fingersUp(hands[0])
# Mouse movement
if fingers[1] == 1 and fingers[2] == 0 and fingers[0] == 1:
conv_x = int(np.interp(ind_x, (frameR, cam_w - frameR), (0, 1536)))
conv_y = int(np.interp(ind_y, (frameR, cam_h - frameR), (0, 864)))
mouse.move(conv_x, conv_y)
print(conv_x, conv_y)
# Mouse Button Clicks
if fingers[1] == 1 and fingers[2] == 1 and fingers[0] == 1:
if abs(ind_x - mid_x) < 25:
# Left Click
if fingers[4] == 0 and l_delay == 0:
mouse.click(button="left")
l_delay = 1
l_clk_thread.start()
# Right Click
if fingers[4] == 1 and r_delay == 0:
mouse.click(button="right")
r_delay = 1
r_clk_thread.start()
# Mouse Scrolling
if fingers[1] == 1 and fingers[2] == 1 and fingers[0] == 0 and fingers[4] == 0:
if abs(ind_x - mid_x) < 25:
mouse.wheel(delta=-1)
if fingers[1] == 1 and fingers[2] == 1 and fingers[0] == 0 and fingers[4] == 1:
if abs(ind_x - mid_x) < 25:
mouse.wheel(delta=1)
# Double Mouse Click
if fingers[1] == 1 and fingers[2] == 0 and fingers[0] == 0 and fingers[4] == 0 and double_delay == 0:
double_delay = 1
mouse.double_click(button="left")
double_clk_thread.start()
cv2.imshow("Camera Feed", img)
if cv2.waitKey(1) == ord('q'):
break
cap.release()
cv2.destroyAllWindows()