I have been watching this tutorial https://www.youtube.com/watch?v=01sAkU_NvOY&ab_channel=freeCodeCamp.org
For the hand module it went fine but for the pose and face module I have been getting error at the same position I have gone through the code and I dont see where I have made a mistake.
import cv2 as cv
import mediapipe as mp
import time
class FaceDetector():
def __init__(self, minDetectionCon=0.5):
self.minDetectionCon = minDetectionCon
self.mpFD = mp.solutions.face_detection
self.mpDraw = mp.solutions.drawing_utils
self.faceDetection = self.mpFD.FaceDetection()
def findFaces(self, vid, draw=True):
vidRBG = cv.cvtColor(vid, cv.COLOR_BGR2RGB)
self.results = self.faceDetection.process(vidRBG)
#print(results)
bboxs = []
if self.results.detections:
for id, detection in enumerate(self.results.detections):
bboxc = detection.location_data.relative_bounding_box
ih, iw, ic = vid.shape
bbox = int(bboxc.xmin * iw), int(bboxc.ymin * ih), \
int(bboxc.width * iw), int(bboxc.height * ih)
bboxs.append([bbox, detection.score])
cv.rectangle(vid, bbox, (255, 0, 255), 2)
cv.putText(vid, f'{int(detection.score[0]*100)}%',
(bbox[0], bbox[1]-20), cv.FONT_HERSHEY_PLAIN, 3, (0, 255, 0), 2)
return vid, bboxs
def main():
cap = cv.VideoCapture(0)
pTime = 0
detector = FaceDetector
while True:
suc, vid = cap.read()
vid, bboxs = detector.findFaces(vid)#getting error here
cTime = time.time()
fps = 1 / (cTime - pTime)
pTime = cTime
cv.putText(vid, f'FPS:{int(fps)}', (20, 70), cv.FONT_HERSHEY_PLAIN, 3, (0, 255, 0), 2)
cv.imshow("VIDEO", vid)
if cv.waitKey(1) & 0xFF == ord('q'):
break
For both the pose estimation module and face detection module both the errors are occurring in the same line.
Error I keep receiving
Traceback (most recent call last):
File "S:\PROJECTS\Face Detection\face_detection_module.py", line 67, in <module>
main()
File "S:\PROJECTS\Face Detection\face_detection_module.py", line 55, in main
vid = detector.findFaces(vid)
TypeError: findFaces() missing 1 required positional argument: 'vid'
[ WARN:0] global C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-sn_xpupm\opencv\modules\videoio\src\cap_msmf.cpp (438) `anonymous-namespace'::SourceReaderCB::~SourceReaderCB terminating async callback