Ứng dụng xử lý ảnh trong hệ thông tiện nghi trên ô tô

70 7 0
Ứng dụng xử lý ảnh trong hệ thông tiện nghi trên ô tô

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH CƠNG TRÌNH NGHIÊN CỨU KHOA HỌC CỦA SINH VIÊN ỨNG DỤNG XỬ LÝ ẢNH TRONG HỆ THỐNG TIỆN NGHI TRÊN Ô TÔ S K C 0 9 MÃ SỐ: SV2021 - 134 CHỦ NHIỆM ĐỀ TÀI: LÊ BÁ TRẮC S KC 0 Tp Hồ Chí Minh, tháng 6/2021 BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐH SƯ PHẠM KỸ THUẬT TPHCM BÁO CÁO TỔNG KẾT ĐỀ TÀI NGHIÊN CỨU KHOA HỌC CỦA SINH VIÊN ỨNG DỤNG XỬ LÝ ẢNH TRONG HỆ THỐNG TIỆN NGHI TRÊN Ô TÔ Mã số đề tài: SV2021 – 134 Thuộc nhóm ngành khoa học: Khoa học kỹ thuật SV thực hiện: Lê Bá Trắc MSSV: 17145376 Dân tộc: Kinh Lớp, khoa: 17145CL1A – ĐT Chất Lượng Cao Ngành học: Công nghệ kỹ thuật ô tô Sinh viên chịu trách nhiệm đề tài: Lê Bá Trắc Người hướng dẫn: Th.S Vũ Đình Huấn Nam, Nữ: Nam Năm thứ: 4/Số năm đào tạo:4 ii CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập – Tự – Hạnh phúc ***** NHIỆM VỤ NGHIÊN CỨU KHOA HỌC TÊN ĐỀ TÀI: ỨNG DỤNG XỬ LÝ ẢNH TRONG HỆ THỐNG TIỆN NGHI TRÊN Ô TÔ Sinh viên thực hiện: Họ tên SV1: Lê Bá Trắc MSSV: 17145376 Họ tên SV2: Nguyễn Quốc Triều MSSV: 17145239 I NỘI DUNG Các số liệu ban đầu:  kit Raspberry Pi 4, thẻ nhớ SD, hình LCD 7inch, wedcam Logitech c270, module relay kênh, bàn phím chuột điều khiển… Nội dung thực hiện:  Tổng quan xử lý ảnh; Tìm hiểu phương pháp phát khuôn mặt nhận diện khn mặt; Tìm hiểu kit Raspberry Pi linh kiện liên quan; Tìm hiểu ngơn ngữ lập trình python thư viện opencv; Viết chương trình kit Raspberry Pi 4; Thiết kế mơ hình điều khiển ghế ô tô… II TÀI LIỆU THAM KHẢO  Sách tham khảo, tài liệu, mơ hình III TRÌNH BÀY  thuyết minh đồ án  Upload ấn phẩm lên Google Drive (Hồ sơ NCKH, file word, powerpoint ĐATN) IV THỜI GIAN THỰC HIỆN  Ngày bắt đầu: 15/12/2020  Ngày hồn thành: 15/12/2021 Tp Hồ Chí Minh, ngày 20 tháng 03 năm 2021 Trưởng ngành Giáo viên hướng iii LỜI CẢM ƠN Trong thời gian thực hoàn thành nghiên cứu khoa học này, nhóm nghiên cứu xin gửi lời cảm ơn chân thành đến: Ban giám hiệu trường Đại học Sư phạm Kỹ thuật Thành phố Hồ Chí Minh tạo tất điều kiện sở vật chất với trang thiết bị đại, hệ thống thư viện đa dạng loại sách, tài liệu thuận lợi cho việc tìm kiếm, nghiên cứu thơng tin Ngồi cố gắng thân, nhóm em khơng thể khơng nhắc đến công lao vạch hướng cho đề tài hướng dẫn yêu cầu đề tài mà thầy môn giảng viên hướng dẫn – Th.S Vũ Đình Huấn truyền đạt cho nhóm kiến thức bổ ích ứng dụng thực tế Thầy giúp chúng em tích lũy thêm nhiều kiến thức q báu để có nhìn sâu sắc hồn thiện chun mơn Từ buổi trị chuyện thầy ngồi học, chúng em dần trả lời câu hỏi sống thông qua kinh nghiệm sống đáng quý từ Thầy Quý thầy môn ThS Vũ Đình Huấn, ThS Lê Quang Vũ, ThS Nguyễn Trọng Thức, ThS Nguyễn Thành Tuyên ThS Nguyễn Quang Trãi góp ý cho chúng em để chúng em hồn thành tốt đồ án tốt nghiệp Nhóm xin cám ơn tới Anh, Chị khóa bạn sinh viên tạo điều kiện giúp đỡ, từ tài liệu liên quan tới đề tài kinh nghiệm sống thực tế Nhờ họ mà nhóm phát triển Mong rằng, điều tốt đẹp đến với người Thành phố Hồ Chí Minh, ngày 10 tháng 06 năm 2021 Nhóm thực Lê Bá Trắc Nguyễn Quốc Triều iv TÓM TẮT Ngày nay, với phát triển tiến khơng ngừng khoa học kỹ thuật xử lý ảnh đề tài cần quan tâm phát triển Từ nghiên cứu ban đầu ảnh trắng đen, ảnh xám, ảnh màu, xử lý ảnh nghiên cứu chuyên sâu ứng dụng nhiều sống Bên cạnh đó, phổ biến kit Raspberry Pi với kích thước nhỏ gọn, xem máy tính thu nhỏ nên có nhiều đề tài nghiên cứu ứng dụng kit Raspberry Pi thực tiễn Đề tài “Ứng dụng xử lý ảnh hệ thống tiện nghi ô tô” mơ hình sử dụng kit Raspberry Pi nhận diện khuôn mặt người dùng để điều khiển ghế ô tô Dựa ngơn ngữ lập trình Python với thư viện OpenCV Ở sử dụng phương pháp chép đặc trưng, đặc điểm riêng biệt ảnh người dùng để nhận dạng sau xuất tín hiệu vào nhớ ghế để điều khiển ghế Kết thực đề tài nhận diện khuôn mặt người dùng điều khiển vị trí ghế theo vị trí mà người dùng lưu v MỤC LỤC LỜI CẢM ƠN TÓM TẮT MỤC LỤC DANH MỤC CÁC TỪ VIẾT TẮT DANH MỤC CÁC BẢN BIỂU 10 DANH MỤC CÁC HÌNH ẢNH 11 CHƯƠNG 1: TỔNG QUAN 1.1 Lý chọn đề tài 1.2 Mục tiêu đề tài 1.3 Đối tượng nghiên cứu 1.4 Giới hạn đề tài 1.5 Phương pháp nghiên cứu 1.6 Nội dung đồ án 1.7 Bố cục đồ án CHƯƠNG 2: CƠ SỞ LÝ THUYẾT 2.1 Tổng quan xử lý ảnh 2.1.1 Giới thiệu xử lý ảnh 2.1.2 Những vấn đề xử lý ảnh 2.1.3 Các bước xử lý ảnh 12 2.2 Giải thuật AdaBoost 13 2.3 Đặc trưng Haar - Like 15 2.4 Giải thuật Facial Landmarks 18 2.4.1 Giới thiệu Facial Landmarks 18 2.4.2 Tìm hiểu phát dấu mốc khuôn mặt Dlib .19 2.5 Khoảng cách Euclide 20 2.6 Giới thiệu ngôn ngữ Python thư viện OpenCV 21 vi 2.6.1 Ngôn ngữ Python 21 2.6.2 Thư viện OpenCV .24 2.7 Thư viện Dlib 25 2.8 Tổng quan Kit Raspberry Pi 26 2.8.1 Giới thiệu tổng quan 26 2.8.2 Cấu tạo phần cứng kit Raspberry Pi 27 2.8.3 Hệ điều hành kit Raspberry Pi 30 2.8.4 Ứng dụng 31 2.9 Tổng quan hình LCD 7inch 31 2.9.1 Giới thiệu 31 2.9.2 Thông số kỹ thuật .31 2.9.3 Ứng dụng 32 2.10 Tổng quan Wedcam Logitech C270 32 2.10.1 Giới thiệu 32 2.10.2 Thông số kỹ thuật .32 2.10.3 Ứng dụng 33 2.11 Tổng quan chuột bàn phím Raspberry Pi 33 2.11.1 Giới thiệu 33 2.11.2 Thông số kỹ thuật .33 2.11.3 Ứng dụng 34 2.12 Tổng quan Module Relay kênh 34 2.12.1 Giới thiệu 34 2.12.2 Thông số kỹ thuật .35 2.12.3 Ứng dụng 35 2.13 Cài đặt hệ điều hành cho Kit Raspberry Pi 35 2.13.1 Thiết bị cần dùng để cài đặt 35 2.13.2 Cài đặt hệ điều hành Raspbian 35 vii 2.13.3 Điều khiển Raspberry Pi từ xa phần mềm VNC 37 2.14 Cài đặt thư viện Raspberry Pi 40 2.14.1 Cài đặt OpenCV 40 CHƯƠNG 3: TÍNH TỐN VÀ THIẾT KẾ 44 3.1 Giới thiệu 44 3.2 Tính tốn thiết kế hệ thống 45 3.2.1 Thiết kế sơ đồ khối hệ thống 45 3.2.2 Sơ đồ kết nối hệ thống 45 3.2.3 Sơ đồ kết nối toàn mạch .45 CHƯƠNG 4: THI CÔNG HỆ THỐNG 45 4.1 Giới thiệu 45 4.2 Thi công hệ thống 45 4.2.1 Chuẩn bị phần cứng 45 4.2.2 Lắp ráp kiểm tra .45 4.3 Lập trình hệ thống 45 4.3.1 Lưu đồ giải thuật Raspberry Pi 45 4.3.2 Lập trình Python 45 4.3.3 Thiết kế giao diện hiển thị 45 4.3.4 Hướng dẫn sử dụng thao tác 45 CHƯƠNG 5: KẾT QUẢ THỰC NGHIỆM 45 5.1 Kết 45 5.2 Nhận xét đánh giá 45 CHƯƠNG 6: KẾT LUẬN VÀ HƯỚNG PHÁT TRIỂN 45 6.1 Kết luận 45 6.2 Kiến nghị 45 TÀI LIỆU THAM KHẢO 45 PHỤ LỤC 46 viii DANH MỤC CÁC TỪ VIẾT TẮT AI: Artificia Intelligence OpenVC: Open Computer Vision SOC: System On Chip GPIO: General Purpose Input Output DSI: Display Serial Interface CSI: Camera Serial Interface LCD: Liquid Crystal Display NC: Normal Close NO: Normal Open ix DANH MỤC CÁC BẢN BIỂU Bảng 2.1: Thông số dòng Raspberry Pi B 27 Bảng 2.2: Thông số kỹ thuật hình LCD 7inch 31 Bảng 2.3: Thông số kỹ thuật Wedcam Logitech C270 32 Bảng 2.4: Thông số kỹ thuật chuột Raspberry Pi 34 Bảng 2.5: Thông số kỹ thuật bàn phím Raspberry Pi 34 Bảng 2.6: Thông số kỹ thuật Module Relay kênh 35 x Module Relay xuất tín tín hiệu nhớ ghế Bàn phím: Có chức để lập trình, điều khiển kit Raspberry Pi Wedcam: Có chức lấy liệu hình ảnh cần xử lý Màn hình: Nhận kết hiển thị từ xử lý trung tâm Module Relay: Nhận tín hiệu xử lý ảnh từ xử lý trung tâm Seat: Nhận tín hiệu điều khiển vị trí từ Module Relay 3.2 Tính tốn thiết kế hệ thống 3.2.1 Thiết kế sơ đồ khối hệ thống 3.2.2 Sơ đồ kết nối hệ thống 3.2.3 Sơ đồ kết nối tồn mạch CHƯƠNG 4: THI CƠNG HỆ THỐNG 4.1 Giới thiệu 4.2 Thi công hệ thống 4.2.1 Chuẩn bị phần cứng 4.2.2 Lắp ráp kiểm tra 4.3 Lập trình hệ thống 4.3.1 Lưu đồ giải thuật Raspberry Pi 4.3.2 Lập trình Python 4.3.3 Thiết kế giao diện hiển thị 4.3.4 Hướng dẫn sử dụng thao tác CHƯƠNG 5: KẾT QUẢ THỰC NGHIỆM 5.1 Kết 5.2 Nhận xét đánh giá CHƯƠNG 6: KẾT LUẬN VÀ HƯỚNG PHÁT TRIỂN 6.1 Kết luận 6.2 Kiến nghị TÀI LIỆU THAM KHẢO 45 PHỤ LỤC face_model.py import import import import import import sys os argparse numpy as np mxnet as mx cv2 def do_flip(data): for idx in range(data.shape[0]): data[idx, :, :] = np.fliplr(data[idx, :, :]) def get_model(ctx, image_size, prefix, epoch, layer): print('loading', prefix, epoch) sym, arg_params, aux_params = mx.model.load_checkpoint(prefix, epoch) all_layers = sym.get_internals() sym = all_layers[layer + '_output'] model = mx.mod.Module(symbol=sym, context=ctx, label_names=None) #model.bind(data_shapes=[('data', (args.batch_size, 3, image_size[0], image_size[1]))], label_shapes=[('softmax_label', (args.batch_size,))]) model.bind(data_shapes=[('data', (1, 3, image_size[0], image_size[1]))]) model.set_params(arg_params, aux_params) return model class FaceModel: def init (self, ctx_id, model_prefix, model_epoch): image_size = (112,112) self.model = get_model(ctx_id, image_size, model_prefix, model_epoch, 'fc1') self.image_size = image_size 46 def get_feature(self, aligned): a = cv2.cvtColor(aligned, cv2.COLOR_BGR2RGB) a = np.transpose(a, (2, 0, 1)) input_blob = np.expand_dims(a, axis=0) data = mx.nd.array(input_blob) db = mx.io.DataBatch(data=(data, )) self.model.forward(db, is_train=False) emb = self.model.get_outputs()[0].asnumpy()[0] # norm = np.sqrt(np.sum(emb*emb)+0.00001) norm = np.sqrt(np.sum(emb*emb)) emb /= norm return emb AddFaceDB.py from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * try: from PyQt5 import sip except ImportError: import sip from PyQt5 import QtCore, QtGui, QtWidgets from ctypes import * import numpy as np import sys, os, re, time from datetime import datetime, date import uuid, io import imutils import cv2 import face_model import mxnet as mx import pickle, json class Ui_AddFaceDB(object): def init (self): prototxtPath = "models/Detection/deploy.prototxt" weightsPath = "models/Detection/res10_300x300_ssd_iter_140000.caffemodel" self.net_Facedetect = cv2.dnn.readNet(prototxtPath, weightsPath) self.captureImg = False self.path_saveBbFace = None self.path_Face ="Database/" def setupUi(self, Form): Form.setObjectName("Register User") Form.resize(880, 600) 47 self.centralwidget = QtWidgets.QWidget(Form) self.centralwidget.setObjectName("centralwidget") self.show_textName = QtWidgets.QLabel(self.centralwidget) self.show_textName.setGeometry(QtCore.QRect(85, 15, 70, 30)) font = QtGui.QFont() font.setPointSize(14) font.setBold(True) font.setWeight(75) self.show_textName.setFont(font) self.show_textName.setTextFormat(QtCore.Qt.AutoText) self.show_textName.setObjectName("show_textName") self.show_textName.setStyleSheet('color: black') self.Notification= QtWidgets.QLabel(self.centralwidget) self.Notification.setGeometry(QtCore.QRect(725, 55, 150, 150)) font = QtGui.QFont() font.setPointSize(14) font.setBold(True) font.setWeight(75) self.Notification.setFont(font) self.Notification.setTextFormat(QtCore.Qt.AutoText) self.Notification.setObjectName("show_textOpenCamera") self.Notification.setStyleSheet('color: black') self.name = QtWidgets.QLineEdit(self.centralwidget) self.name.setGeometry(QtCore.QRect(190, 15, 205, 30)) self.name.setText("") self.name.setObjectName("name") self.Ok_Name = QtWidgets.QPushButton(self.centralwidget) self.Ok_Name.setGeometry(QtCore.QRect(445, 15, 50, 30 )) self.Ok_Name.setObjectName("Quit") self.Ok_Name.setStyleSheet('color: blue') self.Ok_Name.setFont(QtGui.QFont("",11)) self.TakeImage = QtWidgets.QPushButton(self.centralwidget) self.TakeImage.setGeometry(QtCore.QRect(40, 60, 150, 40)) self.TakeImage.setObjectName("Manual") self.TakeImage.setStyleSheet('color: blue') self.TakeImage.setFont(QtGui.QFont("",11)) self.TrainingImage = QtWidgets.QPushButton(self.centralwidget) self.TrainingImage.setGeometry(QtCore.QRect(395, 60, 150, 40)) self.TrainingImage.setObjectName("TrainingImage") self.TrainingImage.setStyleSheet('color: blue') 48 self.TrainingImage.setFont(QtGui.QFont("",11)) self.Quiter_gui = QtWidgets.QPushButton(self.centralwidget) self.Quiter_gui.setGeometry(QtCore.QRect(740, 540, 80, 35)) self.Quiter_gui.setObjectName("Quit") self.Quiter_gui.setStyleSheet('color: red') self.Quiter_gui.setFont(QtGui.QFont("",11)) self.camerashow = QtWidgets.QLabel(self.centralwidget) self.camerashow.setGeometry(QtCore.QRect(40, 110, 645, 460)) self.camerashow.setText("") self.camerashow.setScaledContents(True) self.camerashow.setObjectName("camerashow") self.FaceCaptureshow = QtWidgets.QLabel(self.centralwidget) self.FaceCaptureshow.setGeometry(QtCore.QRect(710, 165, 145, 160)) self.FaceCaptureshow.setText("") self.FaceCaptureshow.setScaledContents(True) self.FaceCaptureshow.setObjectName("camerashow") self.retranslateUi(Form) QtCore.QMetaObject.connectSlotsByName(Form) self.Ok_Name.clicked.connect(self.Mkdir_Folder) self.TakeImage.clicked.connect(self.Take_Images) self.TrainingImage.clicked.connect(self.Add_FaceDB) self.Quiter_gui.clicked.connect(lambda:self.closescr(Form)) self.cameraOpen() def retranslateUi(self, Form): self._translate = QtCore.QCoreApplication.translate Form.setWindowTitle(self._translate("Register User", "Register User")) self.show_textName.setText(self._translate("Add Database", "Name: ")) self.Ok_Name.setText(self._translate("Register User", "OK")) self.TakeImage.setText(self._translate("Register User", "Take Image")) self.TrainingImage.setText(self._translate("Register User", "Training Image")) self.Quiter_gui.setText(self._translate("Register User", "Exit")) def closescr(self,Form): self.capture.release() Form.hide() def cameraOpen (self): self.capture = cv2.VideoCapture(0) self.timer = QTimer() self.timer.timeout.connect(self.display_video_stream) self.timer.start(0) 49 def Mkdir_Folder(self): self.path_saveBbFace = self.path_Face + self.name.text().replace(" ", "_") if not os.path.exists(self.path_saveBbFace): os.mkdir(self.path_saveBbFace) self.Notification.setText(self._translate("Register User", "Register User \nSuccessfully")) def Take_Images(self): self.captureImg = True def display_video_stream(self): ret, self.frame = self.capture.read() if not (not ret): image_show= self.frame.copy() image_detect= self.frame.copy() if self.captureImg ==True: (h, w) = image_detect.shape[:2] blob = cv2.dnn.blobFromImage(cv2.resize(image_detect, (300, 300)), 1.0,(300, 300), (104.0, 177.0, 123.0)) self.net_Facedetect.setInput(blob) detections = self.net_Facedetect.forward() for i in range(0, detections.shape[2]): confidence = detections[0, 0, i, 2] if confidence > 0.55: box = detections[0, 0, i, 3:7] * np.array([w, h, w, h]) (startX, startY, endX, endY) = box.astype("int") startX = max(0, startX) startY = max(0, startY) endX = min(w, endX) endY = min(h, endY) face = image_detect[startY:endY, startX:endX] face_resize = cv2.resize(face, (112, 112)) path_face_save =self.path_saveBbFace + "/" + uuid.uuid4().hex+ ".png" cv2.imwrite(path_face_save, face_resize) img_show_c = cv2.cvtColor(face_resize, cv2.COLOR_BGR2RGB) img_show = QImage(img_show_c, img_show_c.shape[1], img_show_c.shape[0], img_show_c.strides[0], QImage.Format_RGB888) self.FaceCaptureshow.setPixmap(QPixmap.fromImage(img_show)) self.captureImg =False self.Notification.setText(self._translate("Register User", "Save Face \nSuccessfully")) break frame_color = cv2.cvtColor(image_show, cv2.COLOR_BGR2RGB) frame_show = QImage(frame_color, frame_color.shape[1], frame_color.shape[0], frame_color.strides[0], QImage.Format_RGB888) self.camerashow.setPixmap(QPixmap.fromImage(frame_show)) def Add_FaceDB(self): Data_json =[] 50 path_bbFace ="Database/" model_path = os.path.join(os.path.dirname( file ), 'models/model-y1test2/model') model_extractfeature = face_model.FaceModel(mx.cpu(), model_path, 0) for fol in os.listdir(path_bbFace): for fi in os.listdir(path_bbFace + fol): path_img = path_bbFace + fol + "/"+ fi image_Bbface = cv2.imread(path_img) feature_face = model_extractfeature.get_feature(image_Bbface) feat = feature_face.tolist() person_id = str(uuid.uuid4().hex) person_info= {"name":fol, "feature":feat, "face_id":str(person_id)} Data_json.append(person_info) with open("models/database_Facebank.json", "w") as outfile: data = json.dumps(Data_json) outfile.write(data) self.Notification.setText(self._translate("Register User", "Training \nSuccessfully")) 51 Main.py from PyQt5.QtGui import * from PyQt5.QtCore import * from PyQt5.QtWidgets import * try: from PyQt5 import sip except ImportError: import sip from PyQt5 import QtCore, QtGui, QtWidgets from ctypes import * import numpy as np import sys, os, re, time from datetime import datetime, date import uuid, io import imutils, json import pickle, cv2 import face_model import mxnet as mx from AddFaceDB import Ui_AddFaceDB from scipy.spatial.distance import cosine Array_Name =["LE BA TRAC", "NguyenVanA", "NguyenVanB"] def cosine_face ( feature_face, feat_facesbank): temp_min = 1000 temp_index = for i in (feat_facesbank): temp_similarity = abs(1- np.dot(feature_face, feat_facesbank[i]['feature'])) if temp_min > temp_similarity: temp_min = temp_similarity temp_index = i temp_score = temp_min temp_indexs = temp_index return temp_score, temp_indexs class Ui_MainWindow(object): def init (self): prototxtPath = "models/Detection/deploy.prototxt" weightsPath = "models/Detection/res10_300x300_ssd_iter_140000.caffemodel" self.net_detect = cv2.dnn.readNet(prototxtPath, weightsPath) model_path = os.path.join(os.path.dirname( file ), 'models/model-y1- 52 test2/model') self.model_recognition = face_model.FaceModel(mx.cpu(), model_path, 0) self.FaceDetectRecognition = False self.faces_bank ={} if os.path.isfile('models/database_Facebank.json'): f = open("models/database_Facebank.json", 'r') feat = json.load(f) for i in range (len (feat)): self.faces_bank[feat[i]["face_id"]] = feat[i] def setupUi(self, MainWindow): MainWindow.setObjectName("DRIVER MONITORING SYSTEM") MainWindow.resize(1355, 700) self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.Manual = QtWidgets.QPushButton(self.centralwidget) self.Manual.setGeometry(QtCore.QRect(40, 610, 150, 50)) self.Manual.setObjectName("Manual") self.Manual.setStyleSheet('color: blue') self.Manual.setFont(QtGui.QFont("",13)) self.Auto = QtWidgets.QPushButton(self.centralwidget) self.Auto.setGeometry(QtCore.QRect(425, 610, 150, 50)) self.Auto.setObjectName("Auto") self.Auto.setStyleSheet('color: blue') self.Auto.setFont(QtGui.QFont("",13)) self.Register_User = QtWidgets.QPushButton(self.centralwidget) self.Register_User.setGeometry(QtCore.QRect(815, 610, 150, 50 )) self.Register_User.setObjectName("Register User") self.Register_User.setStyleSheet('color: blue') self.Register_User.setFont(QtGui.QFont("",13)) self.Reset_gui = QtWidgets.QPushButton(self.centralwidget) self.Reset_gui.setGeometry(QtCore.QRect(1040, 625, 110, 40)) self.Reset_gui.setObjectName("Reset Gui") self.Reset_gui.setStyleSheet('color: red') self.Reset_gui.setFont(QtGui.QFont("",12)) self.Quiter_gui = QtWidgets.QPushButton(self.centralwidget) self.Quiter_gui.setGeometry(QtCore.QRect(1230, 625, 80, 40)) self.Quiter_gui.setObjectName("Quit") self.Quiter_gui.setStyleSheet('color: red') self.Quiter_gui.setFont(QtGui.QFont("",12)) self.camerashow = QtWidgets.QLabel(self.centralwidget) 53 self.camerashow.setGeometry(QtCore.QRect(40, 70, 925, 520)) self.camerashow.setText("") self.camerashow.setScaledContents(True) self.camerashow.setObjectName("camerashow") self.show_text = QtWidgets.QLabel(self.centralwidget) self.show_text.setGeometry(QtCore.QRect(40, 10, 100, 40)) font = QtGui.QFont() font.setPointSize(22) font.setBold(True) font.setWeight(125) self.show_text.setFont(font) self.show_text.setTextFormat(QtCore.Qt.AutoText) self.show_text.setObjectName("show_text") self.show_text.setStyleSheet('color: black') self.Notification_day = QtWidgets.QLabel(self.centralwidget) self.Notification_day.setGeometry(QtCore.QRect(1020, 60, 200, 30)) font = QtGui.QFont() font.setPointSize(15) font.setBold(True) font.setWeight(75) self.Notification_day.setFont(font) self.Notification_day.setTextFormat(QtCore.Qt.AutoText) self.Notification_day.setObjectName("Notification_day") self.Notification_day.setStyleSheet('color: black') self.Notification_time= QtWidgets.QLabel(self.centralwidget) self.Notification_time.setGeometry(QtCore.QRect(1020, 90, 200, 50)) font = QtGui.QFont() font.setPointSize(15) font.setBold(True) font.setWeight(75) self.Notification_time.setFont(font) self.Notification_time.setTextFormat(QtCore.Qt.AutoText) self.Notification_time.setObjectName("Notification_time") self.Notification_time.setStyleSheet('color: black') self.Results_text = QtWidgets.QTextBrowser(self.centralwidget) self.Results_text.setGeometry(QtCore.QRect(1010, 150, 300, 300)) self.Results_text.setObjectName("Results_text") self.Results_text.setStyleSheet('color: black') self.Results_text.setFont(QtGui.QFont("",13)) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow) 54 self.menubar.setGeometry(QtCore.QRect(0, 0, 1172, 25)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) self.Manual.clicked.connect(self.CarManual_RecognitonFace) self.Auto.clicked.connect(self.CarAuto_RecognitonFace) self.Register_User.clicked.connect(self.secondscr) self.Quiter_gui.clicked.connect(sys.exit) self.Reset_gui.clicked.connect(self.Reset_loadcamera) self.cameraOpen() self.display_time() def retranslateUi(self, MainWindow): self._translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(self._translate("DRIVER MONITORING SYSTEM", "DRIVER MONITORING SYSTEM")) self.show_text.setText(self._translate("DRIVER MONITORING SYSTEM", "Car")) self.Manual.setText(self._translate("DRIVER MONITORING SYSTEM", "Manual")) self.Auto.setText(self._translate("DRIVER MONITORING SYSTEM", "Auto")) self.Register_User.setText(self._translate("DRIVER MONITORING SYSTEM", "Register \nUser")) self.Reset_gui.setText(self._translate("DRIVER MONITORING SYSTEM", "Reset Gui")) self.Quiter_gui.setText(self._translate("DRIVER MONITORING SYSTEM", "Quit")) def secondscr(self): self.capture.release() time.sleep(0.1) self.Form = QtWidgets.QWidget() self.ui = Ui_AddFaceDB() self.ui.setupUi(self.Form) self.Form.show() def cameraOpen (self): self.count_frame = self.capture = cv2.VideoCapture(0) self.timer = QTimer() self.timer.timeout.connect(self.display_video_stream) self.timer.start(0) 55 def Reset_loadcamera (self): f = open("models/database_Facebank.json", 'r') feat = json.load(f) for i in range (len (feat)): self.faces_bank[feat[i]["face_id"]] = feat[i] self.capture = cv2.VideoCapture(0) self.count_frame = self.Results_text.clear() self.timer = QTimer() self.timer.timeout.connect(self.display_video_stream) self.timer.start(0) def CarAuto_RecognitonFace (self): self.FaceDetectRecognition = True def CarManual_RecognitonFace (self): self.FaceDetectRecognition = False def display_video_stream(self): self.count_frame =self.count_frame +1 ret, self.frame = self.capture.read() if not (not ret): if self.count_frame % == 0: image_detect= self.frame.copy() image_show= image_detect.copy() image_crop= image_detect.copy() if self.FaceDetectRecognition == True: (h, w) = image_detect.shape[:2] blob = cv2.dnn.blobFromImage(cv2.resize(image_detect, (300, 300)), 1.0,(300, 300), (104.0, 177.0, 123.0)) self.net_detect.setInput(blob) detections = self.net_detect.forward() for i in range(0, detections.shape[2]): confidence = detections[0, 0, i, 2] if confidence > 0.55: box = detections[0, 0, i, 3:7] * np.array([w, h, w, h]) (startX, startY, endX, endY) = box.astype("int") startX = max(0, startX) startY = max(0, startY) endX = min(w, endX) endY = min(h, endY) face = image_crop[startY:endY, startX:endX] face_resize = cv2.resize(face, (112, 112)) feature_face = self.model_recognition.get_feature(face_resize) temp_score, temp_index = 56 cosine_face(feature_face, self.faces_bank) if temp_score > 0.6: name_face = "New Face" else: name_face= self.faces_bank[temp_index]['name'] cv2.putText(image_show,name_face, (startX, startY), cv2.FONT_HERSHEY_SIMPLEX, 0.8, (255, 0, 0), 2) cv2.rectangle(image_show, (startX, startY), (endX, endY), (0, 255, 0), 2) self.Results_text.clear() self.Results_text.append(str("Name: ") +name_face) self.Results_text.append(str("\n")) self.Results_text.append(str("Status: Hi ") +name_face) self.Results_text.append(str("\n")) try: index= Array_Name.index(name_face) self.Results_text.append(str("Position: ") + str(index) ) except: self.Results_text.append(str("Position: None") ) frame_color = cv2.cvtColor(image_show, cv2.COLOR_BGR2RGB) frame_show = QImage(frame_color, frame_color.shape[1], frame_color.shape[0], frame_color.strides[0], QImage.Format_RGB888) self.camerashow.setPixmap(QPixmap.fromImage(frame_show)) def display_time(self): day_time = datetime.now().strftime("%d-%m-%Y") time_now = datetime.now().strftime("%H:%M") self.Notification_day.setText(self._translate("DRIVER MONITORING SYSTEM", "Date: " +day_time )) self.Notification_time.setText(self._translate("DRIVER MONITORING SYSTEM", "Time: " +time_now)) self.Notification_day.setStyleSheet('color: green') self.Notification_time.setStyleSheet('color: green') if name == " main ": app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() ui = Ui_MainWindow() ui.setupUi(MainWindow) app.setWindowIcon(QtGui.QIcon('icon.ico')) MainWindow.show() sys.exit(app.exec_()) 57 58 S K L 0 ... nghi? ?n cứu ứng dụng kit Raspberry Pi thực tiễn Đề tài ? ?Ứng dụng xử lý ảnh hệ thống tiện nghi tơ” mơ hình sử dụng kit Raspberry Pi nhận diện khuôn mặt người dùng để điều khiển ghế ô tô Dựa ngôn... hệ thống 44 xi BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐH SƯ PHẠM KỸ THUẬT TPHCM THÔNG TIN KẾT QUẢ NGHI? ?N CỨU CỦA ĐỀ TÀI Thông tin chung: - Tên đề tài: Ứng dụng xử lý ảnh hệ thống tiện nghi ô. .. phát triển tiến không ngừng khoa học kỹ thuật xử lý ảnh đề tài cần quan tâm phát triển Từ nghi? ?n cứu ban đầu ảnh trắng đen, ảnh xám, ảnh màu, xử lý ảnh nghi? ?n cứu chuyên sâu ứng dụng nhiều sống

Ngày đăng: 07/09/2022, 21:37

Tài liệu cùng người dùng

Tài liệu liên quan