簡體   English   中英

我目前正在研究我的人臉識別 open-cv,這個問題在我登錄后一直顯示

[英]I am currently working on my face recognition open-cv and this issue keeps showing after I log it

Tkinter 回調異常

回溯(最后一次調用):文件“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'

上述異常是以下異常的直接原因:

回溯(最后一次調用):文件“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'

這是產生錯誤的代碼。

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()

你的錯誤在這里:

aa=df.loc[df.get['Id'] == Id]['Name'].values

您使用了square括號而不是small括號

改用這個:

aa=df.loc[df.get('Id') == Id]['Name'].values

或者,你也可以使用這個:

aa=df.loc[df['Id'] == Id]['Name'].values

這是我的 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

這是我的 csv 的樣子。 在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM