Skip to content
Snippets Groups Projects
Select Git revision
  • dd3260b3aaabf8447a3b2362c086dd0f8fd9a07b
  • master default
  • clement
  • fix_requirements
  • new_signup
  • interface_admin
  • hamza
  • dev
  • test
  • melissa
  • context_sheet
  • sorties_new
  • Seon82-patch-2
  • export_bdd
  • refactor/participation-user-link
15 results

serializers.py

Blame
  • game.py 1.84 KiB
    #Use your camera for processing the video. Stop by pressing Q
    import cv2
    import imageProcess as ip
    import faceAnalysis as fa
    import random
    from config import emotions
    
    cap = cv2.VideoCapture(0)   #0 means we capture the first camera, your webcam probably
    score = 0
    N = 15
    
    def smileyRandom(emotionToDodge):
        emotionNbr = random.randrange(0,6)
        emotion = emotions[emotionNbr]
        if emotion == emotionToDodge: return smileyRandom(emotion)
        smileyImagePath = "data/smileys/"+emotion+".png"
        smiley = cv2.imread(smileyImagePath)
        return smiley, emotion
    
    
    
    ismain = __name__ == "__main__"
    if ismain:
    
        smiley, emotion = smileyRandom("")
    
        while cap.isOpened():		 #or while 1. cap.isOpened() is false if there is a problem
            ret, frame = cap.read()  #Read next video frame, stop if frame not well read
            if not ret: break
            
            emotionsList = ip.imageProcess(frame, returnEmotion=True)
            
            if emotion in emotionsList: #If emotion recognized, increase score, reset smiley to mimick and write "GG!"
                score += 1
                cv2.putText(smiley, "Emotion reconnue !", (50,50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,255,0), 2)
                cv2.imshow("Smiley", smiley)         
                smiley, emotion = smileyRandom(emotion)
    
    
            cv2.imshow("Caméra", frame)  			#Show you making emotional faces
            cv2.putText(smiley, "Score: "+str(score), (40,40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 2)
            cv2.imshow("Smiley", smiley)            #Show the smiley to mimic
    
            if cv2.waitKey(1) & 0xFF == ord('q'):			#If you press Q, stop the while and so the capture
                break   
    
            elif cv2.waitKey(1) & 0xFF == ord('p'):			#If you press P, pass the smiley but lower your score
                score -= 1
                smiley, emotion = smileyRandom(emotion)
    
    
        cap.release()
        cv2.destroyAllWindows()