import cv2
import time
import mediapipe as mp
def main():
cap = cv2.VideoCapture(0)
pTime = 0 # Previous time
global img
detector = poseDetector
while True:
success, img = cap.read()
detector.findPose()
cTime = time.time()
print(cTime, pTime)
fps = 1 / (cTime - pTime)
pTime = cTime
cv2.putText(img, str(int(fps)), (70, 50), cv2.FONT_HERSHEY_SCRIPT_COMPLEX, 3, (255, 0, 0), 3)
cv2.imshow("Image", img)
cv2.waitKey(1)
class poseDetector():
def __init__(self, mode=True, complexity=1, smooth=True, detectionCon=0.5, trackCon=0.5):
self.mode = mode
self.complexity = complexity
self.smooth = smooth
self.detectionCon = detectionCon
self.trackCon = trackCon
self.mpDraw = mp.solutions.drawing_utils
self.mpPose = mp.solutions.pose
self.pose = self.mpPose.Pose(self.mode, self.complexity, self.smooth,
self.detectionCon, self.trackCon)
def findPose(self, draw=True):
imgRGB = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
results = self.pose.process(imgRGB)
if results.pose_landmarks and draw:
self.mpDraw.draw_landmarks(img, results.pose_landmarks, self.mpPose.POSE_CONNECTIONS)
if __name__ == "__main__":
global img
main()
I'm getting this message in Pycharm Earlier when I had not declared img as global it used to be img as missing argument. I've searched a lot it says that pycharm doesn't take arguments apart from list, tuples.... The source of code is from Advanced computer vision. Timeline is somewhere 1hr 18min. Can you please help me