@@ -13,14 +13,14 @@ def draw_face_detections(img, detections):
13
13
if detections :
14
14
for detection in detections :
15
15
# Extract bounding box information
16
- bboxC = detection .location_data .relative_bounding_box
16
+ bbox = detection .location_data .relative_bounding_box
17
17
ih , iw , _ = img .shape
18
- bbox = (
19
- int (bboxC .xmin * iw ), int (bboxC .ymin * ih ),
20
- int (bboxC .width * iw ), int (bboxC .height * ih )
18
+ box = (
19
+ int (bbox .xmin * iw ), int (bbox .ymin * ih ),
20
+ int (bbox .width * iw ), int (bbox .height * ih )
21
21
)
22
22
# Draw the bounding box
23
- cv2 .rectangle (img , bbox , (17 , 219 , 13 ), 2 )
23
+ cv2 .rectangle (img , box , (17 , 219 , 13 ), 2 )
24
24
25
25
def main (video_path ):
26
26
# Initialize video capture
@@ -30,11 +30,11 @@ def main(video_path):
30
30
return
31
31
32
32
# Mediapipe Face Detection setup
33
- mpFaceDetection = mp .solutions .face_detection
34
- mpDraw = mp .solutions .drawing_utils
35
- faceDetection = mpFaceDetection .FaceDetection (0.75 )
33
+ mp_face_detection = mp .solutions .face_detection
34
+ mp_draw = mp .solutions .drawing_utils
35
+ face_detection = mp_face_detection .FaceDetection (0.75 )
36
36
37
- pTime = 0 # Previous time for FPS calculation
37
+ prev_time = 0 # Previous time for FPS calculation
38
38
39
39
while True :
40
40
success , img = cap .read ()
@@ -46,16 +46,16 @@ def main(video_path):
46
46
img = resize_image (img )
47
47
48
48
# Convert image to RGB for face detection
49
- imgRGB = cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB )
50
- result = faceDetection .process (imgRGB )
49
+ img_rgb = cv2 .cvtColor (img , cv2 .COLOR_BGR2RGB )
50
+ result = face_detection .process (img_rgb )
51
51
52
52
# Draw face detections
53
53
draw_face_detections (img , result .detections )
54
54
55
55
# FPS calculation
56
- cTime = time .time ()
57
- fps = 1 / (cTime - pTime )
58
- pTime = cTime
56
+ current_time = time .time ()
57
+ fps = 1 / (current_time - prev_time )
58
+ prev_time = current_time
59
59
60
60
# Display FPS on the video
61
61
cv2 .putText (img , f"FPS: { int (fps )} " , (20 , 70 ), cv2 .FONT_HERSHEY_PLAIN , 3 , (0 , 255 , 0 ), 2 )
0 commit comments