Thiết kế hệ thống nhận diện khuôn mặt đóng mở cửa tự động

100 0 0
Thiết kế hệ thống nhận diện khuôn mặt đóng mở cửa tự động

Đ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 CÔNG NGHỆ TP HỒ CHÍ MINH ĐỒ ÁN TỐT NGHIỆP THIẾT KẾ HỆ THỐNG NHẬN DIỆN KHN MẶT ĐĨNG MỞ CỬA TỰ ĐỘNG Ngành: KỸ THUẬT CƠ KHÍ Chuyên ngành: KỸ THUẬT CƠ KHÍ Giảng viên hướng dẫn: T.S Nguyễn Trọng Hải Sinh viên thực hiện: MSSV: Lớp: Tô Vỹ Quang 1711040568 18DCKA2 Trần Trung Dũng 1811040355 18DCKA2 Nguyễn Thành Trung 1811040390 18DCKA2 TP Hồ Chí Minh, ngày 09 tháng 07 năm 2022 BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC CƠNG NGHỆ TP HỒ CHÍ MINH ĐỒ ÁN TỐT NGHIỆP THIẾT KẾ HỆ THỐNG NHẬN DIỆN KHN MẶT ĐĨNG MỞ CỬA TỰ ĐỘNG Ngành: KỸ THUẬT CƠ KHÍ Chuyên ngành: KỸ THUẬT CƠ KHÍ Giảng viên hướng dẫn: T.S Nguyễn Trọng Hải Sinh viên thực hiện: MSSV: Lớp: Tô Vỹ Quang 1711040568 18DCKA2 Trần Trung Dũng 1811040355 18DCKA2 Nguyễn Thành Trung 1811040390 18DCKA2 TP Hồ Chí Minh, ngày 09 tháng 07 năm 2022 LỜI CAM ĐOAN Chúng em xin cam đoan đề tài “Thiết kế hệ thống nhận diện khn mặt đóng mở cửa tự động” tiến hành cách minh bạch, công khai Mọi thứ dựa cố gắng nỗ lực thành viên nhóm với giúp đỡ không nhỏ từ thầy Nguyễn Trọng Hải Các số liệu kết nghiên cứu đưa đồ án trung thực không chép hay sử dụng kết đề tài nghiên cứu tương tự Nếu phát có chép kết nghiên cứu đề đề tài khác chúng em xin chịu hoàn toàn trách nhiệm Tp Hồ Chí Minh, ngày 09 tháng 07 năm 2022 i LỜI CẢM ƠN Luận văn thử thách cuối sau bốn năm học Đại Học Công Nghệ Thành Phố Hồ Chí Minh Vì vậy, tất kiến thức mà chúng em dạy q trình học tập Khóa luận hội để chúng em áp dụng kiến thức vào thực tế Hơn nữa, luận văn giúp chúng em nâng cao kiến thức so sánh kiến thức với kinh nghiệm đúc kết từ thực tế Máy tách vỏ nha đam hoàn thành nghiên cứu chế tạo Máy chúng em khơng hồn hảo sản xuất nỗ lực cao hướng dẫn nhiệt tình cố vấn Cảm ơn gia đình tin tưởng, ủng hộ tạo điều kiện tốt cho chúng em Cảm ơn thầy Nguyễn Trọng Hải sát cánh, giúp đỡ chúng em nhiều Xin trân trọng kính gửi tới thầy giáo Viện Kỹ Thuật giúp đỡ chúng em hoàn thành luận văn Chúng em cảm ơn tất bạn bè giúp đỡ chia sẻ khó khăn với chúng em Một lần cảm ơn tất ii TÓM TẮT Đề tài “Thiết kế hệ thống nhận diện khn mặt đóng mở cửa tự động” hệ thống tự động mở cửa xác nhận khuôn mặt người có sở liệu tạo trước Hệ thống liệu lập trình phần mềm Python, điều khiển hệ thống kit Raspberry Pi dùng Camera Pi làm thiết bị thu nhận hình ảnh Sử dụng thuật tốn Haar-like để phát khn mặt khung hình trích xuất đặc trưng hình ảnh thuật tốn HOG phân loại liệu Sau gửi tín hiệu đến Raspberry Pi điều khiển hệ thống sau nhận diện iii ABSTRACT The theme “Design of an automatic door opening and closing face recognition system” is a system that automatically opens the door when confirming a person’s face is in a previously created database The system is programmed on Python software, controls the system with a Raspberry Pi kit and uses Camera Pi as an image receiver Use the Haar-like algorithm to detect faces in the frame and extract image characteristics using the HOG algorithm that categorizes the data Then send a signal to Raspberry that controls the system after identification iv option_training: 'C: Training', option_back: 'B: Back', } menu_enter_password = { option_password_title: "", option_delete_password: 'D: Delete', option_confirm_password: 'C: Confirm', option_back: 'B: Back', option_free_option: "your pass: " } def init (self): super(). init () self._run_flag = True def run(self): is_show_menu = False while self._run_flag: try: key=keypad.readKey(keypad.col_list, keypad.row_list) if(key == keypad.show_menu_key): self.print_menu(self.menu_main_options) is_show_menu = True if(key == keypad.exit_program): # self.keypad_input_signal.emit(key) os._exit(0) 71 if is_show_menu: option = '' try: option = int(key) except: print('Wrong input Please enter a number ') #Check what choice was entered and act accordingly if option == self.option_add_new: time.sleep(1) self.add_new_option() self.print_menu(self.menu_main_options) elif option == self.option_delete_data: time.sleep(1) self.delete_data_option() self.print_menu(self.menu_main_options) elif option == self.option_change_password: time.sleep(1) self.change_password_option() self.print_menu(self.menu_main_options) elif option == self.option_hide_menu: print("hide/show") self.hide_menu_option() is_show_menu = False elif option == self.option_open_door: time.sleep(1) print("option_open_door") self.open_door() 72 self.print_menu(self.menu_main_options) else: print('Invalid option Please enter a number between and 4.') except KeyboardInterrupt: GPIO.cleanup() sys.exit() def add_new_option(self): print("add_new_option") admin_pass = self.get_password_from_file() input_pass = self.get_password_authentication("add new") if input_pass == None: return if(input_pass == admin_pass): data_menu = self.menu_addnew_options self.send_text_main_screen("successfully") time.sleep(2) self.print_menu(data_menu) while True: try: key=keypad.readKey(keypad.col_list, keypad.row_list) if key != None: if key is keypad.capture_key: print("capture") self.send_text_main_screen(keypad.capture_key) if key is keypad.training_key: self.send_text_main_screen(keypad.training_key) print("training") 73 return time.sleep(0.3) # gives user enoght time to release without having double inputs except KeyboardInterrupt: GPIO.cleanup() sys.exit() else: self.send_text_main_screen("password false") time.sleep(2) def get_password_authentication(self, title): data_menu = self.menu_enter_password data_menu[self.option_password_title] = title self.print_menu(data_menu) password = "" while True: try: key=keypad.readKey(keypad.col_list, keypad.row_list) if key != None: if key not in keypad.function_keys: password = password + key data_menu[self.option_free_option] = "your password:\n" + password self.print_menu(data_menu) if key is keypad.delete_key: len_key = len(password) if len_key > 0: 74 password = password[:len_key-1] data_menu[self.option_free_option] = "your password:\n" + password self.print_menu(data_menu) if key is keypad.back_key: return None if key is keypad.confirm_key: return password time.sleep(0.3) # gives user enoght time to release without having double inputs except KeyboardInterrupt: GPIO.cleanup() sys.exit() def delete_data_option(self): print("delete_data_option") admin_pass = self.get_password_from_file() input_pass = self.get_password_authentication("delete") if input_pass == None: return if(input_pass == admin_pass): time.sleep(2) self.send_text_main_screen(keypad.delete_key) time.sleep(2) self.send_text_main_screen("delete done") time.sleep(2) else: self.send_text_main_screen("password false") 75 time.sleep(2) def open_door(self): admin_pass = self.get_password_from_file() input_pass = self.get_password_authentication("open door") if input_pass == None: return if(input_pass == admin_pass): self.open_door_signal.emit() time.sleep(2) self.send_text_main_screen("door is open") time.sleep(2) else: self.send_text_main_screen("password false") time.sleep(2) def change_password_option(self): print("change_password_option") admin_pass = self.get_password_from_file() input_pass = self.get_password_authentication("old pass") if input_pass == None: return if(input_pass == admin_pass): time.sleep(2) newpass = self.get_password_authentication("new pass") if newpass == None: self.send_text_main_screen("cancel") 76 time.sleep(2) return if len(newpass) < 4: self.send_text_main_screen("password \ntoo short") time.sleep(2) return self.save_password_to_file(newpass) self.send_text_main_screen("change password \nsuccessfully") time.sleep(2) def hide_menu_option(self): self.keypad_input_signal.emit("") print("hide_menu_option") def print_menu(self, menu): global data_lcd self.data_lcd = "" for key in menu.keys(): self.data_lcd = self.data_lcd + menu[key] + "\n" self.keypad_input_signal.emit(self.data_lcd) def get_password_from_file(self): with open('password.txt', 'r') as f: return f.read() def save_password_to_file(self, password): 77 with open('password.txt', 'w') as f: f.write(password) def send_text_main_screen(self, text): self.keypad_input_signal.emit(text) def stop(self): """Sets run flag to False and waits for thread to finish""" self._run_flag = False self.wait() class App(QWidget): thread = VideoThread() name_save = "test" # is_capture_new = True showRecognize = True password_input = "" create_new_name = True keypadThread = KeypadThread() motorThread = MotorControlThread() def init (self): super(). init () 78 # self.init_variables() # self.setWindowState(Qt.WindowFullScreen) self.setWindowTitle("Face Rec") self.disply_width = 300 self.display_height = 300 self.image_label = QLabel(self) self.image_label.resize(300, 300) self.image_label.setScaledContents(True) self.image_label.move(0, 0) self.textLabel = QLabel('Webcam') self.thread.change_pixmap_signal.connect(self.update_image) self.thread.open_door_signal.connect(self.opendoor) self.thread.start() self.keypadThread.keypad_input_signal.connect(self.keypad_update) self.keypadThread.open_door_signal.connect(self.opendoor) self.keypadThread.start() self.motorThread.start() def closeEvent(self, event): self.thread.stop() event.accept() 79 def del_all_user(self): self.thread.del_all_user() def take_snapshot(self): print("take_snapshot") self.thread.take_snapshot_enable() def training_data(self): print("[INFO] start processing faces ") imagePaths = list(paths.list_images("dataset")) # filter image paths if they are not images # just get image path contain name_save imagePaths = [p for p in imagePaths if self.name_save in p] print("imagePaths", imagePaths) encodingsP = "encodings.pickle" data = pickle.loads(open(encodingsP, "rb").read()) # initialize the list of known encodings and known names knownEncodings = data["encodings"] knownNames = data["names"] # loop over the image paths for (i, imagePath) in enumerate(imagePaths): print("imagePath", imagePath, "i", i) # extract the person name from the image path print("[INFO] processing image {}/{}".format(i + 1, len(imagePaths))) name = imagePath.split(os.path.sep)[-2] image = cv2.imread(imagePath) 80 rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) boxes = face_recognition.face_locations(rgb, model="hog") encodings = face_recognition.face_encodings(rgb, boxes) for encoding in encodings: # check name not exist in knownNames print("name", name) if name not in knownNames: # add name to knownNames knownNames.append(name) # add encoding to knownEncodings knownEncodings.append(encoding) # dump the facial encodings + names to disk print("[INFO] serializing encodings ") data = {"encodings": knownEncodings, "names": knownNames} f = open("encodings.pickle", "wb") f.write(pickle.dumps(data)) f.close() # update user list list_users = self.thread.get_user_list() def tolerance_option_button_change_value(self, value): print("option_button_change_value", self.option_button.currentText()) self.thread.set_tolerance(float(self.option_button.currentText())) # def show_alert(timeout, text): 81 @pyqtSlot(np.ndarray) def update_image(self, cv_img): """Updates the image_label with a new opencv image""" qt_img = self.convert_cv_qt(cv_img) self.image_label.setPixmap(qt_img) @pyqtSlot() def opendoor(self): self.motorThread.turn_on_motor() @pyqtSlot(str) def keypad_update(self, key): if key == keypad.capture_key: if self.create_new_name: self.create_new_name = False self.name_save = str(random.randrange(1000, 10000)) self.thread.set_name(self.name_save) self.take_snapshot() self.thread.setText("capture: " + str(self.thread.getIndexImg() + 1) + "\nname: " + self.name_save) elif key == keypad.training_key: self.training_data() self.create_new_name = True self.thread.setText("training data \n done") self.thread.reload_list() elif key == keypad.delete_key: 82 self.thread.setText("delete all data") self.thread.del_all_user() else: self.thread.setText(key) # global showRecognize, name_save, create_new_name # print("key: ", key) # if(key == keypad.add_new_key): # print("add_new_key") # self.thread.setText("#: enter, D: del\nenter password: ") # elif(key == keypad.enter_key): # print("enter_key") # os._exit(0) # elif(key == keypad.capture_key): # print("capture_key face") # if self.create_new_name: # self.create_new_name = False # self.name_save = str(random.randrange(1000, 10000)) # self.thread.setText("capture: " + str(self.thread.getIndexImg() + 1) + "\nname: " + self.name_save) # self.thread.set_name(self.name_save) # self.take_snapshot() # elif(key == keypad.recognition_enable_key): # print("recognition_enable_key") # self.showRecognize = not self.showRecognize # if self.showRecognize: # # self.thread.setText("recognize") else: 83 # # self.thread.setText("camera") self.thread.set_recognize_user(self.showRecognize) # elif(key == keypad.training_key): # print("training_key face") # self.thread.setText("training data") # self.thread.restart_img_counter() # self.training_data() # self.thread.setText("training data \n done") # self.create_new_name = True # elif(key == keypad.delete_key): # print("delete_key face") # self.thread.setText("delete all data") # self.thread.del_all_user() # else: # password_input = key # self.thread.setText("password: \n" + password_input) def convert_cv_qt(self, cv_img): """Convert from an opencv image to QPixmap""" rgb_image = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB) h, w, ch = rgb_image.shape bytes_per_line = ch * w convert_to_Qt_format = QtGui.QImage( rgb_image.data, w, h, bytes_per_line, QtGui.QImage.Format_RGB888) p = convert_to_Qt_format.scaled( 84 self.disply_width, self.display_height, Qt.KeepAspectRatio) return QPixmap.fromImage(p) if name == " main ": app = QApplication(sys.argv) a = App() a.show() sys.exit(app.exec_()) 85

Ngày đăng: 31/08/2023, 08:48

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

Tài liệu liên quan