def take_attendance():
    start=time.time()
    period=12
    recognizer = cv2.face.LBPHFaceRecognizer_create()  # create lpbh face recognizer
    recognizer.read('trainer/trainer.yml')
    cascadePath = "Cascades/haarcascade_frontalface_default.xml"
    faceCascade = cv2.CascadeClassifier(cascadePath);
    font = cv2.FONT_HERSHEY_SIMPLEX
    # iniciate id counter
    id = 0
    #names = [' ', 'Manoj', 'Ram', 'Srijana', 'Sanjay']

    # Initialize and start realtime video capture
    cam = cv2.VideoCapture(0)
    cam.set(3, 640)  # set video width
    cam.set(4, 480)  # set video height
    # Define min window size to be recognized as a face
    minW = 0.1 * cam.get(3)
    minH = 0.1 * cam.get(4)
    while True:
        ret, img = cam.read()
        img = cv2.flip(img, 1)  # Flip vertically
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

        faces = faceCascade.detectMultiScale(
            gray,
            scaleFactor=1.2,
            minNeighbors=5,
            minSize=(int(minW), int(minH)),
        )
        for (x, y, w, h) in faces:
            cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)
            ids, confidence = recognizer.predict(gray[y:y + h, x:x + w])
            if (confidence < 60):
                count = 1
                fileOpen = open("face.txt", "r")
                for j in fileOpen.readlines():
                    if (count == ids):
                        id = str(j[:-1])
                confidence = "  {0}%".format(round(100 - confidence))
                filename=xlwrite.output('attendance','class1',ids,id,'yes');
				
            else:
                id = "unknown"
                confidence = "  {0}%".format(round(100 - confidence))

            cv2.putText(img, str(id), (x + 5, y - 5), font, 1, (255, 255, 255), 2)
            cv2.putText(img, str(confidence), (x + 5, y + h - 5), font, 1, (255, 255, 0), 1)

        cv2.imshow('camera', img)
        k = cv2.waitKey(10) & 0xff
        if k==27:
            break;
        if time.time()>start+period:
            break;
    print("\n [INFO] Exiting Program ")
    cam.release()
    cv2.destroyAllWindows()
Beispiel #2
0
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cas.detectMultiScale(gray, 1.3, 7)
    for (x, y, w, h) in faces:
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        roi_gray = gray[y:y + h, x:x + w]
        roi_color = img[y:y + h, x:x + w]
        eyes = eye_cas.detectMultiScale(roi_gray)
        for (ex, ey, ew, eh) in eyes:
            cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0),
                          2)
        id, conf = recognizer.predict(roi_gray)
        if (conf < 60):
            if (id == 1):
                id = 'Srinivasa'
                if ((str(id)) not in dict):
                    filename = xlwrite.output('attendance', 'class1', 1, id,
                                              'yes')
                    dict[str(id)] = str(id)

            elif (id == 2):
                id = 'Pavan'
                if ((str(id)) not in dict):
                    filename = xlwrite.output('attendance', 'class1', 2, id,
                                              'yes')
                    dict[str(id)] = str(id)

            elif (id == 3):
                id = 'Bala'
                if ((str(id)) not in dict):
                    filename = xlwrite.output('attendance', 'class1', 3, id,
                                              'yes')
                    dict[str(id)] = str(id)
Beispiel #3
0
cam = cv2.VideoCapture(0)
fontface = cv2.FONT_HERSHEY_SIMPLEX
fontscale = 1
fontcolor = (255, 255, 255)
while True:
    ret, im =cam.read()
    gray=cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
    faces=faceCascade.detectMultiScale(gray, 1.2,5);
    for(x,y,w,h) in faces:
        cv2.rectangle(im,(x,y),(x+w,y+h),(0,0,255),2)
        id, conf = recognizer.predict(gray[y:y+h,x:x+w])
        profile=getProfile(id)
        if(profile!=None):
            if(id==1):
                if((str(id)) not in dict):
                    filename=xlwrite.output('attendance','class1',1,str(profile[1]),'yes');
                dict[str(id)]=str(id);
            elif(id==2):
                if ((str(id)) not in dict):
                    filename=xlwrite.output('attendance', 'class1', 2, str(profile[1]), 'yes');
                dict[str(id)]=str(id);
            """elif(str(profile[0])==3):
                if ((str(id)) not in dict):
                    filename =xlwrite.output('attendance', 'class1', 3, str(profile[1]), 'yes');
                    dict[str(id)] = str(id);
                
        else:
            id="Unknown"""
        cv2.putText(im,str(profile[1]),(x,y+h),fontface,fontscale,fontcolor);
    cv2.imshow('im',im)
    if time.time()>start+period:
def function3():
    start = time.time()
    period = 8
    face_cas = cv2.CascadeClassifier('haarcascade_profileface.xml')
    cap = cv2.VideoCapture(0)
    recognizer = cv2.face.LBPHFaceRecognizer_create()
    recognizer.read('trainer/trainer.yml')
    flag = 0
    id = 0
    filename = 'filename'
    dict = {'item1': 1}
    font = cv2.FONT_HERSHEY_SIMPLEX
    while True:
        ret, img = cap.read()
        gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
        faces = face_cas.detectMultiScale(gray)
        for (x, y, w, h) in faces:
            roi_gray = gray[y:y + h, x:x + w]
            cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
            id, conf = recognizer.predict(roi_gray)
            if (conf < 200):
                if (id == 1):
                    id = 'Kunal'
                    if ((str(id)) not in dict):
                        filename = xlwrite.output('attendance', 'class1', 1,
                                                  id, 'P')
                        dict[str(id)] = str(id)

                elif (id == 2):
                    id = 'Anshu'
                    if ((str(id)) not in dict):
                        filename = xlwrite.output('attendance', 'class1', 2,
                                                  id, 'P')
                        dict[str(id)] = str(id)

                elif (id == 3):
                    id = 'Divya'
                    if ((str(id)) not in dict):
                        filename = xlwrite.output('attendance', 'class1', 3,
                                                  id, 'P')
                        dict[str(id)] = str(id)

                elif (id == 4):
                    id = 'AziroAzide'
                    if ((str(id)) not in dict):
                        filename = xlwrite.output('attendance', 'class1', 4,
                                                  id, 'P')
                        dict[str(id)] = str(id)

                else:
                    id = 'Unrecognized Person ' + str(id)
                    filename = xlwrite.output('attendance', 'class1', 5, id,
                                              'P')
                    flag += 1
                    break

            else:
                print("Failure in reading!!!!!")
            cv2.putText(img,
                        str(id) + " " + str(conf), (x, y - 10), font, 0.55,
                        (120, 255, 120), 1)
            #cv2.cv.PutText(cv2.cv.fromarray(img),str(id),(x,y+h),font,(0,0,255));
        cv2.imshow('frame', img)
        #cv2.imshow('gray',gray);
        if flag == 10:
            print("Transaction Blocked")
            break
        if time.time() > start + period:
            break
        if cv2.waitKey(100) & 0xFF == ord('q'):
            break

    cap.release()
    cv2.destroyAllWindows()
Beispiel #5
0
#font = cv2.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 5, 1, 0, 1, 1)
font = cv2.FONT_HERSHEY_SIMPLEX
while True:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cas.detectMultiScale(gray, 1.3, 5)
    for (x, y, w, h) in faces:
        roi_gray = gray[y:y + h, x:x + w]
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        id, conf = recognizer.predict(roi_gray)

        if (id == 1):
            id = '1'
            name = 'Jannat'
            if ((str(id)) not in dict):
                filename = xlwrite.output('attendance', 'class1', 1, name, id,
                                          'Yes')
                dict[str(id)] = str(id)

        if (id == 2):
            id = '2'
            name = 'Asik Syed'
            if ((str(id)) not in dict):
                filename = xlwrite.output('attendance', 'class1', 2, name, id,
                                          'Yes')
                dict[str(id)] = str(id)

        if (id == 3):
            id = '3'
            name = 'Mizan'
            if ((str(id)) not in dict):
                filename = xlwrite.output('attendance', 'class1', 3, name, id,
    # For each face in faces
    for (x, y, w, h) in faces:

        # Create rectangle around the face
        cv2.rectangle(im, (x - 20, y - 20), (x + w + 20, y + h + 20),
                      (0, 255, 0), 4)

        # Recognize the face belongs to which ID
        Id, confidence = recognizer.predict(gray[y:y + h, x:x + w])

        # Check the ID if exist
        if (confidence < 50):
            if (Id == 1):
                Id = "Kshitiz {0:.2f}%".format(round(100 - confidence, 2))
                if ((str(Id)) not in dict):
                    filename = xlwrite.output('attendance', 'class1', 2, Id,
                                              'yes')
                    dict[str(Id)] = str(Id)

            elif (Id == 2):
                Id = "Shiv {0:.2f}%".format(round(100 - confidence, 2))
                if ((str(Id)) not in dict):
                    filename = xlwrite.output('attendance', 'class1', 1, Id,
                                              'yes')
                    dict[str(Id)] = str(Id)

            elif (Id == 3):
                Id = "Richa {0:.2f}%".format(round(100 - confidence, 2))
                if ((str(Id)) not in dict):
                    filename = xlwrite.output('attendance', 'class1', 3, Id,
                                              'yes')
                    dict[str(Id)] = str(Id)
}

font = cv2.FONT_HERSHEY_SIMPLEX
while True:
    ret, img = cap.read();
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY);
    faces = face_cas.detectMultiScale(gray, 1.3, 7);
    for (x,y,w,h) in faces:
        roi_gray = gray[y:y + h, x:x + w]
        cv2.rectangle(img, (x,y), (x+w, y+h), (255,0,0),2);
        id,conf=recognizer.predict(roi_gray)
        
        if(id==1):
            id='vipin khandelwal'
            if((str(id)) not in dict):
                filename=xlwrite.output('attendance','class1',1,id,'yes');
                dict[str(id)]=str(id);
                
        elif(id==2):
            id = 'vivek sharma'
            if ((str(id)) not in dict):
                filename =xlwrite.output('attendance', 'class1', 2, id, 'yes');
                dict[str(id)] = str(id);

                
        
        cv2.putText(img,str(id)+" "+str(conf),(x,y-10),font,0.55,(120,255,120),1)
        
    cv2.imshow('frame',img);
    
    if time.time()>start+period:
Beispiel #8
0
    for (x,y,w,h) in faces_detected:
      cv2.rectangle(test_img,(x,y),(x+w,y+h),(255,0,0),thickness=4)

    resized_img = cv2.resize(test_img, (1000, 700))
    cv2.imshow('face detection Tutorial ',resized_img)
    cv2.waitKey(10)


    for face in faces_detected:
        (x,y,w,h)=face
        roi_gray=gray_img[y:y+w, x:x+h]
        label,confidence=face_recognizer.predict(roi_gray)#predicting the label of given image
        #print("confidence:",confidence)
        #print("label:",label)
        fr.draw_rect(test_img,face)
        predicted_name=name[label]
        if confidence < 37:#If confidence less than 37 then don't print predicted face text on screen
           fr.put_text(test_img,predicted_name,x,y)


    resized_img = cv2.resize(test_img, (1000, 700))
    cv2.imshow('face recognition tutorial ',resized_img)
    if time.time()>start+period:
        break;
    if cv2.waitKey(100) & 0xFF == ord('q'):
        break;

print("label:",name[label]) 
filename =xlwrite.output('attendance', 'class2', label, name[label], 'yes');
cap.release()
cv2.destroyAllWindows
Beispiel #9
0
     confidence = int(100 * (1 - (conf) / 300))
     print(confidence)
     if confidence >= 78:
         filt = df['Rollno'] == id
         name = df[filt]['Name'].values
         Enrollno = df[filt]['Enrollno'].values
         Course = df[filt]['Course'].values
         Sem = df[filt]['Sem'].values
         Section = df[filt]['Section'].values
         Contact = df[filt]['Contact'].values
         Email = df[filt]['Email'].values
         cv2.putText(img,
                     str(id) + " " + str(conf), (x, y - 10), font, 0.55,
                     (120, 255, 120), 1)
         filename = xlwrite.output('attendance', 'class1', id, name[0],
                                   Enrollno[0], Course[0], Sem[0],
                                   Section[0], Contact[0], Email[0],
                                   'yes')
         dict[str(id)] = str(id)
         match = 1
         match1 = match1 + 1
         #if flg==len(faces):
         speak('Thanks' + name[0] + 'your attandnce successfully done')
         flg = flg + 1
         break
     else:
         cv2.putText(img, "face is not recognize", (x, y - 10), font,
                     0.55, (120, 255, 120), 1)
         speak(
             'face is not recognize you are not register please register then try again'
         )
 else:
        if (confidence > 100):
            cv2.putText(im, "Unknown", (x, y - 40), font, 1, (255, 255, 255),
                        3)
        else:
            cv2.putText(im,
                        str(Id) + "  " + str(round(confidence, 2)) + "%",
                        (x, y - 40), font, 1, (255, 255, 255), 3)

        ##for i in range(1, 90):
        ##filename = xlwrite.output('attendance','class1',i, 16115000 + i, 'no')

        for i in range(1, 91):
            if ((100 - confidence) < 50 and (100 - confidence) > 0):
                if (Id == 16115000 + i):
                    if ((str(Id)) not in dict):
                        filename = xlwrite.output('attendance', 'class1', i,
                                                  16115000 + i, 'YES')
                        dict[str(16115000 + i)] = str(16115000 + i)

        for i in range(1, 91):
            if ((str(16115000 + i)) not in dict):
                filename = xlwrite.output('attendance', 'class1', i,
                                          16115000 + i, 'NO')
        '''            
            elif(Id==16115019):
                if ((str(Id)) not in dict):
                    filename =xlwrite.output('attendance', 'class1', 2, Id, 'yes');
                    dict[str(Id)] = str(Id);

            elif(Id==16115004):
                if ((str(Id)) not in dict):
                    filename =xlwrite.output('attendance', 'class1', 3, Id, 'yes');
Beispiel #11
0
filename = 'filename'
dict = {'item1': 1}
#font = cv2.InitFont(cv2.cv.CV_FONT_HERSHEY_SIMPLEX, 5, 1, 0, 1, 1)
font = cv2.FONT_HERSHEY_SIMPLEX
while True:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cas.detectMultiScale(gray, 1.3, 7)
    newtime = datetime.now().time()
    for (x, y, w, h) in faces:
        roi_gray = gray[y:y + h, x:x + w]
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        id, conf = recognizer.predict(roi_gray)
        if (conf < 50):
            if ((str(id)) not in dict):
                filename = xlwrite.output('attendance', 'class1', 1, id,
                                          newtime)
                playsound('thank_you.mp3')
                dict[str(id)] = str(id)
            else:
                time.sleep(3)
                playsound('youarepresent.mp3')

        else:
            id = 'Unknown, can not recognize'
            flag = flag + 1
            continue
        cv2.putText(img,
                    str(id) + " " + str(conf), (x, y - 10), font, 0.55,
                    (120, 255, 120), 1)
        #cv2.cv.PutText(cv2.cv.fromarray(img),str(id),(x,y+h),font,(0,0,255));
    cv2.imshow('frame', img)
while True:
    ret, img = cap.read()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    faces = face_cas.detectMultiScale(gray, 1.3, 7)
    print(faces)
    for (x, y, w, h) in faces:
        roi_gray = gray[y:y + h, x:x + w]
        cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
        id_, conf = recognizer.predict(roi_gray)
        print(id_, conf)
        if (conf > 100):
            if (id_ == 1):
                id_ = 'Neeraj Singh'
                if ((str(id_)) not in dict_):
                    print("Neeraj")
                    filename = xlwrite.output('Attendance', 'class1', 1, id_,
                                              'yes')
                    dict_[str(id_)] = str(id_)

            elif (id_ == 2):
                id_ = 'Milind Monam'
                if ((str(id_)) not in dict_):
                    filename = xlwrite.output('Attendance', 'class1', 2, id_,
                                              'yes')
                    dict_[str(id_)] = str(id_)

            elif (id_ == 3):
                id_ = 'Mukesh Goyal'
                if ((str(id_)) not in dict_):
                    filename = xlwrite.output('Attendance', 'class1', 3, id_,
                                              'yes')
                    dict_[str(id_)] = str(id_)