Skip to content

Commit a4453c9

Browse files
committed
added face_detection changes
1 parent af4f275 commit a4453c9

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

web_programming/face_detection.py

+14-14
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ def draw_face_detections(img, detections):
1313
if detections:
1414
for detection in detections:
1515
# Extract bounding box information
16-
bboxC = detection.location_data.relative_bounding_box
16+
bbox = detection.location_data.relative_bounding_box
1717
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)
2121
)
2222
# Draw the bounding box
23-
cv2.rectangle(img, bbox, (17, 219, 13), 2)
23+
cv2.rectangle(img, box, (17, 219, 13), 2)
2424

2525
def main(video_path):
2626
# Initialize video capture
@@ -30,11 +30,11 @@ def main(video_path):
3030
return
3131

3232
# 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)
3636

37-
pTime = 0 # Previous time for FPS calculation
37+
prev_time = 0 # Previous time for FPS calculation
3838

3939
while True:
4040
success, img = cap.read()
@@ -46,16 +46,16 @@ def main(video_path):
4646
img = resize_image(img)
4747

4848
# 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)
5151

5252
# Draw face detections
5353
draw_face_detections(img, result.detections)
5454

5555
# 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
5959

6060
# Display FPS on the video
6161
cv2.putText(img, f"FPS: {int(fps)}", (20, 70), cv2.FONT_HERSHEY_PLAIN, 3, (0, 255, 0), 2)

0 commit comments

Comments
 (0)