Commit 5d234edf authored by klorydryk's avatar klorydryk

Q for Quit, F5 for Fullscreen

parent 1a2a9d07
...@@ -49,9 +49,11 @@ def detectAndTrackMultipleFaces(): ...@@ -49,9 +49,11 @@ def detectAndTrackMultipleFaces():
#Open the first webcame device #Open the first webcame device
capture = cv2.VideoCapture(0) capture = cv2.VideoCapture(0)
FULLSCREEN = False
#Create two opencv named windows #Create two opencv named windows
cv2.namedWindow("base-image", cv2.WINDOW_AUTOSIZE) cv2.namedWindow("base-image", cv2.WINDOW_AUTOSIZE)
cv2.namedWindow("result-image", cv2.WINDOW_AUTOSIZE) cv2.namedWindow("result-image", cv2.WINDOW_NORMAL)
#Position the windows next to eachother #Position the windows next to eachother
cv2.moveWindow("base-image",0,100) cv2.moveWindow("base-image",0,100)
...@@ -77,22 +79,29 @@ def detectAndTrackMultipleFaces(): ...@@ -77,22 +79,29 @@ def detectAndTrackMultipleFaces():
#Retrieve the latest image from the webcam #Retrieve the latest image from the webcam
rc,fullSizeBaseImage = capture.read() rc,fullSizeBaseImage = capture.read()
#Resize the image to 320x240
baseImage = cv2.resize( fullSizeBaseImage, ( 320, 240))
#Check if a key was pressed and if it was Q, then break #Check if a key was pressed and if it was Q, then break
#from the infinite loop #from the infinite loop
pressedKey = cv2.waitKey(2) pressedKey = cv2.waitKey(2)
if pressedKey == ord('Q'): if pressedKey == -1:
pass
elif pressedKey == 113: # Q
break break
elif pressedKey == 194: # F5
FULLSCREEN = not FULLSCREEN
#Resize the image to 320x240
baseImage = cv2.resize( fullSizeBaseImage, ( 320, 240))
#Result image is the image we will show the user, which is a #Result image is the image we will show the user, which is a
#combination of the original image from the webcam and the #combination of the original image from the webcam and the
#overlayed rectangle for the largest face #overlayed rectangle for the largest face
resultImage = baseImage.copy() if FULLSCREEN == True:
resultImage = fullSizeBaseImage.copy()
cv2.setWindowProperty('result-image', cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_FULLSCREEN)
else:
resultImage = baseImage.copy()
cv2.setWindowProperty('result-image', cv2.WND_PROP_FULLSCREEN,cv2.WINDOW_NORMAL)
...@@ -117,7 +126,7 @@ def detectAndTrackMultipleFaces(): ...@@ -117,7 +126,7 @@ def detectAndTrackMultipleFaces():
#indicated the quality was not good enough #indicated the quality was not good enough
fidsToDelete = [] fidsToDelete = []
for fid in faceTrackers.keys(): for fid in faceTrackers.keys():
trackingQuality = faceTrackers[ fid ].update( baseImage ) trackingQuality = faceTrackers[ fid ].update( resultImage )
#If the tracking quality is good enough, we must delete #If the tracking quality is good enough, we must delete
#this tracker #this tracker
...@@ -142,7 +151,7 @@ def detectAndTrackMultipleFaces(): ...@@ -142,7 +151,7 @@ def detectAndTrackMultipleFaces():
#For the face detection, we need to make use of a gray #For the face detection, we need to make use of a gray
#colored image so we will convert the baseImage to a #colored image so we will convert the baseImage to a
#gray-based image #gray-based image
gray = cv2.cvtColor(baseImage, cv2.COLOR_BGR2GRAY) gray = cv2.cvtColor(resultImage, cv2.COLOR_BGR2GRAY)
#Now use the haar cascade detector to find all faces #Now use the haar cascade detector to find all faces
#in the image #in the image
faces = faceCascade.detectMultiScale(gray, 1.3, 5) faces = faceCascade.detectMultiScale(gray, 1.3, 5)
...@@ -208,7 +217,7 @@ def detectAndTrackMultipleFaces(): ...@@ -208,7 +217,7 @@ def detectAndTrackMultipleFaces():
print("Creating new tracker " + str(currentFaceID) + " with suspicion level: " + str(suspicionLevel)) print("Creating new tracker " + str(currentFaceID) + " with suspicion level: " + str(suspicionLevel))
#Create and store the tracker #Create and store the tracker
tracker = dlib.correlation_tracker() tracker = dlib.correlation_tracker()
tracker.start_track(baseImage, tracker.start_track(resultImage,
dlib.rectangle( x-10, dlib.rectangle( x-10,
y-20, y-20,
x+w+10, x+w+10,
...@@ -284,12 +293,11 @@ def detectAndTrackMultipleFaces(): ...@@ -284,12 +293,11 @@ def detectAndTrackMultipleFaces():
#of the baseimage and make the result image a copy of this large #of the baseimage and make the result image a copy of this large
#base image and use the scaling factor to draw the rectangle #base image and use the scaling factor to draw the rectangle
#at the right coordinates. #at the right coordinates.
largeResult = cv2.resize(resultImage, # largeResult = cv2.resize(resultImage, OUTPUT_SIZE_WIDTH,OUTPUT_SIZE_HEIGHT))
(OUTPUT_SIZE_WIDTH,OUTPUT_SIZE_HEIGHT))
#Finally, we want to show the images on the screen #Finally, we want to show the images on the screen
cv2.imshow("base-image", baseImage) cv2.imshow("base-image", baseImage)
cv2.imshow("result-image", largeResult) cv2.imshow("result-image", resultImage) #largeResult)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment