
    8Zh                     T    d dl Z d dlZd dlZd dlZd dlmZmZ d dlZ	d dl
Z
d dlZd ZdS )    N)load_encodingsmark_attendancec                     t          j        d           i } t          j        d          5 }|                                }|                    d                                          }|D ]O\  }}t          j        t          j
        |                    }|| vrg | |<   | |                             |           P	 ddd           n# 1 swxY w Y   t          j        d          }t          j                    }d}	t          j                    }
i }d}d}g }d}|                                r"|                                \  }}|st          j        d	           nt          j        |d
dd          }t          j        |t          j                  }t-          j        |          }t-          j        ||          }|                    |||                                f           t5          |          |k    r|                    d           d}t9          ||          D ]\  }}d}|                                 D ]\  }}t-          j        ||d          }d|v rv|                    |d          dz   ||<   d}d}d |D             \  }}}}t          j         |||f||fdd           t          j!        ||||dz
  ft          j"        ddd           |sXd |D             \  }}}}t          j         |||f||fdd           t          j!        |d||dz
  ft          j"        ddd           d}|
#                    |dd           |r|st          j$        d           |                                D ]Y\  }} | |k    rNtK          |           |
                                 |&                                 t          j'                     |c S Zt          j                    |z
  dk    rS|	sQt          j        d           |
                                 |&                                 t          j'                     dS |                                "|&                                 t          j'                     dS )z&Processes webcam for face recognition.zUPlease look directly at the camera and hold still for a few seconds for best results.zapp/facial_attendance_db.dbzeSELECT USERS.name, USER_IMAGES.encoding FROM USERS JOIN USER_IMAGES ON USERS.id = USER_IMAGES.user_idNr   F      zError accessing webcam.)r   r   g      ?)fxfyg?)	toleranceT   c                 2    g | ]}t          |d z            S    int.0xs     <D:\DownLoads\facial_attendance_system-main\app\attendance.py
<listcomp>z&process_video_feed.<locals>.<listcomp>9   s"    /P/P/PQAaC/P/P/P    )r      r   r   
   c                 2    g | ]}t          |d z            S r   r   r   s     r   r   z&process_video_feed.<locals>.<listcomp>>   s"    +L+L+LC!HH+L+L+Lr   )r   r   r   UnknownBGR)channelsuse_container_widthzKUnknown face detected. Only registered users will be marked for attendance.   z$No known face found. Closing webcam.)(stinfosqlite3connectcursorexecutefetchallnparrayjsonloadsappendcv2VideoCapturetimeemptyisOpenedreaderrorresizecvtColorCOLOR_BGR2RGBface_recognitionface_locationsface_encodingscopylenpopzipitemscompare_facesget	rectangleputTextFONT_HERSHEY_SIMPLEXimagewarningr   releasedestroyAllWindows)!registered_usersconnr#   resultsnameencoding_jsonencodingcap
start_time
face_foundplaceholdermatch_countsframe_windowrequired_matchesframe_bufferunknown_face_detectedretframesmall_frame	rgb_framer6   r7   recognized_in_this_frameface_encodingface_locationfound_match	encodingsmatchestoprightbottomleftcounts!                                    r   process_video_feedrd      s   Gcddd	6	7	7 44..  "I  J  J  S  S  U  U#* 	4 	4D-x
= 9 9::H+++)+ &T"))(3333		44 4 4 4 4 4 4 4 4 4 4 4 4 4 4 
1

CJJ(**KLLL!
,,.. 1XXZZ
U 	H.///j33???Lc.?@@	)8CC)8NSS^^UZZ\\JKKK||++Q#( ,/,O,O 	- 	-(M=K#3#9#9#;#; 	n 	ni*8M]abbb7??)5)9)9$)B)BQ)FL&"&K/3,/P/P-/P/P/P,CM%$ufo{TUVVVKtdC"H-=s?WY\^iklmmm -+L+Lm+L+L+L(UFDedC[5&/;PQRRRE9tS2X.>@XZ]_jlmnnn(,%%%TJJJ  	f)A 	fJdeee'--// 	 	KD%(((%%%!!###%''' ) 9;;#b(((H;<<<KKMMM!###4c ,,.. 1d KKMMM4s   BCC
C
)r-   r+   r5   numpyr&   	app.utilsr   r   	streamlitr   r!   r(   rd    r   r   <module>ri      s     



         5 5 5 5 5 5 5 5      K K K K Kr   