Skip to content

Instantly share code, notes, and snippets.

@shoaibmehedi7
Created July 10, 2021 19:43
Show Gist options
  • Save shoaibmehedi7/bcb7569ee2b14974b11849f91e2ff88b to your computer and use it in GitHub Desktop.
Save shoaibmehedi7/bcb7569ee2b14974b11849f91e2ff88b to your computer and use it in GitHub Desktop.
while True:
success, img = cap.read()
imgRGB = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
results = faceDetection.process(imgRGB)
if results.detections:
for id, detection in enumerate(results.detections):
mpDrawing.draw_detection(img, detection)
#print(id, detection)
#print(detection.location_data.relative_bounding_box)
bboxC = detection.location_data.relative_bounding_box
ih, iw, ic = img.shape
bbox = int(bboxC.xmin * iw), int(bboxC.ymin * ih), \
int(bboxC.width * iw), int(bboxC.height * ih)
cv2.rectangle(img, bbox, (255, 0, 255), 2)
cv2.putText(img, f'{int(detection.score[0] * 100)}%',
(bbox[0], bbox[1] - 20),cv2.FONT_HERSHEY_PLAIN,2,(255, 0, 255),2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment