python zuoye

import sqlite3
import os


from PIL import ImageTk

from tkinter import *

root=Tk()

def sqlite_exec_sql(conn, sql):
    c = conn.cursor()
    c.execute(sql)
    conn.commit()
    print("Total number of rows changes :", conn.total_changes)


def sqlite_query(conn, sql):
    c = conn.cursor()
    cursor = c.execute(sql)
    return cursor


def creat_table():
    conn = sqlite3.connect('face.db')
    SQL_CREATE_TABLE = \
        '''
        CREATE TABLE FACE(
            ID             INTEGER  PRIMARY KEY  NOT NULL,
            NAME           TEXT      NOT NULL,
            IMAGE_PATH     CHAR(255) NOT NULL
        );'''
    # 新建表
    sqlite_exec_sql(conn, SQL_CREATE_TABLE)
    print("Table created successfully")
    conn.close()


def insert_face_data(name, img_path):
    conn = sqlite3.connect('face.db')
    SQL_INSET_DATA = \
        "INSERT INTO FACE (NAME,IMAGE_PATH) VALUES ('" + name +"','"+ img_path + "')"
    # 插入数据
    print(SQL_INSET_DATA)
    sqlite_exec_sql(conn, SQL_INSET_DATA)
    conn.close()


def delete_face_data(id):
    conn = sqlite3.connect('face.db')
    SQL_DELETE_DATA = "DELETE from FACE where ID='"+str(id)+"';"
    # 插入数据
    sqlite_exec_sql(conn, SQL_DELETE_DATA)
    conn.close()
    
def delete_face_name():
    conn = sqlite3.connect('face.db')
    SQL_DELETE_DATA = "DELETE from FACE where NAME='" + str() + "';"
    # 插入数据
    sqlite_exec_sql(conn, SQL_DELETE_DATA)
    conn.close()

def query_face_data_all():
    conn = sqlite3.connect('face.db')
    SQL_QUERY_DATA_ALL = "SELECT * from FACE;"
    res = sqlite_query(conn, SQL_QUERY_DATA_ALL)
    temp = []
    for item in res:
        temp.append({'id':item[0] ,"data":{"name":item[1],'img_path':item[2]}})
    conn.close()
    return temp


def query_face_data_by_name(name):
    conn = sqlite3.connect('face.db')
    SQL_QUERY_DATA_ALL = "SELECT * from FACE where name = '"+ name +"';"
    res = sqlite_query(conn, SQL_QUERY_DATA_ALL)
    temp = []
    for item in res:
        temp.append({'id': item[0], "data": {"name": item[1], 'img_path': item[2]}})
    conn.close()
    return temp


def insert_face_img(path):
    def traverse(path, pathsDic):
        tempFilePath = ''
        tempFileName = ''
        tempPerName = ''
        filePath = [os.path.join(path, f) for f in os.listdir(path)]
        for itemPath in filePath:
            if os.path.isdir(itemPath):
                traverse(itemPath, pathsDic)
            elif os.path.isfile(itemPath):
                if itemPath.split("\\")[-1].split(".")[0][-4:] == '0001':
                    tempFileName = itemPath.split("\\")[-1]
                    tempFilePath = itemPath.split("\\")[0] + "/" +itemPath.split("\\")[1]+"/" +itemPath.split("\\")[2]
                    tempPerName = itemPath.split("\\")[1]

            else:
                print("false")
        pathsDic.append({"path":tempFilePath, "imgName":tempFileName,"name":tempPerName})
        return tempFilePath, tempFileName, tempPerName
    result = []
    traverse(path, result)
    del result[-1]
    return result

# def face_search(images):
#     if images == None:
#         print('null!!')
#     return 'none'
# def face_recognition(images):
#     with sqlite3.connect('face.db') as conn:
#         if
# add butten
class search:
    def Show(self):
        self.root.title("Python Gui")
        self.messagebox.label(root,text="search", fg='blue', anchor="c")
        self.messagebox.pack(side = LEFT)
        self.E = Entry(root, bd =10 )
        self.E.pack(side = RIGHT)

    def show_button(self):
        self.btn = Button(self.top, text="seach", command=insert_face_img)
        self.btn.pack()

        root.mainloop()

# add
class add:
    def printcoord(self):
        self.file = self.filedialog.askopenfilename(parent=root,initialdir="./", title="choose an image.")
        filename = ImageTk.PhotoImage(Image.open(self.file))
        self.canvas.imags = filename
        self.canvas.create_image(0,0, anchor="nw", image=filename)
    
    def show_button(self):
        self.btn = Button(self.root, text="choose", command=insert_face_data)
        self.btn.pack()

# delete
class delete:
    def show_button(self):
        self.btn = Button(self.root, text="choose", command=delete_face_data)
        self.btn.pack()



if __name__ == "__main__":
    unknown = "face_img/face.jpg" #Aaron_Eckhart_0001

    # 照片所在文件夹
    path = "./"

    # 遍历照片插入数据库
    result = insert_face_img(path)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值