File size: 3,061 Bytes
b4c5d36 |
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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
"""This module is for seeing the camera stream. This module includes Camera class."""
import cv2
import time
from codes.base import eyeing as ey
from screeninfo import get_monitors
monitors = get_monitors()
class Camera(object):
running = True
def raw(self, camera_id):
"""
See camera stream
Parameters:
camera_id: Camera ID
Returns:
None
"""
frame_size, _, _, _ = ey.get_camera_properties(camera_id)
cap = ey.get_camera(camera_id, frame_size)
ey.pass_frames(cap, 100)
i = 0.0
win_name = "Webcam"
if len(monitors) == 1:
x_disp = 0
else:
x_disp = monitors[0].width
ey.big_win(win_name, x_disp)
t0 = time.perf_counter()
print("Showing camera..")
while self.running:
frame_success, frame, _ = ey.get_frame(cap)
if frame_success:
i += 1
cv2.imshow(win_name, frame)
q = cv2.waitKey(1)
if q == ord('q') or q == ord('Q'):
break
cv2.destroyAllWindows()
fps = ey.get_time(i, t0, True)
print(f"FPS : {fps}")
def features(self, camera_id):
"""
See camera stream with landmarks and features
Parameters:
camera_id: Camera ID
Returns:
None
"""
some_landmarks_ids = ey.get_some_landmarks_ids()
(
frame_size,
camera_matrix,
dst_cof,
pcf
) = ey.get_camera_properties(camera_id)
face_mesh = ey.get_mesh()
cap = ey.get_camera(camera_id, frame_size)
ey.pass_frames(cap, 100)
win_name = "Features"
if len(monitors) == 1:
x_disp = 0
else:
x_disp = monitors[0].width
ey.big_win(win_name, x_disp)
t0 = time.perf_counter()
i = 0
print("Showing features..")
while self.running:
frame_success, frame, frame_rgb = ey.get_frame(cap)
if frame_success:
results = face_mesh.process(frame_rgb)
features_success, frame = ey.get_model_inputs(
frame,
frame_rgb,
results,
camera_matrix,
pcf,
frame_size,
dst_cof,
some_landmarks_ids,
True
)[:2]
if features_success:
i += 1
cv2.imshow(win_name, frame)
q = cv2.waitKey(1)
if q == ord('q') or q == ord('Q'):
break
cap.release()
cv2.destroyAllWindows()
fps = ey.get_time(i, t0, True)
print(f"FPS : {fps}")
|