-
Notifications
You must be signed in to change notification settings - Fork 2
/
DynamicTextReader.py
44 lines (35 loc) · 1.34 KB
/
DynamicTextReader.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import cv2
import cvzone
from cvzone.FaceMeshModule import FaceMeshDetector
import numpy as np
cap = cv2.VideoCapture(2)
detector = FaceMeshDetector(maxFaces=1)
textList = ["Welcome to ", "Murtaza's Workshop.",
"Here we will study", "Computer Vision,", "Robotics and AI.",
"If you like this video", "Like, Share", "and Subscribe."]
sen = 25 # more is less
while True:
success, img = cap.read()
imgText = np.zeros_like(img)
img, faces = detector.findFaceMesh(img, draw=False)
if faces:
face = faces[0]
pointLeft = face[145]
pointRight = face[374]
w, _ = detector.findDistance(pointLeft, pointRight)
W = 6.3
# Finding distance
f = 840
d = (W * f) / w
print(d)
cvzone.putTextRect(img, f'Depth: {int(d)}cm',
(face[10][0] - 100, face[10][1] - 50),
scale=2)
for i, text in enumerate(textList):
singleHeight = 20 + int((int(d/sen)*sen)/4)
scale = 0.4 + (int(d/sen)*sen)/75
cv2.putText(imgText, text, (50, 50 + (i * singleHeight)),
cv2.FONT_ITALIC, scale, (255, 255, 255), 2)
imgStacked = cvzone.stackImages([img, imgText], 2, 1)
cv2.imshow("Image", imgStacked)
cv2.waitKey(1)