简体   繁体   English

我目前正在研究我的人脸识别 open-cv,这个问题在我登录后一直显示

[英]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.

相关问题 如何用 open-cv 和 Picamera 捕捉人脸? - How to capture face with open-cv and Picamera? 我无法从字节读取带有 open-cv 的图像 - I can't read image with open-cv from bytes 打开简历人脸识别python - Open cv face recognition python 处理面部识别项目(使用 face_recognition)但是当我运行程序以获取面部编码时,它显示列表索引超出范围 - Working on a face recog project(using face_recognition) but when i am running the program to get face encodings it is showing list index out of range 我无法安装人脸识别库 - I am unable to install face recognition library 我该怎么做才能安装 Open-CV 库? 如图所示,我遇到了冲突问题 - what can I do to install Open-CV library ? I'm having a conflict problem as shown in the picture 如何使用pip在Ubuntu 16.04系统上安装open-cv库以在Pycharm IDE中使用? - How do I install the open-cv library for use in Pycharm IDE on a Ubuntu 16.04 system using pip? 每次通过人脸识别登录我的注册帐户时都会收到此错误 - I get this error every time I log into my registered account through face recognition 如何在python中找到open-cv摄像机校准常数,OpenCV错误:cv :: calibrateCamera中的断言失败(nimages&gt; 0) - How can I find open-cv camera calibration constant in python , OpenCV Error: Assertion failed (nimages > 0) in cv::calibrateCamera 使用对象检测时出现 Open cv 错误 - I am getting a Open cv error when working with object detection
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM