Skip to content

Commit a5bbb50

Browse files
author
dehobitto
committed
Added cam capture, main loop
Added imports in requirements.txt, created main loop, grabbed webcam
1 parent e52ece8 commit a5bbb50

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

Python/face_detector/main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import numpy as np
2+
import cv2 as cv
3+
4+
5+
def get_camera(camera_source_idx : int) -> cv.VideoCapture:
6+
cap = cv.VideoCapture(camera_source_idx)
7+
8+
if not cap.isOpened():
9+
print("Cannot open camera")
10+
exit()
11+
12+
return cap
13+
14+
15+
16+
def main():
17+
#TODO: List all cameras let him choose
18+
cap = get_camera(0)
19+
20+
while True:
21+
res, frame = cap.read()
22+
23+
if not res:
24+
print("Cannot read frame")
25+
break
26+
27+
cv.imshow('frame', frame)
28+
if cv.waitKey(1) & 0xFF == ord('q'):
29+
break
30+
31+
cap.release()
32+
cv.destroyAllWindows()
33+
34+
35+
if __name__ == '__main__':
36+
main()
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
numpy~=2.2.6
2+
opencv-python~=4.12.0.88

0 commit comments

Comments
 (0)