Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opencv project #4

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions FaceDetection.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import cv2 # import openCV

def selectNextCamera(currentIndex = -1):
'''
Loads next camera and if there is no available camera at next index, set it to the first one
'''
index = currentIndex + 1
nextCam = cv2.VideoCapture(index)
if (nextCam.isOpened):
ret, _ = nextCam.read()
if ret:
return index, nextCam

return 0, cv2.VideoCapture(0)

alg = 'haarcascade_frontalface_default.xml' # accessed the model file

cascade = cv2.CascadeClassifier(alg) # loading the model with cv2

cam = cv2.VideoCapture(0) # initialization camera
cameraIndex = None
cameraIndex, cam = selectNextCamera() # initialization camera
Q_KEY, F2_KEY, ENTER_KEY = 81, 113, 13

while True:

Expand All @@ -22,8 +37,10 @@

key = cv2.waitKey(1)

if key == 81 or key == 113 :
if key == Q_KEY or key == F2_KEY :
break
if key == ENTER_KEY: # switch to next camera by pressing Enter
cameraIndex, cam = selectNextCamera(cameraIndex) # select next available camera

cam.release()
cv2.destroyAllWindows()
Expand Down