I have successfully created a csv file using pandas. I get the following error:
Traceback (most recent call last): File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas\core\indexes\base.py", line 3078, in get_loc return self._engine.get_loc(key) File "pandas_libs\index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Id'
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "C:\Users\Manoj Kumar\AppData\Local\Programs\Python\Python37\lib\tkinter__init__.py", line 1702, in call return self.func(*args) File "C:/Users/Manoj Kumar/PycharmProjects/trex/Facial Recognition Based Attendance Management - Copy/train.py", line 206, in TrackImages aa = df.iloc[df['Id'] == Id]['Name'].values File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas\core\frame.py", line 2688, in getitem return self._getitem_column(key) File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas\core\frame.py", line 2695, in _getitem_column return self._get_item_cache(key) File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas\core\generic.py", line 2489, in _get_item_cache values = self._data.get(item) File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas\core\internals.py", line 4115, in get loc = self.items.get_loc(item) File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas\core\indexes\base.py", line 3080, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas_libs\index.pyx", line 140, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\index.pyx", line 162, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\hashtable_class_helper.pxi", line 1492, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 1500, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Id'
when trying to access the csv file from the code. The code is:
recognizer = cv2.face.EigenFaceRecognizer_create() # cv2.createLBPHFaceRecognizer()
recognizer.read("TrainingImageLabel\Trainner.yml")
harcascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(harcascadePath);
df = pd.read_csv("StudentDetails\StudentDetails.csv")
cam = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
col_names = ['Id', 'Name', 'Date', 'Time']
attendance = pd.DataFrame(columns=col_names)
while True:
ret, im = cam.read()
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
faces = faceCascade.detectMultiScale(gray, 1.2, 5)
if np.all(np.array(np.array(faces).shape)) and faces is not None:
for (x, y, w, h) in faces:
cv2.rectangle(im, (x, y), (x + w, y + h), (225, 0, 0), 2)
gray = gray[y:y + h, x:x + w]
gray = cv2.resize(gray, (100, 100))
Id, conf = recognizer.predict(gray)
print(Id, conf)
if (conf < 2000):
ts = time.time()
date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
aa = df.loc[df['Id'] == Id]['Name'].values
tt = str(Id) + "-" + aa
attendance.loc[len(attendance)] = [Id, aa, date, timeStamp]
else:
Id = 'Unknown'
tt = str(Id)
if (conf > 2000):
noOfFile = len(os.listdir("ImagesUnknown")) + 1
cv2.imwrite("ImagesUnknown\Image" + str(noOfFile) + ".jpg", im[y:y + h, x:x + w])
cv2.putText(im, str(tt), (x, y + h), font, 1, (255, 255, 255), 2)
attendance = attendance.drop_duplicates(subset=['Id'], keep='first')
cv2.imshow('im', im)
if (cv2.waitKey(1) == ord('q')):
break
ts = time.time()
date = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d')
timeStamp = datetime.datetime.fromtimestamp(ts).strftime('%H:%M:%S')
Hour, Minute, Second = timeStamp.split(":")
fileName = "Attendance\Attendance_" + date + "_" + Hour + "-" + Minute + "-" + Second + ".csv"
attendance.to_csv(fileName, index=False)
cam.release()
cv2.destroyAllWindows()
# print(attendance)
res = attendance
message2.configure(text=res)```
The objective of the code is to recognize faces.
df
you don't have a column named 'Id' - Aryerez