[英]I am currently working on my face recognition open-cv and this issue keeps showing after I log it
Exception in Tkinter callback Tkinter 回调异常
Traceback (most recent call last): File "C:\Users\Claire\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexes\base.py", line 2898, in get_loc return self._engine.get_loc(casted_key) File "pandas_libs\index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\index.pyx", line 101, in pandas._libs.index.IndexEngine.get_loc File "pandas_libs\hashtable_class_helper.pxi", line 1675, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Id'回溯(最后一次调用):文件“C:\Users\Claire\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexes\base.py”,第 2898 行,在 get_loc 返回 self._engine。 get_loc(casted_key) 文件“pandas_libs\index.pyx”,第 70 行,在 pandas._libs.index.IndexEngine.get_loc 文件“pandas_libs\index.pyx”,第 101 行,在 Z3A43B4F88325D94022C0EFA9C2FA2FA2.F5. pandas_libs\hashtable_class_helper.pxi", line 1675, in pandas._libs.hashtable.PyObjectHashTable.get_item File "pandas_libs\hashtable_class_helper.pxi", line 1683, in pandas._libs.hashtable.PyObjectHashTable.get_item KeyError: 'Id'
The above exception was the direct cause of the following exception:上述异常是以下异常的直接原因:
Traceback (most recent call last): File "C:\Program Files\Python36\lib\tkinter_ init _.py", line 1702, in call return self.func(*args) File "C:\Users\Claire\Desktop\New folder (6)\login-verification-master\run.py", line 161, in login_submit TrackImages(a) File "C:\Users\Claire\Desktop\New folder (6)\login-verification-master\run.py", line 135, in TrackImages aa=df.loc[df['Id'] == Id]['Name'].values File "C:\Users\Claire\AppData\Roaming\Python\Python36\site-packages\pandas\core\frame.py", line 2906, in getitem indexer = self.columns.get_loc(key) File "C:\Users\Claire\AppData\Roaming\Python\Python36\site-packages\pandas\core\indexes\base.py", line 2900, in get_loc raise KeyError(key) from err KeyError: 'Id'回溯(最后一次调用):文件“C:\Program Files\Python36\lib\tkinter_ init _.py”,第 1702 行,调用中 return self.func(*args) 文件“C:\Users\Claire\Desktop \New 文件夹 (6)\login-verification-master\run.py",第 161 行,在 login_submit TrackImages(a) 文件 "C:\Users\Claire\Desktop\New 文件夹 (6)\login-verification-master\ run.py”,第 135 行,TrackImages aa=df.loc[df['Id'] == Id]['Name'].values 文件“C:\Users\Claire\AppData\Roaming\Python\Python36\ site-packages\pandas\core\frame.py”,第 2906 行,在getitem indexer = self.columns.get_loc(key) 文件“C:\Users\Claire\AppData\Roaming\Python\Python36\site-packages\pandas \core\indexes\base.py", line 2900, in get_loc raise KeyError(key) from err KeyError: 'Id'
This is the code that produces the error.这是产生错误的代码。
def TrackImages(UserId):
recognizer = cv2.face.LBPHFaceRecognizer_create()#cv2.createLBPHFaceRecognizer()
recognizer.read("TrainingImageLabel\Trainner.yml")
harcascadePath = "haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(harcascadePath);
df=pd.read_csv("Details\Details.csv")
cam = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_SIMPLEX
run_count=0;run=True
while run:
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),(225,0,0),2)
Id, conf = recognizer.predict(gray[y:y+h,x:x+w])
print(Id, conf)
if(conf < 50):
aa=df.loc[df.get['Id'] == Id]['Name'].values
tt=str(Id)+"-"+aa
if (str(Id)==UserId):
print(Id, conf)
message.configure(text="Face Recognised Successfully")
run=False
else:
Id='Unknown'
tt=str(Id)
cv2.putText(im,str(tt),(x,y+h), font, 1,(255,255,255),2)
run_count += 1
cv2.imshow('im',im)
if (cv2.waitKey(1)==ord('q') or run_count==150):
message.configure(text="Unable to Recognise Face")
break
cam.release()
cv2.destroyAllWindows()
def login_submit():
a=txt.get()
b=txt2.get()
if (a in data):
if(data[a] == b):
TrackImages(a)
else:
message.configure(text="Id and Password does not Match")
else:
message.configure(text="Entered Id does not Exists")
login_clear()
Your error is here:你的错误在这里:
aa=df.loc[df.get['Id'] == Id]['Name'].values
You have used square
brackets instead of small
brackets您使用了square
括号而不是small
括号
Use this instead:改用这个:
aa=df.loc[df.get('Id') == Id]['Name'].values
OR, you can also use this:或者,你也可以使用这个:
aa=df.loc[df['Id'] == Id]['Name'].values
Here is the code where my dataframe stored.这是我的 dataframe 存储的代码。
def TakeImages():
Id=(txt3.get())
name=(txt4.get())
ret=0
if (Id not in data):
cam = cv2.VideoCapture(0)
harcascadePath = "haarcascade_frontalface_default.xml"
detector=cv2.CascadeClassifier(harcascadePath)
sampleNum=0
while(True):
ret, img = cam.read()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
faces = detector.detectMultiScale(gray, 1.3, 5)
for (x,y,w,h) in faces:
cv2.rectangle(img,(x,y),(x+w,y+h),(255,0,0),2)
#incrementing sample number
sampleNum=sampleNum+1
#saving the captured face in the dataset folder TrainingImage
cv2.imwrite("TrainingImage\ "+name +'.'+Id+'.'+ str(sampleNum) + ".jpg", gray[y:y+h,x:x+w])
#display the frame
cv2.imshow('frame',img)
#wait for 100 miliseconds
if cv2.waitKey(100) & 0xFF == ord('q'):
break
# break if the sample number is morethan 100
elif sampleNum>100:
break
cam.release()
cv2.destroyAllWindows()
res = "Images Saved for ID : " + Id +" Name : "+ name
row = [Id , name]
with open('Details\Details.csv','a+') as csvFile:
writer = csv.writer(csvFile)
writer.writerow(row)
csvFile.close()
message.configure(text= res)
ret=1
else:
res = "User name Already Exists...Try another one!!!"
message.configure(text= res)
return ret
here is what my csv looks like.这是我的 csv 的样子。 enter image description here在此处输入图像描述
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.