├── recognition_back-end
└── CashierManagement
│ ├── CashierWork
│ ├── __init__.py
│ ├── migrations
│ │ ├── __init__.py
│ │ ├── __pycache__
│ │ │ ├── __init__.cpython-36.pyc
│ │ │ └── 0001_initial.cpython-36.pyc
│ │ └── 0001_initial.py
│ ├── tests.py
│ ├── apps.py
│ ├── __pycache__
│ │ ├── admin.cpython-36.pyc
│ │ ├── urls.cpython-36.pyc
│ │ ├── views.cpython-36.pyc
│ │ ├── __init__.cpython-36.pyc
│ │ └── models.cpython-36.pyc
│ ├── urls.py
│ ├── admin.py
│ ├── models.py
│ └── views.py
│ ├── CashierManagement
│ ├── __init__.py
│ ├── __pycache__
│ │ ├── urls.cpython-36.pyc
│ │ ├── wsgi.cpython-36.pyc
│ │ ├── __init__.cpython-36.pyc
│ │ └── settings.cpython-36.pyc
│ ├── asgi.py
│ ├── wsgi.py
│ ├── urls.py
│ └── settings.py
│ ├── templates
│ └── post.html
│ ├── manage.py
│ ├── server.crt
│ └── server.key
├── timg.jpg
├── user.jpeg
├── test_face.jpg
├── background.jpeg
├── background1.jpeg
├── administrators.jpeg
├── FileDrawRect
├── __pycache__
│ ├── MyLabel.cpython-36.pyc
│ └── main_ui.cpython-36.pyc
├── file_drawRect.py
├── MyLabel.py
└── main_ui.py
├── Cashier_management
├── __pycache__
│ ├── lock_on.cpython-36.pyc
│ ├── home_page.cpython-36.pyc
│ ├── capturetest.cpython-36.pyc
│ ├── cashier_work.cpython-36.pyc
│ ├── cashier_console.cpython-36.pyc
│ ├── cashier_datalab.cpython-36.pyc
│ ├── admin_FaceCollect.cpython-36.pyc
│ ├── capture_distinguish.cpython-36.pyc
│ ├── cashier_FaceCollect.cpython-36.pyc
│ ├── administrators_console.cpython-36.pyc
│ └── administreators_datalab.cpython-36.pyc
├── executive.py
├── lock_on.py
├── capturetest.py
├── home_page.py
├── administrators_console.py
├── cashier_work.py
├── admin_FaceCollect.py
├── cashier_FaceCollect.py
├── cashier_console.py
├── administreators_datalab.py
├── cashier_datalab.py
└── capture_distinguish.py
├── README.md
├── .idea
├── misc.xml
├── modules.xml
├── FaceRecognition.iml
└── workspace.xml
└── Cashier_con.py
/recognition_back-end/CashierManagement/CashierWork/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/timg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/timg.jpg
--------------------------------------------------------------------------------
/user.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/user.jpeg
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/migrations/__init__.py:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/test_face.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/test_face.jpg
--------------------------------------------------------------------------------
/background.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/background.jpeg
--------------------------------------------------------------------------------
/background1.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/background1.jpeg
--------------------------------------------------------------------------------
/administrators.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/administrators.jpeg
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/__init__.py:
--------------------------------------------------------------------------------
1 | import pymysql
2 | pymysql.install_as_MySQLdb()
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/tests.py:
--------------------------------------------------------------------------------
1 | from django.test import TestCase
2 |
3 | # Create your tests here.
4 |
--------------------------------------------------------------------------------
/FileDrawRect/__pycache__/MyLabel.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/FileDrawRect/__pycache__/MyLabel.cpython-36.pyc
--------------------------------------------------------------------------------
/FileDrawRect/__pycache__/main_ui.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/FileDrawRect/__pycache__/main_ui.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/lock_on.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/lock_on.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/home_page.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/home_page.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/capturetest.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/capturetest.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/cashier_work.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/cashier_work.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/cashier_console.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/cashier_console.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/cashier_datalab.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/cashier_datalab.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/admin_FaceCollect.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/admin_FaceCollect.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/capture_distinguish.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/capture_distinguish.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/cashier_FaceCollect.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/cashier_FaceCollect.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/apps.py:
--------------------------------------------------------------------------------
1 | from django.apps import AppConfig
2 |
3 |
4 | class CashierworkConfig(AppConfig):
5 | name = 'CashierWork'
6 |
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/administrators_console.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/administrators_console.cpython-36.pyc
--------------------------------------------------------------------------------
/Cashier_management/__pycache__/administreators_datalab.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/Cashier_management/__pycache__/administreators_datalab.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/__pycache__/admin.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierWork/__pycache__/admin.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/__pycache__/urls.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierWork/__pycache__/urls.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/__pycache__/views.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierWork/__pycache__/views.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierWork/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/__pycache__/models.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierWork/__pycache__/models.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/__pycache__/urls.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierManagement/__pycache__/urls.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/__pycache__/wsgi.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierManagement/__pycache__/wsgi.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierManagement/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/__pycache__/settings.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierManagement/__pycache__/settings.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/migrations/__pycache__/__init__.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierWork/migrations/__pycache__/__init__.cpython-36.pyc
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/migrations/__pycache__/0001_initial.cpython-36.pyc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/GODrowsy/-/HEAD/recognition_back-end/CashierManagement/CashierWork/migrations/__pycache__/0001_initial.cpython-36.pyc
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # -
2 | 基于物联网技术以及人脸识别技术,系统底层采用ESP32开发板为核心,在ESP32开发板上接入了红外对管传感器、蜂鸣器、电磁锁等元器件,当有人暴力开锁触发红外报警信息时,便会通过蜂鸣器报警。应用层PC端使用摄像头实现人脸识别,实现用户登录以及收银台解锁,通过TCP协议与云主机服务器中的MYSQL数据库进行连接,实现用户控制台与数据库之间的数据互传;微信小程序端使用HTTPS协议与云主机服务器连接,通过访问服务器中的MYSQL数据库实现用户登录、工作情况查询等操作功能。
3 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/urls.py:
--------------------------------------------------------------------------------
1 | from django.urls import path
2 | from django.conf.urls import url
3 | from . import views
4 |
5 | app_name = 'CashierWork'
6 | urlpatterns = [
7 | url(r'^find', views.find),
8 | url(r'^Findall', views.findall),
9 | url(r'^wxAdSign', views.wxAdSign),
10 | url(r'^wxCaSign', views.wxCaSign),
11 | ]
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/templates/post.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | POST Params
6 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/admin.py:
--------------------------------------------------------------------------------
1 | from __future__ import unicode_literals
2 | from django.contrib import admin
3 |
4 | from .models import *
5 |
6 | # Register your models here.
7 | # 自定义显示效果类
8 | class WorkDateAdmin(admin.ModelAdmin):
9 | list_display = ['id', 'name_id', 'name', 'firsttime', 'lasttime', 'date']
10 |
11 |
12 | # 注册模型类
13 | admin.site.register(WorkDate, WorkDateAdmin)
--------------------------------------------------------------------------------
/.idea/FaceRecognition.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/asgi.py:
--------------------------------------------------------------------------------
1 | """
2 | ASGI config for CashierManagement project.
3 |
4 | It exposes the ASGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.asgi import get_asgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CashierManagement.settings')
15 |
16 | application = get_asgi_application()
17 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/wsgi.py:
--------------------------------------------------------------------------------
1 | """
2 | WSGI config for CashierManagement project.
3 |
4 | It exposes the WSGI callable as a module-level variable named ``application``.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
8 | """
9 |
10 | import os
11 |
12 | from django.core.wsgi import get_wsgi_application
13 |
14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CashierManagement.settings')
15 |
16 | application = get_wsgi_application()
17 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/manage.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python
2 | """Django's command-line utility for administrative tasks."""
3 | import os
4 | import sys
5 |
6 |
7 | def main():
8 | """Run administrative tasks."""
9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'CashierManagement.settings')
10 | try:
11 | from django.core.management import execute_from_command_line
12 | except ImportError as exc:
13 | raise ImportError(
14 | "Couldn't import Django. Are you sure it's installed and "
15 | "available on your PYTHONPATH environment variable? Did you "
16 | "forget to activate a virtual environment?"
17 | ) from exc
18 | execute_from_command_line(sys.argv)
19 |
20 |
21 | if __name__ == '__main__':
22 | main()
23 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/urls.py:
--------------------------------------------------------------------------------
1 | """CashierManagement URL Configuration
2 |
3 | The `urlpatterns` list routes URLs to views. For more information please see:
4 | https://docs.djangoproject.com/en/3.1/topics/http/urls/
5 | Examples:
6 | Function views
7 | 1. Add an import: from my_app import views
8 | 2. Add a URL to urlpatterns: path('', views.home, name='home')
9 | Class-based views
10 | 1. Add an import: from other_app.views import Home
11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
12 | Including another URLconf
13 | 1. Import the include() function: from django.urls import include, path
14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
15 | """
16 | from django.contrib import admin
17 | from django.urls import path
18 | from django.conf.urls import url, include
19 |
20 | urlpatterns = [
21 | path('admin/', admin.site.urls),
22 | url(r'', include('CashierWork.urls')),
23 | ]
24 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/models.py:
--------------------------------------------------------------------------------
1 | from django.db import models
2 |
3 | # Create your models here.
4 |
5 |
6 | class WorkDate(models.Model):
7 | id = models.IntegerField(primary_key=True)
8 | name_id = models.IntegerField()
9 | name = models.CharField(max_length=255)
10 | firsttime = models.TimeField()
11 | lasttime = models.TimeField()
12 | date = models.DateField()
13 |
14 | def __str__(self):
15 | return self.name.encode('utf-8')
16 |
17 | class Meta():
18 | db_table = 'cashierwork'
19 |
20 |
21 | class AdminDate(models.Model):
22 | id = models.IntegerField(primary_key=True)
23 | name = models.CharField(max_length=255)
24 | password = models.CharField(max_length=255)
25 | datetime = models.DateField()
26 |
27 | def __str__(self):
28 | return self.name.encode('utf-8')
29 |
30 | class Meta():
31 | db_table = 'admin'
32 |
33 |
34 | class CashierDate(models.Model):
35 | id = models.IntegerField(primary_key=True)
36 | name = models.CharField(max_length=255)
37 | password = models.CharField(max_length=255)
38 | datetime = models.DateField()
39 |
40 | def __str__(self):
41 | return self.name.encode('utf-8')
42 |
43 | class Meta():
44 | db_table = 'cashier'
45 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/server.crt:
--------------------------------------------------------------------------------
1 | -----BEGIN CERTIFICATE-----
2 | MIIDiDCCAnACCQDjpwJwLC4DOjANBgkqhkiG9w0BAQUFADCBhTELMAkGA1UEBhMC
3 | Q04xETAPBgNVBAgTCFNoYW5naGFpMREwDwYDVQQHEwhTaGFuZ2hhaTEPMA0GA1UE
4 | ChMGc3VuZWVlMQ8wDQYDVQQLEwZ0ZXN0ZXIxDDAKBgNVBAMTA2x0dzEgMB4GCSqG
5 | SIb3DQEJARYRMTQ2ODA5MTY0N0BxcS5jb20wHhcNMjEwMjIxMTU0MzI1WhcNMjIw
6 | MjIxMTU0MzI1WjCBhTELMAkGA1UEBhMCQ04xETAPBgNVBAgTCFNoYW5naGFpMREw
7 | DwYDVQQHEwhTaGFuZ2hhaTEPMA0GA1UEChMGc3VuZWVlMQ8wDQYDVQQLEwZ0ZXN0
8 | ZXIxDDAKBgNVBAMTA2x0dzEgMB4GCSqGSIb3DQEJARYRMTQ2ODA5MTY0N0BxcS5j
9 | b20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCoxNmVzDpAfb1ZHHjZ
10 | ZvbdFAsZvPdaQbFmmaSCPl2usYRQrImScfOhpUtpsiz0T7ftyH/iZK5deKAq/t60
11 | +zy7DGN13fMJhWlFqlUtBEPjXY/2RzSFQYucF+R79XgToW9ja2yJSGZPwwQgISEp
12 | cGAodIiO5Cd4F09Vrs2A2fgBzt6KG1EakJdOhc49zNagNCd8RXLsh8OhCo4Y6Q4E
13 | o2iqlctlX6WRz6gsfrKAmyIVIwOr7lImrvj9HXkevcpX+aB9jQGxsK+SD9J5Bk9s
14 | Bza2Bqjc2GeL7ZwNTRYHTcg5138LNCya6GdyV+7Vdw86ql9bfPMN/IcZCNef7Or6
15 | s41XAgMBAAEwDQYJKoZIhvcNAQEFBQADggEBABMmDgvzaJ5ifbjjMn0e6Jo/9Pd5
16 | /XHrwSnQDD04gG/fLz1Eg7NHQoIGV+2YfOoYwXNAh/CKnKg1r5mARPgJX5W+3Z8x
17 | Heo3taxOc9wulevaHBJ0HAEs9+J13kNpDvqrLafVEve2Zkdz2RH6Up92BW2iPLea
18 | 0zQIZVhT9pMzoB5mYF4SihQGoIGcGx6s6eNST/gC55UjL2Rl2F6l7r6zl3qDD6Yo
19 | ov70XD6lsjeaexdVHbDCkkTZDhl6YWjembKFtsepeWlPvwqsL2WZSVqc9o2SZBk+
20 | q/BWTpG44MZwBq9PhbppTln4cWHXG9aHyRp0DpqdNqzvOReSi//a4wSTZXI=
21 | -----END CERTIFICATE-----
22 |
--------------------------------------------------------------------------------
/Cashier_con.py:
--------------------------------------------------------------------------------
1 |
2 | import time
3 | from machine import Pin, UART
4 | led=Pin(2,Pin.OUT) #create LED object from pin2,Set Pin2 to output
5 | Rout=Pin(4,Pin.OUT)
6 | Rin=Pin(16,Pin.IN)
7 | lock=Pin(17,Pin.OUT)
8 | Buzzer=Pin(5,Pin.OUT)
9 |
10 | uart = UART(2, baudrate=115200, rx=13,tx=12,timeout=10)
11 | L=1
12 | out = True
13 | while True:
14 | uart = UART(2, baudrate=115200, rx=13,tx=12,timeout=10)
15 | if L == 0:
16 | lock.value(0)
17 | L=1
18 | print(uart.any())
19 | time.sleep(1)
20 | if uart.any():
21 | if uart.any()<=3:
22 | uart = UART(2, baudrate=115200, rx=13,tx=12,timeout=10)
23 | continue
24 | bin_data = uart.readline().decode()
25 | print('Echo String: {}'.format(bin_data))
26 | if bin_data == 'close':
27 | out = False
28 | elif bin_data == 'open':
29 | out = True
30 | elif bin_data == 'lockon':
31 | lock.value(1)
32 | time.sleep(5)
33 | L=0
34 | while out:
35 | Rout.value(1)
36 | if Rin.value() == 1:
37 | print('cabinet off')
38 | led.value(0)
39 | Buzzer.value(0)
40 | time.sleep(0.5)
41 | elif Rin.value() == 0:
42 | print('cabinet on')
43 | led.value(1)
44 | Buzzer.value(1)
45 | time.sleep(0.5)
46 |
47 | if uart.any():
48 | bin_data = uart.readline().decode()
49 | print('Echo String: {}'.format(bin_data))
50 | if bin_data == 'close':
51 | out = False
52 | elif bin_data == 'open':
53 | out = True
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/migrations/0001_initial.py:
--------------------------------------------------------------------------------
1 | # Generated by Django 3.1.4 on 2021-03-03 15:04
2 |
3 | from django.db import migrations, models
4 |
5 |
6 | class Migration(migrations.Migration):
7 |
8 | initial = True
9 |
10 | dependencies = [
11 | ]
12 |
13 | operations = [
14 | migrations.CreateModel(
15 | name='AdminDate',
16 | fields=[
17 | ('id', models.IntegerField(primary_key=True, serialize=False)),
18 | ('name', models.CharField(max_length=255)),
19 | ('password', models.CharField(max_length=255)),
20 | ('date', models.DateField()),
21 | ],
22 | options={
23 | 'db_table': 'admin',
24 | },
25 | ),
26 | migrations.CreateModel(
27 | name='CashierDate',
28 | fields=[
29 | ('id', models.IntegerField(primary_key=True, serialize=False)),
30 | ('name', models.CharField(max_length=255)),
31 | ('password', models.CharField(max_length=255)),
32 | ('date', models.DateField()),
33 | ],
34 | options={
35 | 'db_table': 'cashier',
36 | },
37 | ),
38 | migrations.CreateModel(
39 | name='WorkDate',
40 | fields=[
41 | ('id', models.IntegerField(primary_key=True, serialize=False)),
42 | ('name_id', models.IntegerField()),
43 | ('name', models.CharField(max_length=255)),
44 | ('firsttime', models.TimeField()),
45 | ('lasttime', models.TimeField()),
46 | ('date', models.DateField()),
47 | ],
48 | options={
49 | 'db_table': 'cashierwork',
50 | },
51 | ),
52 | ]
53 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/server.key:
--------------------------------------------------------------------------------
1 | -----BEGIN RSA PRIVATE KEY-----
2 | Proc-Type: 4,ENCRYPTED
3 | DEK-Info: DES-EDE3-CBC,56D52395F6620F3A
4 |
5 | MmDfVDUIlb5kKb7ke8T8/kDyF1Iow8mRdMmNI4AUP0URuhOMdBnRmSUIHaevzPGm
6 | CaKyjtpjp1UX44yPR67bGhEuYoC7JxDxwNzcgVnAxzoGHwHZsvg/bumlwNEh9STZ
7 | V7/NHzZGGWvNbys5a3QQpjJy0XerlCWc3/5oS+2xlGqA35fD2/kLf160aDStnMn1
8 | 5vgi3DjgdXwKY/lIVEAc1waF25F/zo/2QaVCEZchkmDzy02oe+0uV5ub6rFNZ9cG
9 | w5iESsFCqsizEg6CNc27tiUAmOgt/7FXAZaIuF9ynCx+qh4TyDC6YmAmj4LcNRHI
10 | tPw//7wnVerZCEbZE35sO5vpb+K62FUT4O6I4CQDNHXyGRxXiBkO/WrrngLK7lgS
11 | wcUJWqccvMh/Cz2jopxB2ZfVjWghMdCp9LKiIrL3RhI7d9mGFHVgPgH7GxZXm2OY
12 | Q+umNmQrmlbCpQoRK+RPj0Fm7tu0GKXqgz8jbomXSHEXH4pDEByps8dW4zfnjx3T
13 | XUcRl/KnPX2fOMI6p9jRWhxGzzF9GGlZEwqrz9cIiFpkH3WmiGNed+2dFTEta3UL
14 | z3RgbNiwRiGpqEUmNZghlu0Jn3gOaSX6vS4RI8OTM+IdoiCYdZNy26GY3UndT0W/
15 | lwXy0wxOpYhye8lBu5mR1TACBJ6uzm+2wOtVLpETQ7d5+x2QQb3TG32PsHQCv6Dr
16 | LJGyS9Jrege6eIF3BS0xNVZ1sMGgj6NlUfiZya7WSvhnjP/fQXjaEdwPYDzINtT7
17 | 9016WnJYO4XHgz5RQsw4srNqUvjjckSLDDnAV2dT3PuSWtVVTxEvJVTPOhrWjriM
18 | ODddfW8nU1P6692xYk0ZA6d7Y9YsMy3b6gVgEWuYcirZxDOn2bakQQQuJhsu+BJE
19 | aWnCgMwGQkUtkrqDrm+smY1X84l79Nfd8swUIHyWc+MhTkDqyBUg/ItwHYD7fnVx
20 | mqGKzW6+JSwqenp+5sQoiS9Q2Lc8hnCw96CgL5gzTwuax6o7UAx7EoJpNSFXmQts
21 | 1hwlM0V58JuXKd/0FSoMAaPk9PE0XISKlJp/gIjYnwxdGXQx3zSXLZPEuaOtPw+5
22 | 0iONEzs/tmbJvHkDEkTBQt4wRXcbNlJOQIwqqAucNiGo9TBNeOo9PWo6sV833u2+
23 | UtBkVydovoxr1aE8P74OEmG7+yMzKOyu7lVZYfXHkTIpB5gc2zeT1MVrF4MFz90H
24 | cGq3HnZmEwrlX1jTNwEM2a3nFLtbNH584/SQuKHjrgGhXye0YjRxefObQ7Az1Gj6
25 | kvsmYrt02iFUVwoC+i/W3k0lCUzQHAvW3VM7mcQFvl75Gv7rqyYBwasTvvKAdcRJ
26 | N3ZUDflAmtthnkfGb8BmBXh2v2jcNZuFZl8Pvrph+LgQ/4E7vuKLdTLoegNWwO1v
27 | 01tDFCNZ+b5sz89ltP3x1GXFaYFAoVqd/lJKzt9YXArBB9OQ9K6WiH3yYq0H2zEm
28 | WjUjszGBwEv/bVwe5K8hUjY/Qx8tv4gD50dMbBCEpC46x9lSGrmPw+KfgG3vTTfw
29 | B5qhINoxGVUfMXrpq+MkHJY6isz6E4H0UCVHvxL9NkRdKtqosnFAoH3J0hoJdFkl
30 | -----END RSA PRIVATE KEY-----
31 |
--------------------------------------------------------------------------------
/FileDrawRect/file_drawRect.py:
--------------------------------------------------------------------------------
1 | import sys
2 | from PIL import ImageQt, Image
3 | from PyQt5 import QtCore
4 | from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog, QLabel
5 | from main_ui import Ui_MainWindow
6 |
7 | class MyMainWindow(QMainWindow, Ui_MainWindow):
8 | def __init__(self, parent=None):
9 | super().__init__(parent)
10 | self.setupUi(self)
11 | img = Image.open(r'E:\\py project\\FaceRecognition\\background.jpeg')
12 | img = self.transImg(img)
13 | self.label.setPixmap(img)
14 |
15 | self.flagPaint = False
16 |
17 | self.pushButton.clicked.connect(self.getImage)
18 | self.pushButton_2.clicked.connect(self.saveImage)
19 |
20 | def getImage(self):
21 | fdir, ftypr = QFileDialog.getOpenFileName(self,
22 | "选择图片",
23 | "../",
24 | "Image Files (*.png *.jpg *.jpeg)")
25 |
26 | img = Image.open(fdir)
27 | img = self.transImg(img)
28 | self.label.setPixmap(img)
29 |
30 | self.label.initDrawing(img)
31 | self.label.drawingPermission(True)
32 | self.flagPaint = True
33 |
34 | def saveImage(self):
35 | if self.flagPaint:
36 | img = self.label.pix.toImage()
37 | fdir, ftypr = QFileDialog.getOpenFileName(self,
38 | "保存图片",
39 | "../",
40 | "Image Files (*.jpg)")
41 | img.save(fdir)
42 |
43 | def transImg(self, img):
44 | img = img.resize((self.label.width(), self.label.height()))
45 | return ImageQt.toqpixmap(img)
46 |
47 |
48 | if __name__ == "__main__":
49 | QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
50 |
51 | app = QApplication(sys.argv)
52 | myWin = MyMainWindow()
53 | myWin.show()
54 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/FileDrawRect/MyLabel.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QtWidgets import QLabel
2 | from PyQt5.QtCore import Qt, QPoint
3 | from PyQt5.QtGui import QPainter, QPixmap, QPen, QFont
4 |
5 | class MyLabel(QLabel):
6 | def __init__(self, parent):
7 | super().__init__(parent)
8 | self.drawable = False
9 |
10 | def drawingPermission(self, a):
11 | if isinstance(a, bool):
12 | self.drawable = a
13 |
14 | def initDrawing(self, img):
15 | self.pix =img
16 | self.tmpPix = self.pix.copy()
17 | self.lastPoint = QPoint()
18 | self.endPoint = QPoint()
19 |
20 | def drawRect(self, lastPoint, endPoint):
21 | if self.drawable:
22 | self.pix = self.tmpPix.copy()
23 | pp = QPainter(self.pix)
24 | pp.setPen(QPen(Qt.blue, 5))
25 | pp.drawRect(lastPoint.x(), lastPoint.y(),
26 | endPoint.x() - lastPoint.x(),
27 | endPoint.y() - lastPoint.y())
28 | # pp.setFont(QFont('SimSun', 20))
29 | # pp.drawText(0, 0, s)
30 | self.update()
31 | self.tmpPix = self.pix
32 | self.lastPoint = lastPoint
33 | self.endPoint = endPoint
34 |
35 | def paintEvent(self, event):
36 | super().paintEvent(event)
37 | if self.drawable:
38 | pp = QPainter(self)
39 | pp.begin(self)
40 | pp.drawPixmap(self.rect(), self.pix)
41 | pp.end()
42 |
43 | # def mousePressEvent(self, event):
44 | # super().mousePressEvent(event)
45 | # if self.drawable:
46 | # if event.buttons() and Qt.LeftButton:
47 | # self.endPoint = event.pos()
48 | #
49 | # self.pix = self.tmpPix.copy()
50 | # pp = QPainter(self.pix)
51 | # pp.setPen(QPen(Qt.blue, 5))
52 | # pp.drawRect(self.lastPoint.x(), self.lastPoint.y(),
53 | # self.endPoint.x() - self.lastPoint.x(),
54 | # self.endPoint.y() - self.lastPoint.y())
55 | # self.update()
56 | #
57 | # def mouseReleaseEvent(self, event):
58 | # super().mouseReleaseEvent(event)
59 | # if self.drawable:
60 | # if event.buttons() == Qt.LeftButton:
61 | # self.tmpPix = self.pix
62 |
--------------------------------------------------------------------------------
/FileDrawRect/main_ui.py:
--------------------------------------------------------------------------------
1 | from PyQt5 import QtCore, QtGui, QtWidgets
2 | from MyLabel import MyLabel
3 |
4 |
5 | class Ui_MainWindow(object):
6 | def setupUi(self, MainWindow):
7 | MainWindow.setObjectName("MainWindow")
8 | MainWindow.resize(600, 480)
9 | self.centralwidget = QtWidgets.QWidget(MainWindow)
10 | self.centralwidget.setObjectName("centralwidget")
11 | self.pushButton = QtWidgets.QPushButton(self.centralwidget)
12 | self.pushButton.setGeometry(QtCore.QRect(140, 370, 131, 41))
13 | font = QtGui.QFont()
14 | font.setFamily("Arial")
15 | font.setPointSize(14)
16 | self.pushButton.setFont(font)
17 | self.pushButton.setObjectName("pushButton")
18 |
19 | # 生成代码为:
20 | # self.label = QtWidgets.QLabel(self.centralwidget)
21 | # 这里改为MyLabel,因为QLabel的鼠标点击事件没有具体实现,我们需要重写这个类的鼠标点击方法
22 | self.label = MyLabel(self.centralwidget)
23 | self.label.setGeometry(QtCore.QRect(110, 40, 401, 281))
24 | self.label.setText("")
25 | self.label.setObjectName("label")
26 |
27 | self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
28 | self.pushButton_2.setGeometry(QtCore.QRect(360, 370, 131, 41))
29 | font = QtGui.QFont()
30 | font.setFamily("Arial")
31 | font.setPointSize(14)
32 | self.pushButton_2.setFont(font)
33 | self.pushButton_2.setObjectName("pushButton_2")
34 | MainWindow.setCentralWidget(self.centralwidget)
35 | self.menubar = QtWidgets.QMenuBar(MainWindow)
36 | self.menubar.setGeometry(QtCore.QRect(0, 0, 600, 22))
37 | self.menubar.setObjectName("menubar")
38 | self.menuOpen = QtWidgets.QMenu(self.menubar)
39 | self.menuOpen.setObjectName("menuOpen")
40 | MainWindow.setMenuBar(self.menubar)
41 | self.statusbar = QtWidgets.QStatusBar(MainWindow)
42 | self.statusbar.setObjectName("statusbar")
43 | MainWindow.setStatusBar(self.statusbar)
44 | self.actionNew = QtWidgets.QAction(MainWindow)
45 | self.actionNew.setObjectName("actionNew")
46 | self.menuOpen.addAction(self.actionNew)
47 | self.menubar.addAction(self.menuOpen.menuAction())
48 |
49 | self.retranslateUi(MainWindow)
50 | QtCore.QMetaObject.connectSlotsByName(MainWindow)
51 |
52 | def retranslateUi(self, MainWindow):
53 | _translate = QtCore.QCoreApplication.translate
54 | MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
55 | self.pushButton.setText(_translate("MainWindow", "Get Image"))
56 | self.pushButton_2.setText(_translate("MainWindow", "Save Image"))
57 | self.menuOpen.setTitle(_translate("MainWindow", "Open"))
58 | self.actionNew.setText(_translate("MainWindow", "New"))
59 |
--------------------------------------------------------------------------------
/Cashier_management/executive.py:
--------------------------------------------------------------------------------
1 | from Cashier_management_new import home_page
2 | from Cashier_management_new import capture_distinguish
3 | from Cashier_management_new import administrators_console
4 | from Cashier_management_new import cashier_console
5 | from Cashier_management_new import administreators_datalab
6 | from Cashier_management_new import cashier_datalab
7 | from Cashier_management_new import admin_FaceCollect
8 | from Cashier_management_new import cashier_FaceCollect
9 | from Cashier_management_new import cashier_work
10 | from Cashier_management_new import lock_on
11 |
12 | import sys
13 | from PyQt5 import QtCore, QtWidgets
14 |
15 | class Controller:
16 |
17 | def __init__(self):
18 | pass
19 |
20 | def show_home(self):
21 | self.home = home_page.HomePage()
22 | self.home.switch_window.connect(self.show_cap_dis)
23 | self.home.show()
24 |
25 | def show_cap_dis(self, user):
26 | print(user)
27 | self.cap_dis = capture_distinguish.GUI(user)
28 | if user == '收银员':
29 | self.cap_dis.switch_window.connect(self.show_cashier_con)
30 | elif user == '管理员':
31 | self.cap_dis.switch_window.connect(self.show_admin_con)
32 | # self.home.close()
33 | self.cap_dis.show()
34 |
35 | def show_cashier_con(self, user):
36 | self.cashier_con = cashier_console.CashierConsole(user)
37 | self.cashier_con.lock_window.connect(self.show_lock_on)
38 | self.cashier_con.home_window.connect(self.show_home)
39 | self.cap_dis.close()
40 | self.cashier_con.show()
41 |
42 | def show_lock_on(self, user):
43 | self.lock_on = lock_on.CashierConsole(user)
44 | self.lock_on.switch_window.connect(self.show_cap_dis)
45 | self.cashier_con.close()
46 | self.lock_on.show()
47 |
48 |
49 | def show_admin_con(self, user):
50 | self.admin_con = administrators_console.CashierConsole(user)
51 | self.admin_con.cashwork_window.connect(self.show_cashier_work)
52 | self.admin_con.cash_window.connect(self.show_cashier_data)
53 | self.admin_con.admin_window.connect(self.show_admin_data)
54 | self.cap_dis.close()
55 | self.admin_con.show()
56 |
57 | def show_cashier_data(self):
58 | # self.cashier_data = cashier_datalab.Controller.show_main()
59 | self.cashier_data = cashier_datalab.DataLab()
60 | self.cashier_data.show()
61 |
62 | def show_cashier_face_col(self, name, id):
63 | self.cashier_face_col = cashier_FaceCollect.GUI(name, id)
64 | self.cashier_face_col.show()
65 |
66 | def show_admin_data(self):
67 | # self.admin_data = administreators_datalab.Controller.show_main()
68 | self.admin_data = administreators_datalab.DataLab()
69 | self.admin_data.show()
70 |
71 | def show_admin_face_col(self, name, id):
72 | self.admin_face_col = admin_FaceCollect.GUI(name, id)
73 | self.admin_face_col.show()
74 |
75 | def show_cashier_work(self):
76 | self.cashier_work = cashier_work.DataLab()
77 | self.cashier_work.show()
78 |
79 | def main():
80 | app = QtWidgets.QApplication(sys.argv)
81 | controller = Controller()
82 | controller.show_home()
83 | sys.exit(app.exec_())
84 |
85 |
86 | if __name__ == '__main__':
87 | main()
--------------------------------------------------------------------------------
/Cashier_management/lock_on.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QtWidgets import *
2 | from PyQt5.QtGui import *
3 | from PyQt5.QtCore import Qt, QTimer, QDateTime
4 |
5 | import sys
6 | from Cashier_management import capture_distinguish
7 | from PyQt5 import QtCore
8 |
9 |
10 | class CashierConsole(QMainWindow):
11 | switch_window = QtCore.pyqtSignal(str)
12 |
13 | def __init__(self, user = 'qwe'):
14 | super(CashierConsole, self).__init__()
15 | self.user = user
16 | self.init_ui()
17 |
18 | def init_ui(self):
19 | self.userimage = QPixmap('E:\\py project\\FaceRecognition\\user.jpeg')
20 |
21 | self.statusBar().showMessage('Ready')
22 | self.setWindowTitle('收银台已锁')
23 | self.setWindowIcon(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'))
24 | # 窗体大小
25 | self.resize(1200, 900)
26 | # 窗体居中
27 | self.center()
28 |
29 | self.user_name = QLabel(self)
30 | self.user_name.setAlignment(Qt.AlignCenter)
31 | self.user_name.setFont(QFont("Roman times", 18))
32 | self.user_name.setGeometry(400, 50, 400, 100)
33 |
34 | self.btn = QPushButton('解锁', self)
35 | self.btn.setToolTip('人脸识别解锁继续工作!')
36 | self.btn.resize(220, 60)
37 | self.btn.move(490, 700)
38 | # self.btn2.setFlat(True)
39 |
40 | self.timelabel = QLabel(self)
41 | self.timelabel.setGeometry(400, 200, 400, 100)
42 | self.timelabel.setAlignment(Qt.AlignCenter)
43 | self.timelabel.setFont(QFont("Roman times", 18))
44 | self.timer = QTimer(self)
45 |
46 | self.timer.timeout.connect(self.showTime)
47 | self.timer.start(1000)
48 |
49 | self.btn.clicked.connect(self.buttonClicked)
50 |
51 | def showTime(self):
52 | # 获取系统现在时间
53 | time = QDateTime.currentDateTime()
54 | # 设置系统时间显示格式
55 | timeDisplay = time.toString("yyyy-MM-dd hh:mm:ss dddd")
56 | # 在标签上显示时间
57 | self.timelabel.setText(timeDisplay)
58 |
59 | def buttonClicked(self):
60 | print('12')
61 | sender = self.sender()
62 | self.statusBar().showMessage(sender.text() + '被点击')
63 |
64 | if sender.text() == str('解锁'):
65 | self.timer.stop()
66 | self.faceon()
67 |
68 | def faceon(self):
69 | self.switch_window.emit(str('收银员'))
70 | # self.rewin = capture_distinguish.GUI("收银员")
71 | # self.rewin.show()
72 | self.close()
73 |
74 |
75 | def center(self):
76 | # 得到一个指定了主窗体形状的矩形
77 | qr = self.frameGeometry()
78 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
79 | cp = QDesktopWidget().availableGeometry().center()
80 | # 将矩形移动到屏幕中心
81 | qr.moveCenter(cp)
82 | # 窗体的左上角移动到矩形qr的左上角
83 | self.move(qr.topLeft())
84 |
85 |
86 | def paintEvent(self, event):
87 | username = self.user + ' 收银员临时离开'
88 |
89 | painter = QPainter(self)
90 | pixmap = QPixmap('E:\\py project\\FaceRecognition\\background1.jpeg')
91 |
92 | self.user_name.setText(username)
93 | self.user_name.setScaledContents(True)
94 |
95 | self.timelabel.setScaledContents(True)
96 | painter.drawPixmap(self.rect(), pixmap)
97 |
98 |
99 | if __name__ == '__main__':
100 | app = QApplication(sys.argv)
101 | page = CashierConsole()
102 | page.show()
103 | sys.exit(app.exec_())
104 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierWork/views.py:
--------------------------------------------------------------------------------
1 | from django.shortcuts import render, get_object_or_404
2 | import json
3 | import random
4 |
5 | import datetime
6 |
7 | from django.shortcuts import render
8 | from django.http import HttpResponse
9 | from .models import *
10 | from django.core.paginator import Paginator, EmptyPage, PageNotAnInteger
11 | # Create your views here.
12 | class DateEncoder(json.JSONEncoder):
13 | def default(self, obj):
14 | if isinstance(obj, datetime.datetime):
15 | return obj.strftime('%Y-%m-%d %H:%M:%S')
16 | elif isinstance(obj, datetime.date):
17 | return obj.strftime("%Y-%m-%d")
18 | elif isinstance(obj, datetime.time):
19 | return obj.strftime("%H:%M:%S")
20 | else:
21 | return json.JSONEncoder.default(self, obj)
22 |
23 |
24 | def findall(request):
25 | if request.method == 'GET':
26 | result = WorkDate.objects.all()
27 | print(result[0].name)
28 | arr = []
29 | for i in result:
30 | content = ({"id": i.name_id, "name": i.name, "firsttime": i.firsttime,
31 | "lasttime": i.lasttime, "date": i.date})
32 | print(type(content))
33 | arr.append(content)
34 |
35 | print(json.dumps(arr, cls=DateEncoder))
36 | # print(type(json.dumps(arr)))
37 | return HttpResponse(json.dumps(arr, cls=DateEncoder))
38 |
39 |
40 | def find(request):
41 | if request.method == 'GET':
42 | id = request.GET['id']
43 | result = WorkDate.objects.filter(name_id=id)
44 | arr = []
45 | for i in result:
46 | content = ({"id": i.name_id, "name": i.name, "firsttime": i.firsttime,
47 | "lasttime": i.lasttime, "date": i.date})
48 | print(type(content))
49 | arr.append(content)
50 |
51 | print(json.dumps(arr, cls=DateEncoder))
52 | # print(type(json.dumps(arr)))
53 | return HttpResponse(json.dumps(arr, cls=DateEncoder))
54 |
55 |
56 |
57 |
58 |
59 | def wxAdSign(request):
60 | if request.method == 'GET':
61 | id = request.GET['id']
62 | password = request.GET['password']
63 | result = AdminDate.objects.filter(id=id)
64 | if len(result) != 0:
65 | if result[0].password == ' ' + password:
66 | return HttpResponse(json.dumps({'name': result[0].name, 'code': 'True'}))
67 | else:
68 | return HttpResponse(json.dumps({'name': '', 'code': 'False'}))
69 | else:
70 | return HttpResponse(json.dumps({'name': '', 'code': 'False'}))
71 |
72 |
73 | def wxCaSign(request):
74 | if request.method == 'GET':
75 | id = request.GET['id']
76 | password = request.GET['password']
77 | result = CashierDate.objects.filter(id=id)
78 | if len(result) != 0:
79 | if result[0].password == ' ' + password:
80 | return HttpResponse(json.dumps({'name': result[0].name, 'code': 'True'}))
81 | else:
82 | return HttpResponse(json.dumps({'name': '', 'code': 'False'}))
83 | else:
84 | return HttpResponse(json.dumps({'name': '', 'code': 'False'}))
85 |
86 |
87 | def post(request):
88 | if request.method == 'GET':
89 | return render(request, 'post.html')
90 | elif request.method == 'POST':
91 | id = request.POST.get('id', '')
92 | # 查询name = tom1的数据
93 | result = WorkDate.objects.filter(name_id=id)
94 | """
95 | result为的对象
96 | 需要进行数据处理
97 | """
98 | arr = []
99 | for i in result:
100 | content = {'工号': i.name_id, '姓名': i.name, '工作开始时间': i.firsttime,
101 | '工作结束时间': i.lasttime, '日期': i.date}
102 | arr.append(content)
103 | print(arr)
104 | print(type(arr))
105 | return HttpResponse(arr)
106 |
107 |
--------------------------------------------------------------------------------
/recognition_back-end/CashierManagement/CashierManagement/settings.py:
--------------------------------------------------------------------------------
1 | """
2 | Django settings for CashierManagement project.
3 |
4 | Generated by 'django-admin startproject' using Django 3.1.4.
5 |
6 | For more information on this file, see
7 | https://docs.djangoproject.com/en/3.1/topics/settings/
8 |
9 | For the full list of settings and their values, see
10 | https://docs.djangoproject.com/en/3.1/ref/settings/
11 | """
12 |
13 | from pathlib import Path
14 | import os
15 |
16 | # Build paths inside the project like this: BASE_DIR / 'subdir'.
17 | BASE_DIR = Path(__file__).resolve().parent.parent
18 |
19 |
20 | # Quick-start development settings - unsuitable for production
21 | # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
22 |
23 | # SECURITY WARNING: keep the secret key used in production secret!
24 | SECRET_KEY = 'q=*0%25w9u9+)5=^$520v#k3n2ni1b_yy4r8sqqf68pz4&%v0%'
25 |
26 | # SECURITY WARNING: don't run with debug turned on in production!
27 | DEBUG = True
28 |
29 | ALLOWED_HOSTS = []
30 |
31 |
32 | # Application definition
33 |
34 | INSTALLED_APPS = [
35 | 'django.contrib.admin',
36 | 'django.contrib.auth',
37 | 'django.contrib.contenttypes',
38 | 'django.contrib.sessions',
39 | 'django.contrib.messages',
40 | 'django.contrib.staticfiles',
41 | 'CashierWork',
42 | 'werkzeug_debugger_runserver',
43 | 'django_extensions',
44 | ]
45 |
46 | MIDDLEWARE = [
47 | 'django.middleware.security.SecurityMiddleware',
48 | 'django.contrib.sessions.middleware.SessionMiddleware',
49 | 'django.middleware.common.CommonMiddleware',
50 | 'django.middleware.csrf.CsrfViewMiddleware',
51 | 'django.contrib.auth.middleware.AuthenticationMiddleware',
52 | 'django.contrib.messages.middleware.MessageMiddleware',
53 | 'django.middleware.clickjacking.XFrameOptionsMiddleware',
54 | ]
55 |
56 | ROOT_URLCONF = 'CashierManagement.urls'
57 |
58 | TEMPLATES = [
59 | {
60 | 'BACKEND': 'django.template.backends.django.DjangoTemplates',
61 | 'DIRS': [os.path.join(BASE_DIR, 'templates'), ],
62 | 'APP_DIRS': True,
63 | 'OPTIONS': {
64 | 'context_processors': [
65 | 'django.template.context_processors.debug',
66 | 'django.template.context_processors.request',
67 | 'django.contrib.auth.context_processors.auth',
68 | 'django.contrib.messages.context_processors.messages',
69 | ],
70 | },
71 | },
72 | ]
73 |
74 | WSGI_APPLICATION = 'CashierManagement.wsgi.application'
75 |
76 |
77 | # Database
78 | # https://docs.djangoproject.com/en/3.1/ref/settings/#databases
79 |
80 | DATABASES = {
81 | 'default': {
82 | 'ENGINE': 'django.db.backends.mysql',
83 | 'NAME': 'cashier_management',
84 | 'USER': 'root',
85 | 'PASSWORD': 'root',
86 | 'HOST': '127.0.0.1',
87 | 'PORT': '3306',
88 | }
89 | }
90 |
91 |
92 | # Password validation
93 | # https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
94 |
95 | AUTH_PASSWORD_VALIDATORS = [
96 | {
97 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
98 | },
99 | {
100 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
101 | },
102 | {
103 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
104 | },
105 | {
106 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
107 | },
108 | ]
109 |
110 |
111 | # Internationalization
112 | # https://docs.djangoproject.com/en/3.1/topics/i18n/
113 |
114 | # LANGUAGE_CODE = 'en-us'
115 | LANGUAGE_CODE = 'zh-hans' # 语言设置中文
116 |
117 | TIME_ZONE = 'Asia/Shanghai' # 时区亚洲上海
118 |
119 | USE_I18N = True
120 |
121 | USE_L10N = True
122 |
123 | USE_TZ = True
124 |
125 |
126 | # Static files (CSS, JavaScript, Images)
127 | # https://docs.djangoproject.com/en/3.1/howto/static-files/
128 |
129 | STATIC_URL = '/static/'
130 |
--------------------------------------------------------------------------------
/Cashier_management/capturetest.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import cv2
3 | import numpy as np
4 |
5 | from PIL import ImageQt, Image
6 | from PyQt5.QtWidgets import *
7 | from PyQt5.QtGui import *
8 | from PyQt5 import QtCore
9 | from PyQt5.QtCore import QTimer, Qt, QPoint
10 |
11 | from FileDrawRect.MyLabel import MyLabel
12 |
13 | class Video(object):
14 | def __init__(self, capture):
15 | self.capture = capture
16 | self.currentFrame = np.array([])
17 |
18 | def captureFrame(self):
19 | ret, frame =self.capture.read()
20 | return frame
21 |
22 | def captureNextFrame(self):
23 | ret, frame =self.capture.read()
24 | if ret is True:
25 | self.currentFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
26 |
27 | def convertFrame(self):
28 | try:
29 | height, width = self.currentFrame.shape[:2]
30 | img = QImage(self.currentFrame,
31 | width,
32 | height,
33 | QImage.Format_RGB888)
34 | img = QPixmap.fromImage(img)
35 |
36 | # self.previousFrame = self.currentFrame
37 | return img
38 | except:
39 | return None
40 |
41 |
42 | class GUI(QMainWindow):
43 | def __init__(self):
44 | super().__init__()
45 | self.Face_Cascade = cv2.CascadeClassifier(
46 | r'E:\\anaconda\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_alt2.xml')
47 | self.recognizer = cv2.face.LBPHFaceRecognizer_create()
48 | self.recognizer.read(r'E:\\py project\\FaceRecognition\\trainer\\trainer.yml')
49 |
50 | self.setGeometry(250, 80, 800, 600)
51 | self.setWindowTitle('人脸识别')
52 | self.video = Video(cv2.VideoCapture(0, cv2.CAP_DSHOW))
53 | self._timer = QTimer(self)
54 | self._timer.timeout.connect(self.play)
55 | self._timer.start(27)
56 | self.update()
57 | self.videoFrame = MyLabel("摄像头准备中,请稍后......")
58 | self.videoFrame.setAlignment(Qt.AlignCenter)
59 | self.setCentralWidget(self.videoFrame)
60 |
61 | self.ret, self.frame = self.video.capture.read()
62 |
63 | def play(self):
64 | try:
65 | self.video.captureNextFrame()
66 | self.videoFrame.drawingPermission(True)
67 | self.videoFrame.initDrawing(self.video.convertFrame())
68 |
69 | faces = self.Face_Cascade.detectMultiScale(self.video.currentFrame, minSize=(120, 120))
70 | for (x, y, w, h) in faces:
71 | # idnum, confidence = self.recognizer.predict(self.video.currentFrame[x: x + w,y: y + h])
72 | # cv2.waitKey(100)
73 | # print(idnum)
74 |
75 | self.videoFrame.drawRect(QPoint(x, y), QPoint(x + w, y + h))
76 |
77 | self.videoFrame.drawRect(QPoint(0, 0), QPoint(0, 0))
78 | self.videoFrame.setScaledContents(True)
79 |
80 | except TypeError:
81 | print('No Frame')
82 |
83 | def transImg(self, img):
84 | img = img.resize((self.label.width(), self.label.height()))
85 | return ImageQt.toqpixmap(img)
86 |
87 | def SHOW(self):
88 | self.show()
89 |
90 | def closeEvent(self, event):
91 | event.accept()
92 | cv2.VideoCapture(0, cv2.CAP_DSHOW).release()
93 | # cv2.destroyAllWindows()
94 |
95 | # def faceGet(self):
96 | # self.recognizer.read('E:\\py project\\FaceRecognition\\trainer\\trainer.yml')
97 | #
98 | # ret, frame = self.video.capture.read()
99 | # gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
100 | # faces = self.Face_Cascade.detectMultiScale(gray, minSize=(120, 120))
101 | #
102 | # return faces
103 | #
104 | # for (x, y, w, h) in faces:
105 | # cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
106 | # idnum, confidence = self.recognizer.predict(gray[y:y + h, x:x + w])
107 | # #
108 | # if confidence < 50:
109 | # name = 'ltw' + str(idnum)
110 | # Error = "{0}%".format(round(100 - confidence))
111 | # else:
112 | # name = 'unknown'
113 | # Error = "{0}%".format(round(confidence))
114 |
115 |
116 | if __name__ == "__main__":
117 | QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
118 |
119 | app = QApplication(sys.argv)
120 | ex = GUI()
121 | ex.show()
122 | sys.exit(app.exec_())
123 |
--------------------------------------------------------------------------------
/Cashier_management/home_page.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QtWidgets import *
2 | from PyQt5.QtGui import *
3 | from PyQt5 import QtCore
4 | # from gevent.libev.corecext import SIGNAL, time
5 |
6 | import sys
7 |
8 | from Cashier_management import capture_distinguish
9 |
10 |
11 | class HomePage(QMainWindow):
12 | switch_window = QtCore.pyqtSignal(str)
13 |
14 | def __init__(self):
15 | super(HomePage, self).__init__()
16 | self.init_ui()
17 |
18 | def init_ui(self):
19 | self.administratorsimage = QPixmap('E:\\py project\\FaceRecognition\\administrators.jpeg')
20 | self.userimage = QPixmap('E:\\py project\\FaceRecognition\\user.jpeg')
21 |
22 | self.statusBar().showMessage('Ready')
23 | self.setWindowTitle('首页')
24 | self.setWindowIcon(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'))
25 | # 窗体大小
26 | self.resize(1200, 900)
27 | # 窗体居中
28 | self.center()
29 |
30 | # 创建菜单栏
31 | exitAction = QAction(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'), '&关闭', self)
32 | exitAction.setShortcut('Ctrl+Q')
33 | exitAction.setStatusTip('Exit application')
34 | # 菜单栏事件
35 | exitAction.triggered.connect(qApp.quit)
36 |
37 | # 创建菜单栏目录
38 | menu_bar = self.menuBar()
39 | fileMenu = menu_bar.addMenu('&File')
40 | fileMenu.addAction(exitAction)
41 |
42 | # 创建工具栏目录
43 | # toolbar = self.addToolBar('Exit')
44 | # toolbar.addAction(exitAction)
45 |
46 | # 这个静态方法为tooltip设置了10px的Sanserif字体
47 | # QToolTip.setFont(QFont('SansSerif', 10))
48 | # self.setToolTip('This is a QWidget widget')
49 | self.administrators_lab = QLabel(self)
50 | self.administrators_lab.setGeometry(120, 200, 300, 400)
51 |
52 | self.user_lab = QLabel(self)
53 | self.user_lab.setGeometry(720, 200, 300, 400)
54 |
55 | # col = QColor(0, 0, 0)
56 | # self.frm = QFrame(self)
57 | # self.frm.setStyleSheet("QWidget { background-color: %s }"
58 | # % col.name())
59 |
60 | # self.frm.setGeometry(160, 200, 200, 200)
61 |
62 | self.btn1 = QPushButton('管理员', self)
63 | self.btn1.setToolTip('管理员登录!')
64 | self.btn1.resize(220, 60)
65 | self.btn1.move(160, 700)
66 |
67 | # layout = QGridLayout(self)
68 | btn2 = QPushButton('收银员', self)
69 | btn2.setToolTip('收银员登录!')
70 | btn2.resize(220, 60)
71 | btn2.move(760, 700)
72 |
73 | self.btn1.clicked.connect(self.buttonClicked)
74 | # btn1.clicked.connect(self.sign_in())
75 | btn2.clicked.connect(self.buttonClicked)
76 |
77 | # def sign_in(self):
78 | #
79 | # fr = FaceRecognition()
80 | # fr.RecognitionFace()
81 |
82 | def buttonClicked(self):
83 |
84 | username = '收银员'
85 | administratorsname = '管理员'
86 |
87 | sender = self.sender()
88 | self.statusBar().showMessage(sender.text() + '被点击')
89 |
90 | self.onclick(sender.text())
91 |
92 | # if sender.text() == str(administratorsname):
93 | # self.admin()
94 |
95 | def onclick(self, user):
96 | # self.newWindow = capture_distinguish.GUI(user)
97 | # self.newWindow.show()
98 |
99 | self.switch_window.emit(user)
100 |
101 | def center(self):
102 | # 得到一个指定了主窗体形状的矩形
103 | qr = self.frameGeometry()
104 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
105 | cp = QDesktopWidget().availableGeometry().center()
106 | # 将矩形移动到屏幕中心
107 | qr.moveCenter(cp)
108 | # 窗体的左上角移动到矩形qr的左上角
109 | self.move(qr.topLeft())
110 |
111 | def closeEvent(self, event):
112 | reply = QMessageBox.question(self, 'Message',
113 | "Are you sure to quit?", QMessageBox.Yes |
114 | QMessageBox.No, QMessageBox.No)
115 |
116 | if reply == QMessageBox.Yes:
117 | event.accept()
118 | else:
119 | event.ignore()
120 |
121 | def paintEvent(self, event):
122 |
123 | painter = QPainter(self)
124 | pixmap = QPixmap('E:\\py project\\FaceRecognition\\background.jpeg')
125 |
126 | self.administrators_lab.setPixmap(self.administratorsimage)
127 | self.administrators_lab.setScaledContents(True)
128 | self.user_lab.setPixmap(self.userimage)
129 | self.user_lab.setScaledContents(True)
130 | painter.drawPixmap(self.rect(), pixmap)
131 |
132 |
133 | if __name__ == '__main__':
134 | app = QApplication(sys.argv)
135 | page = HomePage()
136 | page.show()
137 | sys.exit(app.exec_())
138 |
--------------------------------------------------------------------------------
/Cashier_management/administrators_console.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QtWidgets import *
2 | from PyQt5.QtGui import *
3 | from PyQt5.QtCore import Qt, QTimer, QDateTime
4 | from PyQt5 import QtCore
5 |
6 | import sys
7 |
8 | from Cashier_management import administreators_datalab, cashier_datalab, cashier_work
9 |
10 |
11 | class CashierConsole(QMainWindow):
12 | cashwork_window = QtCore.pyqtSignal()
13 | cash_window = QtCore.pyqtSignal()
14 | admin_window = QtCore.pyqtSignal()
15 |
16 | def __init__(self, user):
17 | super().__init__()
18 | self.user = user
19 | self.init_ui()
20 |
21 | def init_ui(self):
22 | self.userimage = QPixmap('E:\\py project\\FaceRecognition\\user.jpeg')
23 |
24 | self.statusBar().showMessage('Ready')
25 | self.setWindowTitle('管理员控制台')
26 | self.setWindowIcon(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'))
27 | # 窗体大小
28 | self.resize(1200, 900)
29 | # 窗体居中
30 | self.center()
31 |
32 | # # 创建菜单栏
33 | # exitAction = QAction(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'), '&关闭', self)
34 | # exitAction.setShortcut('Ctrl+Q')
35 | # exitAction.setStatusTip('Exit application')
36 | # # 菜单栏事件
37 | # exitAction.triggered.connect(qApp.quit)
38 | #
39 | # # 创建菜单栏目录
40 | # menu_bar = self.menuBar()
41 | # fileMenu = menu_bar.addMenu('&File')
42 | # fileMenu.addAction(exitAction)
43 |
44 | self.user_name = QLabel(self)
45 | self.user_name.setAlignment(Qt.AlignCenter)
46 | self.user_name.setFont(QFont("Roman times", 18))
47 | self.user_name.setGeometry(400, 50, 400, 100)
48 |
49 | self.user_lab = QLabel(self)
50 | self.user_lab.setGeometry(220, 320, 300, 400)
51 |
52 | self.btn1 = QPushButton('收银员工作情况', self)
53 | self.btn1.setToolTip('检查收银员的工作情况')
54 | self.btn1.resize(220, 60)
55 | self.btn1.move(760, 500)
56 |
57 | self.btn2 = QPushButton('收银员人员管理', self)
58 | self.btn2.setToolTip('收银员的人员情况、注册、修改以及删除')
59 | self.btn2.resize(220, 60)
60 | self.btn2.move(760, 700)
61 |
62 | self.btn3 = QPushButton('管理员人员管理', self)
63 | self.btn3.setToolTip('管理员的人员情况、注册、修改以及删除')
64 | self.btn3.resize(220, 60)
65 | self.btn3.move(760, 300)
66 |
67 | self.timelabel = QLabel(self)
68 | self.timelabel.setGeometry(760, 200, 220, 60)
69 | self.timer = QTimer(self)
70 | self.timer.timeout.connect(self.showTime)
71 | self.timer.start(1000)
72 |
73 | self.btn1.clicked.connect(self.buttonClicked)
74 | self.btn2.clicked.connect(self.buttonClicked)
75 | self.btn3.clicked.connect(self.buttonClicked)
76 |
77 | def showTime(self):
78 | # 获取系统现在时间
79 | time = QDateTime.currentDateTime()
80 | # 设置系统时间显示格式
81 | timeDisplay = time.toString("yyyy-MM-dd hh:mm:ss dddd")
82 | # 在标签上显示时间
83 | self.timelabel.setText(timeDisplay)
84 |
85 |
86 | def buttonClicked(self):
87 |
88 | sender = self.sender()
89 | self.statusBar().showMessage(sender.text() + '被点击')
90 |
91 | if sender.text() == str('管理员人员管理'):
92 | self.onadmin()
93 | # self.close()
94 | elif sender.text() == str('收银员人员管理'):
95 | self.oncashier()
96 | elif sender.text() == str('收银员工作情况'):
97 | self.oncashwork()
98 |
99 | def oncashwork(self):
100 | # self.cashworkwin = cashier_work.DataLab()
101 | # self.cashworkwin.show()
102 | self.cashwork_window.emit()
103 |
104 | def oncashier(self):
105 | # self.cashwin = cashier_datalab.DataLab()
106 | # self.cashwin.show()
107 | self.cash_window.emit()
108 |
109 | def onadmin(self):
110 | # self.adminWindow = administreators_datalab.DataLab()
111 | # self.adminWindow.show()
112 | self.admin_window.emit()
113 |
114 |
115 | def center(self):
116 | # 得到一个指定了主窗体形状的矩形
117 | qr = self.frameGeometry()
118 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
119 | cp = QDesktopWidget().availableGeometry().center()
120 | # 将矩形移动到屏幕中心
121 | qr.moveCenter(cp)
122 | # 窗体的左上角移动到矩形qr的左上角
123 | self.move(qr.topLeft())
124 |
125 |
126 | def paintEvent(self, event):
127 | username = self.user + ' 欢迎使用管理员控制台'
128 |
129 | painter = QPainter(self)
130 | pixmap = QPixmap('E:\\py project\\FaceRecognition\\background1.jpeg')
131 |
132 | self.user_lab.setPixmap(self.userimage)
133 | self.user_lab.setScaledContents(True)
134 |
135 | self.user_name.setText(username)
136 | self.user_name.setScaledContents(True)
137 | painter.drawPixmap(self.rect(), pixmap)
138 |
139 |
140 | if __name__ == '__main__':
141 | app = QApplication(sys.argv)
142 | page = CashierConsole('ltw')
143 | page.show()
144 | sys.exit(app.exec_())
145 |
--------------------------------------------------------------------------------
/Cashier_management/cashier_work.py:
--------------------------------------------------------------------------------
1 | from functools import partial
2 | from PyQt5.QtGui import QFont, QIcon
3 | from PyQt5.QtWidgets import (QWidget, QMainWindow, QLabel, QFrame, QApplication,
4 | QTableWidgetItem, QPushButton, QLineEdit, QInputDialog,
5 | QDesktopWidget, QTableWidget)
6 | from PyQt5.QtCore import Qt, QCoreApplication
7 | from PyQt5 import QtCore
8 |
9 | import pymysql
10 | import sys
11 | import datetime
12 |
13 |
14 | class DataLab(QMainWindow):
15 | switch_window = QtCore.pyqtSignal()
16 |
17 | def __init__(self):
18 | super(DataLab, self).__init__()
19 | self.init_ui()
20 |
21 | def init_ui(self):
22 |
23 | self.statusBar().showMessage('Ready')
24 | self.setWindowTitle('收银员工作情况查询')
25 | self.setWindowIcon(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'))
26 | # 窗体大小
27 | self.resize(1200, 900)
28 | # 窗体居中
29 | self.center()
30 |
31 | self.user_name = QLabel(self)
32 | self.user_name.setAlignment(Qt.AlignCenter)
33 | self.user_name.setFont(QFont("Roman times", 18))
34 | self.user_name.setGeometry(400, 0, 400, 100)
35 | self.user_name.setText('欢迎查看收银员工作情况')
36 | self.user_name.setScaledContents(True)
37 |
38 | # 数据库初始化
39 | self.connect_sql()
40 |
41 | # 插入表格
42 | self.MyTable = QTableWidget(self.row, self.vol, self)
43 | font = QFont('微软雅黑', 10)
44 | self.MyTable.setGeometry(0, 100, 1200, 700)
45 |
46 | # 设置字体、表头
47 | self.MyTable.horizontalHeader().setFont(font)
48 | self.MyTable.setHorizontalHeaderLabels(self.col_lst)
49 | # 设置竖直方向表头不可见
50 | self.MyTable.verticalHeader().setVisible(False)
51 | self.MyTable.setFrameShape(QFrame.NoFrame)
52 |
53 | self.data_set()
54 |
55 | self.btn1 = QPushButton('刷新', self)
56 | self.btn1.setToolTip('数据刷新')
57 | self.btn1.resize(220, 60)
58 | self.btn1.move(960, 820)
59 |
60 | self.btn2 = QPushButton('删除收银员记录', self)
61 | self.btn2.setToolTip('收银员记录删除')
62 | self.btn2.resize(220, 60)
63 | self.btn2.move(720, 820)
64 |
65 | self.btn1.clicked.connect(self.buttonClicked)
66 | self.btn2.clicked.connect(self.buttonClicked)
67 |
68 | def buttonClicked(self):
69 |
70 | sender = self.sender()
71 | self.statusBar().showMessage(sender.text() + '被点击')
72 |
73 | if sender.text() == str('刷新'):
74 | self.nowwin = DataLab()
75 | self.nowwin.show()
76 | self.close()
77 | elif sender.text() == str('删除收银员记录'):
78 | value, ok = QInputDialog.getText(self, "删除收银员记录", "请输入你要删除记录的收银员id:")
79 | self.del_date(value)
80 |
81 | def data_set(self):
82 | # 数据插入
83 | for i in range(self.row):
84 | for j in range(self.vol):
85 | temp_data = self.data[i][j] # 临时记录,不能直接插入表格
86 | data1 = QTableWidgetItem(str(temp_data)) # 转换后可插入表格
87 | self.MyTable.setItem(i, j, data1)
88 |
89 | def connect_sql(self):
90 |
91 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
92 | database='cashier_management', port=3306,
93 | charset='utf8')
94 | # 得到一个可以执行SQL语句的光标对象
95 | cursor = conn.cursor()
96 | # 定义要执行的SQL语句
97 | cursor.execute('select * from cashierwork')
98 | self.data = cursor.fetchall()
99 |
100 | # 数据列名
101 | self.col_lst = [tup[0] for tup in cursor.description]
102 |
103 | # 数据大小
104 | if len(self.data) == 0:
105 | self.row = 0
106 | self.vol = 0
107 | else:
108 | self.row = len(self.data)
109 | self.vol = len(self.data[0])
110 |
111 |
112 | # 关闭光标对象
113 | cursor.close()
114 | # 关闭数据库连接
115 | conn.close()
116 |
117 | def del_date(self, id):
118 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
119 | database='cashier_management', port=3306,
120 | charset='utf8')
121 |
122 | sql_delete = "DELETE FROM cashierwork WHERE id = %d;" \
123 | % int(id)
124 | cursor = conn.cursor()
125 | # 定义要执行的SQL语
126 | sql = cursor.execute(sql_delete)
127 | conn.commit()
128 |
129 | # 关闭光标对象
130 | cursor.close()
131 | # 关闭数据库连接
132 | conn.close()
133 |
134 | def center(self):
135 | # 得到一个指定了主窗体形状的矩形
136 | qr = self.frameGeometry()
137 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
138 | cp = QDesktopWidget().availableGeometry().center()
139 | # 将矩形移动到屏幕中心
140 | qr.moveCenter(cp)
141 | # 窗体的左上角移动到矩形qr的左上角
142 | self.move(qr.topLeft())
143 |
144 |
145 | if __name__ == '__main__':
146 | app = QApplication(sys.argv)
147 | page = DataLab()
148 | page.show()
149 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/Cashier_management/admin_FaceCollect.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import cv2
3 | import numpy as np
4 | import face_recognition
5 | import pymysql
6 |
7 | from PIL import ImageQt, Image
8 | from PyQt5.QtWidgets import *
9 | from PyQt5.QtGui import *
10 | from PyQt5 import QtCore
11 | from PyQt5.QtCore import QTimer, Qt, QPoint
12 |
13 | from FileDrawRect.MyLabel import MyLabel
14 |
15 | class Video(object):
16 | def __init__(self, capture):
17 | self.capture = capture
18 | self.currentFrame = np.array([])
19 |
20 | def captureFrame(self):
21 | ret, frame =self.capture.read()
22 | return frame
23 |
24 | def captureNextFrame(self):
25 | ret, frame =self.capture.read()
26 | if ret is True:
27 | self.currentFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
28 |
29 | def convertFrame(self):
30 | try:
31 | height, width = self.currentFrame.shape[:2]
32 | img = QImage(self.currentFrame,
33 | width,
34 | height,
35 | QImage.Format_RGB888)
36 | img = QPixmap.fromImage(img)
37 |
38 |
39 | # self.previousFrame = self.currentFrame
40 | return img
41 | except:
42 | return None
43 |
44 |
45 | class GUI(QMainWindow):
46 | switch_window = QtCore.pyqtSignal()
47 |
48 | def __init__(self, name, id):
49 | super().__init__()
50 | self.name = name
51 | self.name_id = id
52 | self.Face_Cascade = cv2.CascadeClassifier(
53 | r'E:\\anaconda\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_alt2.xml')
54 | self.recognizer = cv2.face.LBPHFaceRecognizer_create()
55 | self.recognizer.read(r'E:\\py project\\FaceRecognition\\trainer\\trainer.yml')
56 |
57 | self.setGeometry(250, 80, 800, 600)
58 | self.setWindowTitle('人脸识别')
59 | self.video = Video(cv2.VideoCapture(0))
60 | self._timer = QTimer(self)
61 | self._timer.timeout.connect(self.play)
62 | self._timer.start(27)
63 | self.update()
64 |
65 | self.count = 0
66 |
67 | self.videoFrame = MyLabel("摄像头准备中,请稍后......")
68 | self.videoFrame.setAlignment(Qt.AlignCenter)
69 | self.setCentralWidget(self.videoFrame)
70 |
71 | self.ret, self.frame = self.video.capture.read()
72 |
73 | def play(self):
74 | self.video.captureNextFrame()
75 | self.videoFrame.drawingPermission(True)
76 | self.videoFrame.initDrawing(self.video.convertFrame())
77 |
78 | faces = self.Face_Cascade.detectMultiScale(self.video.currentFrame, minSize=(120, 120))
79 |
80 | for (x, y, w, h) in faces:
81 | # 人脸画框
82 | self.videoFrame.drawRect(QPoint(x, y), QPoint(x + w, y + h))
83 |
84 | # 返回图像中每个面的128维人脸编码
85 | # 图像中可能存在多张人脸,取下标为0的人脸编码,表示识别出来的最清晰的人脸
86 | if len(face_recognition.face_encodings(self.video.currentFrame)) != 0:
87 | image_face_encoding = face_recognition.face_encodings(self.video.currentFrame)[0]
88 | # print(np.shape(image_face_encoding))
89 |
90 | # 将numpy array类型转化为列表
91 | encoding__array_list = image_face_encoding.tolist()
92 |
93 | # 将列表里的元素转化为字符串
94 | encoding_str_list = [str(i) for i in encoding__array_list]
95 |
96 | # 拼接列表里的字符串
97 | encoding_str = ','.join(encoding_str_list)
98 |
99 | print(encoding_str)
100 |
101 | self.save_encoding(encoding_str, self.name, self.name_id)
102 | self.count = self.count + 1
103 |
104 | if self.count >= 10:
105 | self.close()
106 | self._timer.stop()
107 |
108 | print(self.count)
109 |
110 |
111 | self.videoFrame.drawRect(QPoint(0, 0), QPoint(0, 0))
112 | self.videoFrame.setScaledContents(True)
113 |
114 |
115 | # 人脸特征信息保存
116 | def save_encoding(self, encoding_str, name, id):
117 | # 创建数据库连接对象
118 | conn = pymysql.connect(
119 | # 数据库的IP地址
120 | host="139.9.105.107",
121 | # 数据库用户名称
122 | user="root",
123 | # 数据库用户密码
124 | password="wzr152wzrA",
125 | # 数据库名称
126 | db="cashier_management",
127 | # 数据库端口名称
128 | port=3306,
129 | # 数据库的编码方式 注意是utf8
130 | charset="utf8"
131 | )
132 |
133 | # 使用 cursor() 方法创建一个游标对象 cursor
134 | cursor = conn.cursor()
135 |
136 | # SQL插入语句
137 | insert_sql = "insert into admin_face(name_id,name,encoding) values(%d,%s,%s)"
138 | try:
139 | # 执行sql语句
140 | cursor.execute(insert_sql % (int(id), "'"+name+"'", "'"+encoding_str+"'"))
141 | # 提交到数据库执行
142 | conn.commit()
143 | except Exception as e:
144 | # 如果发生错误则回滚并打印错误信息
145 | conn.rollback()
146 | print(e)
147 |
148 | # 关闭游标
149 | cursor.close()
150 | # 关闭数据库连接
151 | conn.close()
152 |
153 | def transImg(self, img):
154 | img = img.resize((self.label.width(), self.label.height()))
155 | return ImageQt.toqpixmap(img)
156 |
157 | def SHOW(self):
158 | self.show()
159 |
160 | def closeEvent(self, event):
161 | event.accept()
162 | cv2.VideoCapture(0, cv2.CAP_DSHOW).release()
163 |
164 |
165 | if __name__ == "__main__":
166 | QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
167 |
168 | app = QApplication(sys.argv)
169 | ex = GUI('ltw','123')
170 | ex.show()
171 | sys.exit(app.exec_())
172 |
--------------------------------------------------------------------------------
/Cashier_management/cashier_FaceCollect.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import cv2
3 | import numpy as np
4 | import face_recognition
5 | import pymysql
6 |
7 | from PIL import ImageQt, Image
8 | from PyQt5.QtWidgets import *
9 | from PyQt5.QtGui import *
10 | from PyQt5 import QtCore
11 | from PyQt5.QtCore import QTimer, Qt, QPoint
12 |
13 | from FileDrawRect.MyLabel import MyLabel
14 |
15 | class Video(object):
16 | def __init__(self, capture):
17 | self.capture = capture
18 | self.currentFrame = np.array([])
19 |
20 | def captureFrame(self):
21 | ret, frame =self.capture.read()
22 | return frame
23 |
24 | def captureNextFrame(self):
25 | ret, frame =self.capture.read()
26 | if ret is True:
27 | self.currentFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
28 |
29 | def convertFrame(self):
30 | try:
31 | height, width = self.currentFrame.shape[:2]
32 | img = QImage(self.currentFrame,
33 | width,
34 | height,
35 | QImage.Format_RGB888)
36 | img = QPixmap.fromImage(img)
37 |
38 |
39 | # self.previousFrame = self.currentFrame
40 | return img
41 | except:
42 | return None
43 |
44 |
45 | class GUI(QMainWindow):
46 | switch_window = QtCore.pyqtSignal()
47 |
48 | def __init__(self, name = 'ltw', id = 123):
49 | super().__init__()
50 | self.name = name
51 | self.name_id = id
52 | self.Face_Cascade = cv2.CascadeClassifier(
53 | r'E:\\anaconda\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_alt2.xml')
54 | self.recognizer = cv2.face.LBPHFaceRecognizer_create()
55 | self.recognizer.read(r'E:\\py project\\FaceRecognition\\trainer\\trainer.yml')
56 |
57 | self.setGeometry(250, 80, 800, 600)
58 | self.setWindowTitle('人脸识别')
59 | self.video = Video(cv2.VideoCapture(0))
60 | self._timer = QTimer(self)
61 | self._timer.timeout.connect(self.play)
62 | self._timer.start(27)
63 | self.update()
64 |
65 | self.count = 0
66 |
67 | self.videoFrame = MyLabel("摄像头准备中,请稍后......")
68 | self.videoFrame.setAlignment(Qt.AlignCenter)
69 | self.setCentralWidget(self.videoFrame)
70 |
71 | self.ret, self.frame = self.video.capture.read()
72 |
73 | def play(self):
74 | self.video.captureNextFrame()
75 | self.videoFrame.drawingPermission(True)
76 | self.videoFrame.initDrawing(self.video.convertFrame())
77 |
78 | faces = self.Face_Cascade.detectMultiScale(self.video.currentFrame, minSize=(120, 120))
79 |
80 | for (x, y, w, h) in faces:
81 | # 人脸画框
82 | self.videoFrame.drawRect(QPoint(x, y), QPoint(x + w, y + h))
83 |
84 | # 返回图像中每个面的128维人脸编码
85 | # 图像中可能存在多张人脸,取下标为0的人脸编码,表示识别出来的最清晰的人脸
86 | if len(face_recognition.face_encodings(self.video.currentFrame)) != 0:
87 | image_face_encoding = face_recognition.face_encodings(self.video.currentFrame)[0]
88 | # print(np.shape(image_face_encoding))
89 |
90 | # 将numpy array类型转化为列表
91 | encoding__array_list = image_face_encoding.tolist()
92 |
93 | # 将列表里的元素转化为字符串
94 | encoding_str_list = [str(i) for i in encoding__array_list]
95 |
96 | # 拼接列表里的字符串
97 | encoding_str = ','.join(encoding_str_list)
98 |
99 | print(encoding_str)
100 |
101 | self.save_encoding(encoding_str, self.name, self.name_id)
102 | self.count = self.count + 1
103 |
104 | if self.count >= 10:
105 | self.close()
106 | self._timer.stop()
107 |
108 | print(self.count)
109 |
110 |
111 | self.videoFrame.drawRect(QPoint(0, 0), QPoint(0, 0))
112 | self.videoFrame.setScaledContents(True)
113 |
114 |
115 | # 人脸特征信息保存
116 | def save_encoding(self, encoding_str, name, id):
117 | # 创建数据库连接对象
118 | conn = pymysql.connect(
119 | # 数据库的IP地址
120 | host="139.9.105.107",
121 | # 数据库用户名称
122 | user="root",
123 | # 数据库用户密码
124 | password="wzr152wzrA",
125 | # 数据库名称
126 | db="cashier_management",
127 | # 数据库端口名称
128 | port=3306,
129 | # 数据库的编码方式 注意是utf8
130 | charset="utf8"
131 | )
132 |
133 | # 使用 cursor() 方法创建一个游标对象 cursor
134 | cursor = conn.cursor()
135 |
136 | # SQL插入语句
137 | insert_sql = "insert into cashier_face(name_id,name,encoding) values(%d,%s,%s)"
138 | try:
139 | # 执行sql语句
140 | cursor.execute(insert_sql % (int(id), "'"+name+"'", "'"+encoding_str+"'"))
141 | # 提交到数据库执行
142 | conn.commit()
143 | except Exception as e:
144 | # 如果发生错误则回滚并打印错误信息
145 | conn.rollback()
146 | print(e)
147 |
148 | # 关闭游标
149 | cursor.close()
150 | # 关闭数据库连接
151 | conn.close()
152 |
153 | def transImg(self, img):
154 | img = img.resize((self.label.width(), self.label.height()))
155 | return ImageQt.toqpixmap(img)
156 |
157 | def SHOW(self):
158 | self.show()
159 |
160 | def closeEvent(self, event):
161 | event.accept()
162 | cv2.VideoCapture(0, cv2.CAP_DSHOW).release()
163 |
164 |
165 | if __name__ == "__main__":
166 | QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
167 |
168 | app = QApplication(sys.argv)
169 | ex = GUI()
170 | ex.show()
171 | sys.exit(app.exec_())
172 |
--------------------------------------------------------------------------------
/Cashier_management/cashier_console.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QtWidgets import *
2 | from PyQt5.QtGui import *
3 | from PyQt5.QtCore import Qt, QTimer, QDateTime
4 | import serial
5 |
6 | import sys
7 | import pymysql
8 | import datetime as dt
9 | import time
10 | from PyQt5 import QtCore
11 |
12 | from Cashier_management import lock_on, home_page
13 |
14 |
15 | class CashierConsole(QMainWindow):
16 | lock_window = QtCore.pyqtSignal(str)
17 | home_window = QtCore.pyqtSignal()
18 |
19 | def __init__(self, user = 'qwe'):
20 | super(CashierConsole, self).__init__()
21 | self.user = user
22 | self.frist_time = time.strftime('%Y-%m-%d %H:%M:%S').split(' ')[1]
23 | print(self.frist_time)
24 | # 打开端口
25 | self.port = serial.Serial(port='COM4', baudrate=115200, bytesize=8, parity='E', stopbits=1, timeout=2)
26 | self.init_ui()
27 |
28 | def init_ui(self):
29 | self.port.write("close".encode("utf-8"))
30 | self.userimage = QPixmap('E:\\py project\\FaceRecognition\\user.jpeg')
31 |
32 | self.statusBar().showMessage('Ready')
33 | self.setWindowTitle('收银员控制台')
34 | self.setWindowIcon(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'))
35 | # 窗体大小
36 | self.resize(1200, 900)
37 | # 窗体居中
38 | self.center()
39 |
40 | # # 创建菜单栏
41 | # exitAction = QAction(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'), '&关闭', self)
42 | # exitAction.setShortcut('Ctrl+Q')
43 | # exitAction.setStatusTip('Exit application')
44 | # # 菜单栏事件
45 | # exitAction.triggered.connect(qApp.quit)
46 |
47 | # # 创建菜单栏目录
48 | # menu_bar = self.menuBar()
49 | # fileMenu = menu_bar.addMenu('&File')
50 | # fileMenu.addAction(exitAction)
51 |
52 | self.user_name = QLabel(self)
53 | self.user_name.setAlignment(Qt.AlignCenter)
54 | self.user_name.setFont(QFont("Roman times", 18))
55 | self.user_name.setGeometry(400, 50, 400, 100)
56 |
57 | self.user_lab = QLabel(self)
58 | self.user_lab.setGeometry(220, 250, 300, 400)
59 |
60 | self.btn1 = QPushButton('换班/收银员退出', self)
61 | self.btn1.setToolTip('收银员退出登录!')
62 | self.btn1.resize(220, 60)
63 | self.btn1.move(760, 400)
64 | # self.btn1.setFlat(True)
65 |
66 | self.btn2 = QPushButton('开锁', self)
67 | self.btn2.setToolTip('打开收银柜!')
68 | self.btn2.resize(220, 60)
69 | self.btn2.move(760, 550)
70 |
71 | self.btn3 = QPushButton('临时离开', self)
72 | self.btn3.setToolTip('收银员临时离开!')
73 | self.btn3.resize(220, 60)
74 | self.btn3.move(760, 700)
75 | # self.btn2.setFlat(True)
76 |
77 | self.timelabel = QLabel(self)
78 | self.timelabel.setGeometry(760, 300, 220, 60)
79 | self.timer = QTimer(self)
80 | self.timer.timeout.connect(self.showTime)
81 | self.timer.start(1000)
82 |
83 | self.btn1.clicked.connect(self.buttonClicked)
84 | # btn1.clicked.connect(self.sign_in())
85 | self.btn2.setShortcut('enter')
86 | self.btn2.clicked.connect(self.buttonClicked)
87 | self.btn3.clicked.connect(self.buttonClicked)
88 |
89 | def showTime(self):
90 | # 获取系统现在时间
91 | time = QDateTime.currentDateTime()
92 | # 设置系统时间显示格式
93 | timeDisplay = time.toString("yyyy-MM-dd hh:mm:ss dddd")
94 | # 在标签上显示时间
95 | self.timelabel.setText(timeDisplay)
96 |
97 |
98 | def buttonClicked(self):
99 |
100 | sender = self.sender()
101 | self.statusBar().showMessage(sender.text() + '被点击')
102 |
103 | if sender.text() == str('临时离开'):
104 | self.timer.stop()
105 | self.last_time = time.strftime('%Y-%m-%d %H:%M:%S').split(' ')[1]
106 | print(self.last_time)
107 | self.port.write("open".encode("utf-8"))
108 | self.save_work()
109 | self.port.close()
110 | self.onlock()
111 | # self.close()
112 | elif sender.text() == str('换班/收银员退出'):
113 | self.timer.stop()
114 | self.last_time = time.strftime('%Y-%m-%d %H:%M:%S').split(' ')[1]
115 | self.port.write("open".encode("utf-8"))
116 | self.save_work()
117 | self.port.close()
118 | self.onhome()
119 | # self.close()
120 | elif sender.text() == str('开锁'):
121 | print('lock_on')
122 | self.port.write("lockon".encode("utf-8"))
123 | # self.port.close()
124 |
125 | def onlock(self):
126 | # self.newWindow = lock_on.CashierConsole()
127 | # self.newWindow.show()
128 | self.lock_window.emit(self.user)
129 |
130 | def onhome(self):
131 | # self.homewin = home_page.HomePage()
132 | # self.homewin.show()
133 | self.home_window.emit()
134 | self.close()
135 |
136 | def center(self):
137 | # 得到一个指定了主窗体形状的矩形
138 | qr = self.frameGeometry()
139 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
140 | cp = QDesktopWidget().availableGeometry().center()
141 | # 将矩形移动到屏幕中心
142 | qr.moveCenter(cp)
143 | # 窗体的左上角移动到矩形qr的左上角
144 | self.move(qr.topLeft())
145 |
146 |
147 | def paintEvent(self, event):
148 | username = self.user + ' 欢迎使用收银控制台'
149 |
150 | painter = QPainter(self)
151 | pixmap = QPixmap('E:\\py project\\FaceRecognition\\background1.jpeg')
152 |
153 | self.user_lab.setPixmap(self.userimage)
154 | self.user_lab.setScaledContents(True)
155 |
156 | self.user_name.setText(username)
157 | self.user_name.setScaledContents(True)
158 | painter.drawPixmap(self.rect(), pixmap)
159 |
160 | def save_work(self):
161 | # 连接database
162 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
163 | database='cashier_management', port=3306,
164 | charset='utf8')
165 |
166 | # 得到一个可以执行SQL语句的光标对象
167 | cursor = conn.cursor()
168 | print(self.user)
169 | sql_select = "SELECT id FROM cashier where name=%s;" % ("'"+self.user+"'")
170 | cursor.execute(sql_select)
171 | self.name_id = cursor.fetchone()[0]
172 | print(self.name_id)
173 | sql_insert = "INSERT INTO cashierwork(name_id,name,firsttime,lasttime,date)" \
174 | " VALUES (%d,%s,%s,%s,%s);" \
175 | % (int(self.name_id), "'"+self.user+"'", "'"+self.frist_time+"'",
176 | "'"+self.last_time+"'", dt.date.today().strftime('"%Y-%m-%d"'))
177 |
178 | cursor.execute(sql_insert)
179 | conn.commit()
180 | # 关闭光标对象
181 | cursor.close()
182 | # 关闭数据库连接
183 | conn.close()
184 |
185 |
186 | if __name__ == '__main__':
187 | app = QApplication(sys.argv)
188 | page = CashierConsole()
189 | page.show()
190 | sys.exit(app.exec_())
191 |
--------------------------------------------------------------------------------
/Cashier_management/administreators_datalab.py:
--------------------------------------------------------------------------------
1 | from PyQt5.QtGui import QFont, QIcon
2 | from PyQt5.QtWidgets import (QWidget, QMainWindow, QLabel, QFrame, QApplication,
3 | QTableWidgetItem, QPushButton, QLineEdit, QInputDialog,
4 | QDesktopWidget, QTableWidget)
5 | from PyQt5.QtCore import Qt, QCoreApplication
6 | from PyQt5 import QtCore
7 |
8 | import pymysql
9 | import sys
10 | import datetime
11 |
12 | import admin_FaceCollect
13 |
14 |
15 | class DataLab(QMainWindow):
16 | switch_window = QtCore.pyqtSignal()
17 |
18 | def __init__(self):
19 | super(DataLab, self).__init__()
20 | self.init_ui()
21 |
22 | def init_ui(self):
23 |
24 | self.statusBar().showMessage('Ready')
25 | self.setWindowTitle('管理员人员管理')
26 | self.setWindowIcon(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'))
27 | # 窗体大小
28 | self.resize(1200, 900)
29 | # 窗体居中
30 | self.center()
31 |
32 | self.user_name = QLabel(self)
33 | self.user_name.setAlignment(Qt.AlignCenter)
34 | self.user_name.setFont(QFont("Roman times", 18))
35 | self.user_name.setGeometry(400, 0, 400, 100)
36 | self.user_name.setText('欢迎使用管理员人员管理')
37 | self.user_name.setScaledContents(True)
38 |
39 | # 数据库初始化
40 | self.connect_sql()
41 |
42 | # 插入表格
43 | self.MyTable = QTableWidget(self.row, self.vol, self)
44 | font = QFont('微软雅黑', 10)
45 | self.MyTable.setGeometry(0, 100, 1200, 700)
46 |
47 | # 设置字体、表头
48 | self.MyTable.horizontalHeader().setFont(font)
49 | self.MyTable.setHorizontalHeaderLabels(self.col_lst)
50 | # 设置竖直方向表头不可见
51 | self.MyTable.verticalHeader().setVisible(False)
52 | self.MyTable.setFrameShape(QFrame.NoFrame)
53 |
54 | self.data_set()
55 |
56 | self.btn1 = QPushButton('增加管理员', self)
57 | self.btn1.setToolTip('管理员数据增加')
58 | self.btn1.resize(220, 60)
59 | self.btn1.move(480, 820)
60 |
61 | self.btn2 = QPushButton('删除管理员', self)
62 | self.btn2.setToolTip('管理员数据删除')
63 | self.btn2.resize(220, 60)
64 | self.btn2.move(720, 820)
65 |
66 | self.btn3 = QPushButton('刷新', self)
67 | self.btn3.setToolTip('数据刷新')
68 | self.btn3.resize(220, 60)
69 | self.btn3.move(960, 820)
70 |
71 | self.btn1.clicked.connect(self.buttonClicked)
72 | self.btn2.clicked.connect(self.buttonClicked)
73 | self.btn3.clicked.connect(self.buttonClicked)
74 |
75 | def buttonClicked(self):
76 |
77 | sender = self.sender()
78 | self.statusBar().showMessage(sender.text() + '被点击')
79 |
80 | if sender.text() == str('增加管理员'):
81 | self.onadd()
82 | elif sender.text() == str('删除管理员'):
83 | # 后面四个数字的作用依次是 初始值 最小值 最大值 步幅
84 | value, ok = QInputDialog.getText(self, "删除管理员", "请输入你要删除的管理员id:")
85 | self.del_date(value)
86 | elif sender.text() == str('刷新'):
87 | self.nowwin = DataLab()
88 | self.nowwin.show()
89 | self.close()
90 |
91 | def onadd(self):
92 | self.newWindow = add_win()
93 | self.newWindow.show()
94 | # self.switch_window.emit()
95 |
96 | def data_set(self):
97 | # 数据插入
98 | for i in range(self.row):
99 | for j in range(self.vol):
100 | if self.col_lst[j] != 'password':
101 | temp_data = self.data[i][j] # 临时记录,不能直接插入表格
102 | data1 = QTableWidgetItem(str(temp_data)) # 转换后可插入表格
103 | else:
104 | temp_data = '******' # 临时记录,不能直接插入表格
105 | data1 = QTableWidgetItem(str(temp_data)) # 转换后可插入表格
106 | self.MyTable.setItem(i, j, data1)
107 |
108 | def connect_sql(self):
109 |
110 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
111 | database='cashier_management', port=3306,
112 | charset='utf8')
113 | # 得到一个可以执行SQL语句的光标对象
114 | cursor = conn.cursor()
115 | # 定义要执行的SQL语句
116 | cursor.execute('select * from admin')
117 | self.data = cursor.fetchall()
118 |
119 | # 数据列名
120 | self.col_lst = [tup[0] for tup in cursor.description]
121 |
122 | # 数据大小
123 | if len(self.data) == 0:
124 | self.row = 0
125 | self.vol = 0
126 | else:
127 | self.row = len(self.data)
128 | self.vol = len(self.data[0])
129 |
130 | # 关闭光标对象
131 | cursor.close()
132 | # 关闭数据库连接
133 | conn.close()
134 |
135 | def del_date(self, id):
136 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
137 | database='cashier_management', port=3306,
138 | charset='utf8')
139 |
140 | admin_delete = "DELETE FROM admin WHERE id = %d;" \
141 | % int(id)
142 |
143 | adface_delete = "DELETE FROM admin_face WHERE name_id = %d;" \
144 | % int(id)
145 | cursor = conn.cursor()
146 | # 定义要执行的SQL语
147 | cursor.execute(admin_delete)
148 | cursor.execute(adface_delete)
149 | conn.commit()
150 |
151 | # 关闭光标对象
152 | cursor.close()
153 | # 关闭数据库连接
154 | conn.close()
155 |
156 | def center(self):
157 | # 得到一个指定了主窗体形状的矩形
158 | qr = self.frameGeometry()
159 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
160 | cp = QDesktopWidget().availableGeometry().center()
161 | # 将矩形移动到屏幕中心
162 | qr.moveCenter(cp)
163 | # 窗体的左上角移动到矩形qr的左上角
164 | self.move(qr.topLeft())
165 |
166 |
167 | class add_win(QWidget):
168 | switch_window = QtCore.pyqtSignal(str, str)
169 |
170 | def __init__(self):
171 | super(add_win, self).__init__()
172 | self.init_ui()
173 |
174 | def init_ui(self):
175 | self.setWindowTitle("管理员添加")
176 | self.resize(400, 400)
177 | self.center()
178 |
179 | self.IDLabel = QLabel("ID : ", self)
180 | self.IDLabel.setAlignment(Qt.AlignCenter)
181 | self.IDLabel.setGeometry(0, 0, 100, 100)
182 |
183 | self.IDLineEdit = QLineEdit(" ", self)
184 | self.IDLineEdit.setGeometry(120, 30, 200, 50)
185 |
186 | self.nameLabel = QLabel("name : ", self)
187 | self.nameLabel.setAlignment(Qt.AlignCenter)
188 | self.nameLabel.setGeometry(0, 100, 100, 100)
189 |
190 | self.nameLineEdit = QLineEdit(" ", self)
191 | self.nameLineEdit.setGeometry(120, 130, 200, 50)
192 |
193 | self.passwordLabel = QLabel("passwork : ", self)
194 | self.passwordLabel.setAlignment(Qt.AlignCenter)
195 | self.passwordLabel.setGeometry(0, 200, 100, 100)
196 |
197 | self.passwordLineEdit = QLineEdit(" ", self)
198 | self.passwordLineEdit.setGeometry(120, 230, 200, 50)
199 |
200 | self.save_Btn = QPushButton('保存', self)
201 | self.save_Btn.setGeometry(50, 300, 100, 50)
202 | self.cancle_Btn = QPushButton('取消', self)
203 | self.cancle_Btn.setGeometry(250, 300, 100, 50)
204 | self.cancle_Btn.clicked.connect(self.quit)
205 | self.save_Btn.clicked.connect(self.addNum)
206 |
207 | def quit(self):
208 | self.close()
209 |
210 | def addNum(self):
211 | id = self.IDLineEdit.text() # 获取文本框内容
212 | name = self.nameLineEdit.text()
213 | password = self.passwordLineEdit.text()
214 |
215 | self.add_sql(id, name, password)
216 | # self.switch_window.emit(name, id)
217 | self.add_face = admin_FaceCollect.GUI(name, id)
218 | self.add_face.show()
219 | self.close()
220 |
221 | def center(self):
222 | # 得到一个指定了主窗体形状的矩形
223 | qr = self.frameGeometry()
224 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
225 | cp = QDesktopWidget().availableGeometry().center()
226 | # 将矩形移动到屏幕中心
227 | qr.moveCenter(cp)
228 | # 窗体的左上角移动到矩形qr的左上角
229 | self.move(qr.topLeft())
230 |
231 | def add_sql(self, id, name, password):
232 |
233 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
234 | database='cashier_management', port=3306,
235 | charset='utf8')
236 |
237 | sql_insert = "INSERT INTO admin VALUES (%d, %s, %s, %s);" \
238 | % (int(id), "'"+name+"'", "'"+password+"'", datetime.datetime.now().strftime('"%Y-%m-%d %H:%M:%S"'))
239 | cursor = conn.cursor()
240 | # 定义要执行的SQL语
241 | cursor.execute(sql_insert)
242 | conn.commit()
243 |
244 | # 关闭光标对象
245 | cursor.close()
246 | # 关闭数据库连接
247 | conn.close()
248 |
249 | #
250 | # class Controller(object):
251 | #
252 | # def __init__(self):
253 | # pass
254 | #
255 | # def show_main(self):
256 | # self.datalab = DataLab()
257 | # self.datalab.switch_window.connect(self.show_add)
258 | # self.datalab.show()
259 | #
260 | # def show_add(self):
261 | # self.addwin = add_win()
262 | # self.addwin.switch_window.connect(self.show_face_col)
263 | # self.addwin.show()
264 | #
265 | # def show_face_col(self, name, id):
266 | # self.face_col = admin_FaceCollect.GUI(name, id)
267 | # self.addwin.close()
268 | # self.face_col.show()
269 |
270 |
271 | if __name__ == '__main__':
272 | app = QApplication(sys.argv)
273 | page = DataLab()
274 | page.show()
275 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/Cashier_management/cashier_datalab.py:
--------------------------------------------------------------------------------
1 | from functools import partial
2 | from PyQt5.QtGui import QFont, QIcon
3 | from PyQt5.QtWidgets import (QWidget, QMainWindow, QLabel, QFrame, QApplication,
4 | QTableWidgetItem, QPushButton, QLineEdit, QInputDialog,
5 | QDesktopWidget, QTableWidget)
6 | from PyQt5.QtCore import Qt, QCoreApplication
7 | from PyQt5 import QtCore
8 | import pymysql
9 | import sys
10 | import datetime
11 |
12 | import cashier_FaceCollect
13 |
14 | class DataLab(QMainWindow):
15 | switch_window = QtCore.pyqtSignal()
16 |
17 | def __init__(self):
18 | super(DataLab, self).__init__()
19 | self.init_ui()
20 |
21 | def init_ui(self):
22 |
23 | self.statusBar().showMessage('Ready')
24 | self.setWindowTitle('收银员人员管理')
25 | self.setWindowIcon(QIcon('E:\\py project\\FaceRecognition\\timg.jpg'))
26 | # 窗体大小
27 | self.resize(1200, 900)
28 | # 窗体居中
29 | self.center()
30 |
31 | self.user_name = QLabel(self)
32 | self.user_name.setAlignment(Qt.AlignCenter)
33 | self.user_name.setFont(QFont("Roman times", 18))
34 | self.user_name.setGeometry(400, 0, 400, 100)
35 | self.user_name.setText('欢迎使用收银员人员管理')
36 | self.user_name.setScaledContents(True)
37 |
38 | # 数据库初始化
39 | self.connect_sql()
40 |
41 | # 插入表格
42 | self.MyTable = QTableWidget(self.row, self.vol, self)
43 | font = QFont('微软雅黑', 10)
44 | self.MyTable.setGeometry(0, 100, 1200, 700)
45 |
46 | # 设置字体、表头
47 | self.MyTable.horizontalHeader().setFont(font)
48 | self.MyTable.setHorizontalHeaderLabels(self.col_lst)
49 | # 设置竖直方向表头不可见
50 | self.MyTable.verticalHeader().setVisible(False)
51 | self.MyTable.setFrameShape(QFrame.NoFrame)
52 |
53 | self.data_set()
54 |
55 | self.btn1 = QPushButton('增加收银员', self)
56 | self.btn1.setToolTip('收银员数据增加')
57 | self.btn1.resize(220, 60)
58 | self.btn1.move(480, 820)
59 |
60 | self.btn2 = QPushButton('删除收银员', self)
61 | self.btn2.setToolTip('收银员数据删除')
62 | self.btn2.resize(220, 60)
63 | self.btn2.move(720, 820)
64 |
65 | self.btn3 = QPushButton('刷新', self)
66 | self.btn3.setToolTip('数据刷新')
67 | self.btn3.resize(220, 60)
68 | self.btn3.move(960, 820)
69 |
70 | self.btn1.clicked.connect(self.buttonClicked)
71 | self.btn2.clicked.connect(self.buttonClicked)
72 | self.btn3.clicked.connect(self.buttonClicked)
73 |
74 | def buttonClicked(self):
75 |
76 | sender = self.sender()
77 | self.statusBar().showMessage(sender.text() + '被点击')
78 |
79 | if sender.text() == str('增加收银员'):
80 | self.onadd()
81 | elif sender.text() == str('删除收银员'):
82 | # 后面四个数字的作用依次是 初始值 最小值 最大值 步幅
83 | value, ok = QInputDialog.getText(self, "删除收银员", "请输入你要删除的收银员员id:")
84 | self.del_date(value)
85 | elif sender.text() == str('刷新'):
86 | self.nowwin = DataLab()
87 | self.nowwin.show()
88 | self.close()
89 |
90 | def onadd(self):
91 | self.newWindow = add_win()
92 | self.newWindow.show()
93 | # self.switch_window.emit()
94 |
95 | def data_set(self):
96 | # 数据插入
97 | for i in range(self.row):
98 | for j in range(self.vol):
99 | if self.col_lst[j] != 'password':
100 | temp_data = self.data[i][j] # 临时记录,不能直接插入表格
101 | data1 = QTableWidgetItem(str(temp_data)) # 转换后可插入表格
102 | else:
103 | temp_data = '******' # 临时记录,不能直接插入表格
104 | data1 = QTableWidgetItem(str(temp_data)) # 转换后可插入表格
105 | self.MyTable.setItem(i, j, data1)
106 |
107 | def connect_sql(self):
108 |
109 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
110 | database='cashier_management', port=3306,
111 | charset='utf8')
112 | # 得到一个可以执行SQL语句的光标对象
113 | cursor = conn.cursor()
114 | # 定义要执行的SQL语句
115 | cursor.execute('select * from cashier')
116 | self.data = cursor.fetchall()
117 |
118 | # 数据列名
119 | self.col_lst = [tup[0] for tup in cursor.description]
120 |
121 | # 数据大小
122 | if len(self.data) == 0:
123 | self.row = 0
124 | self.vol = 0
125 | else:
126 | self.row = len(self.data)
127 | self.vol = len(self.data[0])
128 |
129 | # 关闭光标对象
130 | cursor.close()
131 | # 关闭数据库连接
132 | conn.close()
133 |
134 | def del_date(self, id):
135 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
136 | database='cashier_management', port=3306,
137 | charset='utf8')
138 |
139 | sql_delete = "DELETE FROM cashier WHERE id = %d;" \
140 | % int(id)
141 | adface_delete = "DELETE FROM cashier_face WHERE name_id = %d;" \
142 | % int(id)
143 | cursor = conn.cursor()
144 | # 定义要执行的SQL语
145 | cursor.execute(sql_delete)
146 | cursor.execute(adface_delete)
147 | conn.commit()
148 |
149 | # 关闭光标对象
150 | cursor.close()
151 | # 关闭数据库连接
152 | conn.close()
153 |
154 | def center(self):
155 | # 得到一个指定了主窗体形状的矩形
156 | qr = self.frameGeometry()
157 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
158 | cp = QDesktopWidget().availableGeometry().center()
159 | # 将矩形移动到屏幕中心
160 | qr.moveCenter(cp)
161 | # 窗体的左上角移动到矩形qr的左上角
162 | self.move(qr.topLeft())
163 |
164 |
165 |
166 | class add_win(QWidget):
167 | switch_window = QtCore.pyqtSignal(str, str)
168 |
169 | def __init__(self):
170 | super(add_win, self).__init__()
171 | self.init_ui()
172 |
173 | def init_ui(self):
174 | self.setWindowTitle("收银员添加")
175 | self.resize(400, 400)
176 | self.center()
177 |
178 | self.IDLabel = QLabel("ID : ", self)
179 | self.IDLabel.setAlignment(Qt.AlignCenter)
180 | self.IDLabel.setGeometry(0, 0, 100, 100)
181 |
182 | self.IDLineEdit = QLineEdit(" ", self)
183 | self.IDLineEdit.setGeometry(120, 30, 200, 50)
184 |
185 | self.nameLabel = QLabel("name : ", self)
186 | self.nameLabel.setAlignment(Qt.AlignCenter)
187 | self.nameLabel.setGeometry(0, 100, 100, 100)
188 |
189 | self.nameLineEdit = QLineEdit(" ", self)
190 | self.nameLineEdit.setGeometry(120, 130, 200, 50)
191 |
192 | self.passwordLabel = QLabel("passwork : ", self)
193 | self.passwordLabel.setAlignment(Qt.AlignCenter)
194 | self.passwordLabel.setGeometry(0, 200, 100, 100)
195 |
196 | self.passwordLineEdit = QLineEdit(" ", self)
197 | self.passwordLineEdit.setGeometry(120, 230, 200, 50)
198 |
199 | self.save_Btn = QPushButton('保存', self)
200 | self.save_Btn.setGeometry(50, 300, 100, 50)
201 | self.cancle_Btn = QPushButton('取消', self)
202 | self.cancle_Btn.setGeometry(250, 300, 100, 50)
203 | self.cancle_Btn.clicked.connect(self.quit)
204 | self.save_Btn.clicked.connect(self.addNum)
205 |
206 | def quit(self):
207 | self.close()
208 |
209 | def addNum(self):
210 | id = self.IDLineEdit.text() # 获取文本框内容
211 | name = self.nameLineEdit.text()
212 | password = self.passwordLineEdit.text()
213 |
214 | self.add_sql(id, name, password)
215 |
216 | # self.switch_window.emit(name, id)
217 | self.add_face = cashier_FaceCollect.GUI(name, id)
218 | self.add_face.show()
219 | self.close()
220 |
221 | def center(self):
222 | # 得到一个指定了主窗体形状的矩形
223 | qr = self.frameGeometry()
224 | # 指出显示器的屏幕分辨率并根据分辨率找出屏幕的中心点
225 | cp = QDesktopWidget().availableGeometry().center()
226 | # 将矩形移动到屏幕中心
227 | qr.moveCenter(cp)
228 | # 窗体的左上角移动到矩形qr的左上角
229 | self.move(qr.topLeft())
230 |
231 | def add_sql(self, id, name, password):
232 |
233 | conn = pymysql.connect(host='139.9.105.107', user='root', passwd='wzr152wzrA',
234 | database='cashier_management', port=3306,
235 | charset='utf8')
236 |
237 | sql_insert = "INSERT INTO cashier VALUES (%d, %s, %s, %s);" \
238 | % (int(id), "'"+name+"'", "'"+password+"'", datetime.datetime.now().strftime('"%Y-%m-%d %H:%M:%S"'))
239 | cursor = conn.cursor()
240 | # 定义要执行的SQL语
241 | cursor.execute(sql_insert)
242 | conn.commit()
243 |
244 | # 关闭光标对象
245 | cursor.close()
246 | # 关闭数据库连接
247 | conn.close()
248 |
249 |
250 | # class Controller:
251 | #
252 | # def __init__(self):
253 | # pass
254 | #
255 | # def show_main(self):
256 | # self.datalab = DataLab()
257 | # self.datalab.switch_window.connect(self.show_add)
258 | # self.datalab.show()
259 | #
260 | # def show_add(self):
261 | # self.addwin = add_win()
262 | # self.addwin.switch_window.connect(self.show_face_col)
263 | # self.addwin.show()
264 | #
265 | # def show_face_col(self, name, id):
266 | # self.face_col = cashier_FaceCollect.GUI(name, id)
267 | # self.addwin.close()
268 | # self.face_col.show()
269 |
270 |
271 | if __name__ == '__main__':
272 | app = QApplication(sys.argv)
273 | page = DataLab()
274 | page.show()
275 | sys.exit(app.exec_())
--------------------------------------------------------------------------------
/Cashier_management/capture_distinguish.py:
--------------------------------------------------------------------------------
1 | import time
2 | import sys
3 | import cv2
4 | import numpy as np
5 | import pymysql
6 | import face_recognition
7 | from collections import Counter
8 |
9 | from PIL import ImageQt, Image, ImageFont, ImageDraw
10 | from PyQt5.QtWidgets import *
11 | from PyQt5.QtGui import *
12 | from PyQt5 import QtCore
13 | from PyQt5.QtCore import QTimer, Qt, QPoint
14 |
15 | from FileDrawRect.MyLabel import MyLabel
16 | from Cashier_management import administrators_console
17 | from Cashier_management import cashier_console
18 |
19 |
20 | class Video(object):
21 | def __init__(self, capture):
22 | self.capture = capture
23 | self.currentFrame = np.array([])
24 |
25 | def captureOpen(self):
26 |
27 | return self.capture.isOpened()
28 |
29 | def captureFrame(self):
30 | ret, frame = self.capture.read()
31 | return frame
32 |
33 | def captureNextFrame(self):
34 | ret, frame = self.capture.read()
35 | if ret is True:
36 | self.currentFrame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
37 | # print(frame)
38 | return ret
39 |
40 | def convertFrame(self):
41 | try:
42 | height, width = self.currentFrame.shape[:2]
43 | img = QImage(self.currentFrame,
44 | width,
45 | height,
46 | QImage.
47 | Format_RGB888)
48 | img = QPixmap.fromImage(img)
49 |
50 | # self.previousFrame = self.currentFrame
51 | return img
52 | except Exception as e:
53 | print(e)
54 | return None
55 |
56 |
57 | class GUI(QMainWindow):
58 | switch_window = QtCore.pyqtSignal(str)
59 |
60 | def __init__(self, user = '管理员'):
61 | super().__init__()
62 | self.user = user
63 | self.Face_Cascade = cv2.CascadeClassifier(
64 | r'E:\\anaconda\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_alt2.xml')
65 | self.recognizer = cv2.face.LBPHFaceRecognizer_create()
66 | self.recognizer.read(r'E:\\py project\\FaceRecognition\\trainer\\trainer.yml')
67 | self.known_face_encodings = []
68 | self.known_face_names = []
69 |
70 | if self.user == "管理员":
71 | self.get_admin_info()
72 | elif self.user == "收银员":
73 | self.get_cashier_info()
74 | print(self.user)
75 | print(self.known_face_names)
76 |
77 | self.setGeometry(250, 80, 800, 600)
78 | self.setWindowTitle('人脸识别')
79 | #self.video = Video(cv2.VideoCapture(0, cv2.CAP_DSHOW))
80 | self.video = Video(cv2.VideoCapture(0))
81 | time.sleep(1)
82 | self._timer = QTimer(self)
83 | self._timer.timeout.connect(self.play)
84 | self._timer.start(27)
85 | self.update()
86 | self.videoFrame = MyLabel("摄像头准备中,请稍后......")
87 | self.videoFrame.setAlignment(Qt.AlignCenter)
88 | self.setCentralWidget(self.videoFrame)
89 |
90 | self.ret, self.frame = self.video.capture.read()
91 |
92 | def play(self):
93 | try:
94 | if self.video.captureNextFrame() is True:
95 | self.videoFrame.drawingPermission(True)
96 | self.videoFrame.initDrawing(self.video.convertFrame())
97 |
98 | faces = self.Face_Cascade.detectMultiScale(self.video.currentFrame, minSize=(120, 120))
99 | for (x, y, w, h) in faces:
100 | self.videoFrame.drawRect(QPoint(x, y), QPoint(x + w, y + h))
101 | face_name = self.load_image()
102 | print(face_name[0])
103 | if face_name[0] != "Unknow":
104 |
105 | face_name_now = Counter(face_name).most_common(1)[0][0]
106 | print(Counter(face_name).most_common(1)[0][1])
107 | if Counter(face_name).most_common(1)[0][1] <= 8:
108 | continue
109 | print(face_name_now)
110 | # if self.user == "管理员":
111 | # self.adminwin = administrators_console.CashierConsole(face_name_now)
112 | # self.adminwin.show()
113 | # elif self.user == "收银员":
114 | # self.cashierwin = cashier_console.CashierConsole(face_name_now)
115 | # self.cashierwin.show()
116 | # self.close()
117 |
118 | self.switch_window.emit(face_name_now)
119 | self._timer.stop()
120 |
121 | self.videoFrame.drawRect(QPoint(0, 0), QPoint(0, 0))
122 | self.videoFrame.setScaledContents(True)
123 |
124 |
125 | except Exception as e:
126 | print(e)
127 |
128 | def transImg(self, img):
129 | img = img.resize((self.label.width(), self.label.height()))
130 | return ImageQt.toqpixmap(img)
131 |
132 | def SHOW(self):
133 | self.show()
134 |
135 | def closeEvent(self, event):
136 | event.accept()
137 | cv2.VideoCapture(0, cv2.CAP_DSHOW).release()
138 |
139 | def load_image(self):
140 |
141 | # 利用opencv的缩放函数改变摄像头图像的大小
142 | small_frame = cv2.resize(self.video.captureFrame(), (0, 0), fx=0.25, fy=0.25)
143 |
144 | # opencv的图像是BGR格式的,将其转化为RGB格式
145 | rgb_small_frame = small_frame[:, :, ::-1]
146 |
147 | # 使用默认的HOG模型查找图像中的所有人脸
148 | face_locations = face_recognition.face_locations(rgb_small_frame)
149 | # face_locations = face_recognition.face_locations(image, number_of_times_to_upsample=0, model="cnn")
150 |
151 | # 返回128维人脸编码,即人脸特征
152 | face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations)
153 |
154 | face_names = []
155 |
156 | # 将得到的人脸特征与数据库中的人脸特征集合进行比较,相同返回True,不同返回False
157 | for face_encoding in face_encodings:
158 |
159 | if len(self.known_face_encodings) != 0:
160 | # matches:一个返回值为True或者False值的列表,该表指示了known_face_encodings列表的每个成员的匹配结果
161 | # tolerance:越小对比越严格,官方说法是0.6为典型的最佳值,也是默认值
162 | matches = face_recognition.compare_faces(self.known_face_encodings, face_encoding, tolerance=0.45)
163 |
164 | if True in matches:
165 |
166 | # first_match_index = matches.index(True)
167 | # name = self.known_face_names[first_match_index]
168 | # print('已存在')
169 |
170 | for index, value in enumerate(matches):
171 | if value == True:
172 | name = self.known_face_names[index]
173 | face_names.append(name)
174 | else:
175 | # 默认为unknown
176 | name = "Unknow"
177 | # print('不存在')
178 | face_names.append(name)
179 |
180 | return face_names
181 |
182 | def get_admin_info(self):
183 | # 创建数据库连接对象
184 | conn = pymysql.connect(
185 | # 数据库的IP地址
186 | host="139.9.105.107",
187 | # 数据库用户名称
188 | user="root",
189 | # 数据库用户密码
190 | password="wzr152wzrA",
191 | # 数据库名称
192 | db="cashier_management",
193 | # 数据库端口名称
194 | port=3306,
195 | # 数据库的编码方式 注意是utf8
196 | charset="utf8"
197 | )
198 |
199 | # 使用 cursor() 方法创建一个游标对象 cursor
200 | cursor = conn.cursor()
201 |
202 | # SQL查询语句
203 | sql = "select * from admin_face"
204 | try:
205 | # 执行SQL语句
206 | cursor.execute(sql)
207 | # 获取所有记录列表
208 | results = cursor.fetchall()
209 | # 返回的结果集为元组
210 | for row in results:
211 | name = row[2]
212 | encoding = row[3]
213 | # print("name=%s,encoding=%s" % (name, encoding))
214 | # 将字符串转为numpy ndarray类型,即矩阵
215 | # 转换成一个list
216 | dlist = encoding.strip(' ').split(',')
217 | # 将list中str转换为float
218 | dfloat = list(map(float, dlist))
219 | arr = np.array(dfloat)
220 |
221 | # 将从数据库获取出来的信息追加到集合中
222 | self.known_face_encodings.append(arr)
223 | self.known_face_names.append(name)
224 |
225 | except Exception as e:
226 | print(e)
227 |
228 | # 关闭数据库连接
229 | conn.close()
230 |
231 | def get_cashier_info(self):
232 | # 创建数据库连接对象
233 | conn = pymysql.connect(
234 | # 数据库的IP地址
235 | host="139.9.105.107",
236 | # 数据库用户名称
237 | user="root",
238 | # 数据库用户密码
239 | password="wzr152wzrA",
240 | # 数据库名称
241 | db="cashier_management",
242 | # 数据库端口名称
243 | port=3306,
244 | # 数据库的编码方式 注意是utf8
245 | charset="utf8"
246 | )
247 |
248 | # 使用 cursor() 方法创建一个游标对象 cursor
249 | cursor = conn.cursor()
250 |
251 | # SQL查询语句
252 | sql = "select * from cashier_face"
253 | try:
254 | # 执行SQL语句
255 | cursor.execute(sql)
256 | # 获取所有记录列表
257 | results = cursor.fetchall()
258 | # 返回的结果集为元组
259 | for row in results:
260 | name = row[2]
261 | encoding = row[3]
262 | # print("name=%s,encoding=%s" % (name, encoding))
263 | # 将字符串转为numpy ndarray类型,即矩阵
264 | # 转换成一个list
265 | dlist = encoding.strip(' ').split(',')
266 | # 将list中str转换为float
267 | dfloat = list(map(float, dlist))
268 | arr = np.array(dfloat)
269 |
270 | # 将从数据库获取出来的信息追加到集合中
271 | self.known_face_encodings.append(arr)
272 | self.known_face_names.append(name)
273 |
274 | except Exception as e:
275 | print(e)
276 |
277 | # 关闭数据库连接
278 | conn.close()
279 |
280 |
281 | if __name__ == "__main__":
282 | QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling)
283 |
284 | app = QApplication(sys.argv)
285 | ex = GUI()
286 | ex.show()
287 | sys.exit(app.exec_())
288 |
--------------------------------------------------------------------------------
/.idea/workspace.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
62 |
63 |
64 |
65 | print
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 | true
129 | DEFINITION_ORDER
130 |
131 |
132 |
133 |
134 |
135 |
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 |
146 |
147 |
148 |
149 |
150 |
151 |
152 |
153 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 |
199 |
200 |
201 |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 |
285 |
286 |
287 |
288 |
289 |
290 |
291 |
292 |
293 |
294 |
295 |
296 |
297 |
298 |
299 |
300 |
301 |
302 |
303 |
304 |
305 |
306 |
307 |
308 |
309 |
310 | 1609069876192
311 |
312 |
313 | 1609069876192
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 |
343 |
344 |
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
378 |
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 |
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 |
426 |
427 |
428 |
429 |
430 |
431 |
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 |
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
489 |
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 |
512 |
513 |
514 |
515 |
516 |
517 |
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 |
529 |
530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 |
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 |
622 |
623 |
624 |
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 |
686 |
687 |
688 |
689 |
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
709 |
710 |
--------------------------------------------------------------------------------