AndreMiras / pycaw

Python Core Audio Windows Library
MIT License
376 stars 68 forks source link

from _ctypes import COMError #84

Closed SMRaza1009 closed 1 month ago

SMRaza1009 commented 9 months ago

Hey!

I currently using Ubuntu 22.04 and python 3.8.

When i am running my code. import time import cv2 import numpy as np import HandTrackingModule as htm import mediapipe as mp import math from comtypes import CLSCTX_ALL from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume

widthCam, heightCam = 640, 480

cap = cv2.VideoCapture(0) cap.set(3, widthCam) cap.set(4, heightCam) previousTime = 0

detector = htm.handDetector(detectionCon=0.8)

devices = AudioUtilities.GetSpeakers() interface = devices.Activate( IAudioEndpointVolume.iid, CLSCTX_ALL, None) volume = interface.QueryInterface(IAudioEndpointVolume) volume.GetMute() volume.GetMasterVolumeLevel() volume.GetVolumeRange() volume.SetMasterVolumeLevel(-20.0, None)

while True:

succcess, img = cap.read()
img = detector.findHands(img)
landmarkList = detector.findPosition(img, draw=False)
if len(landmarkList) != 0:
    #print(landmarkList[4], landmarkList[8])

    x1, y1 = landmarkList[4][1], landmarkList[4][2]
    x2, y2 = landmarkList[8][1], landmarkList[8][2]

    # Making a circle in between line
    cx, cy = (x1+ x2)//2, (y1+y2)//2

    cv2.circle(img, (x1, y1), 10, (128, 70, 66), cv2.FILLED)
    cv2.circle(img, (x2, y2), 10, (128, 70, 66), cv2.FILLED)
    cv2.line(img, (x1, y1), (x2, y2), (92, 135, 100), 2)
    cv2.circle(img, (cx, cy), 10, (92, 135, 100), cv2.FILLED)
    #print((x1, y1), (x2, y2))

    length_points = math.hypot((x2-x1), (y2-y1))

    if length_points < 50:
        cv2.circle(img, (cx, cy), 10, (0, 100, 255), cv2.FILLED)

    print(length_points)

# FPS Logic
currentTime = time.time()
fps = (1 / (currentTime - previousTime))
previousTime = currentTime

cv2.putText(img, f'FPS: {int(fps)}', (30,60), cv2.FONT_HERSHEY_COMPLEX, 1, (0, 3, 255), 3)

cv2.imshow("Image", img)
cv2.waitKey(1)

Getting this error!
from _ctypes import COMError

ImportError: cannot import name 'COMError' from '_ctypes' (/usr/lib/python3.8/lib-dynload/_ctypes.cpython-38-x86_64-linux-gnu.so)

katyalmohit commented 1 month ago

This library is supported only on the Windows operating system. It is stated in the README.md file. You can also refer to the issue COMError from '_ctypes #35