飞道的博客

OpenCV人脸检测打卡系统

309人阅读  评论(0)

Python+OpenCV人脸检测打卡系统

如需远程调试,可加QQ905733049由专业技术人员远程协助!

运行代码如下:


  
  1. from tkinter import *
  2. from tkinter import ttk
  3. import db
  4. import detect
  5. class APP:
  6. def __init__(self):
  7. self.root = Tk()
  8. self.root.title( 'FACE')
  9. self.root.geometry( '%dx%d' % ( 550, 450))
  10. self.createFirstPage()
  11. # 新录入的人的姓名
  12. self.name = StringVar()
  13. def createFirstPage(self):
  14. self.page1 = Frame( self.root)
  15. self.page1.grid()
  16. Label( self.page1, height= 4, text= '人脸识别系统', font=( 'microsoft yahei', 26)).grid(columnspan= 2)
  17. #self.usernames 是 用户名字组成的列表
  18. self.usernames = []
  19. self.usernames = self.mydb.query_name()
  20. self.button11 = Button( self.page1, width= 18, height= 2, text= "签到打卡", bg= 'white', font=( "microsoft yahei", 14),
  21. relief= 'raise', command = lambda :detect.check( self.usernames))
  22. self.button11.grid(row= 1, column= 0, padx= 25, pady= 10)
  23. self.button12 = Button( self.page1, width= 18, height= 2, text= "录入新的人脸", bg= 'white', font=( "microsoft yahei", 14),
  24. relief= 'raise', command = self.createSecondPage)
  25. self.button12.grid(row= 1, column= 1, padx= 25, pady= 10)
  26. self.button13 = Button( self.page1, width= 18, height= 2, text= "查询签到信息", bg= 'white', font=( "microsoft yahei", 14),
  27. relief= 'raise',command = self.checkDataView)
  28. self.button13.grid( row= 2, column= 0,padx= 25, pady= 10)
  29. self.button14 = Button( self.page1, width= 18, height= 2, text= "退出系统", bg= 'gray', font=( "microsoft yahei", 14),
  30. relief= 'raise',command = self.quitMain)
  31. self.button14.grid(row= 2, column= 1,padx= 25, pady= 10)
  32. def createSecondPage(self):
  33. # self.camera = cv2.VideoCapture(0)
  34. self.page1.grid_forget()
  35. self.page2 = Frame( self.root)
  36. self.page2.pack()
  37. Label( self.page2, text= '欢迎使用人脸识别系统', font=( '粗体', 20)).pack()
  38. # 输入姓名的文本框
  39. font1 = ( '宋', 18)
  40. # self.name = StringVar()
  41. self.text = Entry( self.page2, textvariable= self.name, width= 20, font=font1).pack(side=LEFT)
  42. self.name.set( '请输入姓名')
  43. # 确认名字的按钮
  44. self.button21 = Button( self.page2, text= '确认', bg= 'white', font=( "宋", 12),
  45. relief= 'raise', command=lambda :add_face.add_face( self.name, self.usernames))
  46. self.button21.pack(side=LEFT, padx= 5, pady= 10)
  47. # 返回按钮
  48. self.button22 = Button(page2, text= "返回", bg= 'white', font=( "宋", 12),
  49. relief= 'raise',command = self.backFirst)
  50. self.button22.pack(side=LEFT, padx= 10, pady= 10)
  51. def checkDataView(self):
  52. self.page3 = Frame( self.root)
  53. self.page1.grid_forget()
  54. self.root.geometry( '700x360')
  55. self.page3.pack()
  56. Label( self.page3, text= '今日签到信息', bg= 'white', fg= 'red', font=( '宋体', 25)).pack(side=TOP, fill= 'x')
  57. # 签到信息查看视图
  58. self.checkDate = ttk.Treeview( self.page3, show= 'headings', column=( 'sid', 'name', 'check_time'))
  59. self.checkDate.column( 'sid', width= 100, anchor= "center")
  60. self.checkDate.column( 'name', width= 200, anchor= "center")
  61. self.checkDate.column( 'check_time', width= 300, anchor= "center")
  62. self.checkDate.heading( 'sid', text= '签到序号')
  63. self.checkDate.heading( 'name', text= '名字')
  64. self.checkDate.heading( 'check_time', text= '签到时间')
  65. # 插入数据
  66. self.records = self.mydb.query_record()
  67. for i in self. records:
  68. self.checkDate.insert( '', 'end', values=i)
  69. # y滚动条
  70. yscrollbar = Scrollbar( self.page3, orient=VERTICAL, command= self.checkDate.yview)
  71. self.checkDate.configure(yscrollcommand=yscrollbar.set)
  72. yscrollbar.pack(side=RIGHT, fill=Y)
  73. self.checkDate.pack(expand= 1, fill=BOTH)
  74. # 返回按钮
  75. Button( self.page3, width= 20, height= 2, text= "返回", bg= 'gray', font=( "宋", 12),
  76. relief= 'raise',command = self.backMain).pack(padx = 20, pady = 20)
  77. def backFirst(self):
  78. self.page2.pack_forget()
  79. self.root.geometry( '400x300')
  80. self.page1.grid()
  81. def backMain(self):
  82. self.root.geometry( '400x300')
  83. self.page3.pack_forget()
  84. self.page1.grid()
  85. def quitMain(self):
  86. sys.exit( 0)
  87. if __name_ _ == '__main__':
  88. demo = APP()

运行结果:


转载:https://blog.csdn.net/alicema1111/article/details/105315066
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场