模式识别:原理、方法与应用详解

3星 · 超过75%的资源 需积分: 10 5 下载量 78 浏览量 更新于2024-08-02 收藏 379KB PPT 举报
"Pattern Recognition.ppt"是一份关于模式识别的重要学习资料,该主题深入探讨了如何让机器理解环境,识别出感兴趣的模式并做出合理的决策。模式识别是计算机科学中的一个重要分支,它关注于机器如何通过观察和学习区分不同类别的模式,如指纹图像、手写笔迹、人脸或语音信号等。 课程大纲主要包括以下几个部分: 1. 模式识别简介:介绍模式识别的基本概念,即研究如何让计算机从复杂环境中提取有用信息,区分目标对象,并基于这些信息进行决策。 2. 基本概念: - 识别(Recognition):核心任务是判断输入是否属于某个预定义的类别。 - 决策(Decision): 根据识别结果做出判断或选择行动。 - 学习(Learning): 计算机通过经验或数据调整其识别能力的过程。 - 普适、推广、概括(Generalization): 使模型能够在未见过的新数据上表现良好,能够从已知模式中推断未知模式的能力。 3. 模式识别方法: - 模版匹配: 对于每个类别创建模板,通过计算输入样本与模板之间的相似度或距离进行匹配,简单直接但适应性较差。 - 统计方法: 基于大量训练数据,构建决策边界来区分不同的类别,如贝叶斯分类和判别分析。 - 句法方法: 通过分解复杂模式为基本元素(基元),利用规则或语法结构进行模式识别。 4. 与其他学科的关系:模式识别与统计学、人工智能、机器学习以及运筹学等领域紧密相连,这些学科提供了不同的理论和技术支持。 5. 模式识别系统流程: - 数据获取与预处理: 从实际环境中获取数据,并进行必要的清洗和标准化。 - 数据表达: 将原始数据转换为机器可以理解和处理的形式。 - 决策过程: 根据识别算法执行决策,输出最终的结果。 这份PPT提供了全面且深入的模式识别基础和实践内容,适合对这一领域有兴趣的学生、研究人员和工程师深入学习和理解。通过学习,读者将掌握如何设计和实现有效的模式识别系统,应用于各种实际场景,如图像处理、语音识别、自然语言处理等领域。

import cv2 import face_recognition import numpy as np from PIL import Image, ImageDraw,ImageFont video_capture = cv2.VideoCapture(r'C:/Users/ALIENWARE/123.mp4')#如果输入是(0)为摄像头输入 #现输入为MP4进行识别检测人脸 first_image = face_recognition.load_image_file("1.jpg") first_face_encoding = face_recognition.face_encodings(first_image)[0] Second_image = face_recognition.load_image_file("2.jpg") Second_face_encoding = face_recognition.face_encodings(Second_image)[0] third_image = face_recognition.load_image_file("3.jpg") third_face_encoding = face_recognition.face_encodings(third_image)[0] inside_face_encodings = [first_face_encoding,Second_face_encoding,third_face_encoding] inside_face_names = ['A','B','C'] face_locations = [] face_encodings = [] face_names = [] process_this_frame = True while True: ret, frame = video_capture.read() small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25) rgb_small_frame = small_frame[:, :, ::-1] if process_this_frame: face_locations = face_recognition.face_locations(rgb_small_frame) face_encodings = face_recognition.face_encodings(rgb_small_frame, face_locations) face_names = [] for face_encoding in face_encodings: matches = face_recognition.compare_faces(inside_face_encodings, face_encoding) name = '未录入人脸' if True in matches: first_match_index = matches.index(True) name = inside_face_names[first_match_index] face_names.append(name) process_this_frame = not process_this_frame for (top, right, bottom, left), name in zip(face_locations, face_names): top *= 4 right *= 4 bottom *= 4 left *= 4 cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2) img_pil = Image.fromarray(frame) draw = ImageDraw.Draw(img_pil) fontStyle = ImageFont.truetype("C:/Windows/Fonts/simsun.ttc", 32, encoding="utf-8") draw.text((left + 6, bottom - 6), name, (0, 200, 0), font=fontStyle) frame = np.asarray(np.array(img_pil)) cv2.imshow('face_out', frame) if cv2.waitKey(1) & 0xFF == ord('q'): #退出需要按下Q键否则内核会崩溃 break video_capture.release() cv2.destroyAllWindows()

2023-06-07 上传

import face_recognition import cv2 import os unknow_people_list = [i for i in os.listdir('unknow_people') if (i.endswith('.jpg')) or (i.endswith('.png')) or (i.endswith('.jpeg'))] know_people_list = [i for i in os.listdir('know_people') if (i.endswith('.jpg')) or (i.endswith('.png')) or (i.endswith('.jpeg'))] def face_select(): for unknow_people in unknow_people_list: # 读取待识别图片 unknow = face_recognition.load_image_file('unknow_people/' + unknow_people) # 将待识别图片转化为特征向量 unknow_encode = face_recognition.face_encodings(unknow)[0] flag = False for know_people in know_people_list: # 读取计算机已经认识的图片 know = face_recognition.load_image_file('know_people/' + know_people) # 获得面部位置 face_location1 = face_recognition.face_locations(know) face_location2 = face_recognition.face_locations(unknow) # 提取面部关键点 face_landmarks_list1 = face_recognition.face_landmarks(know) face_landmarks_list2 = face_recognition.face_landmarks(unknow) # 图片转化为特征向量 know_encode = face_recognition.face_encodings(know)[0] # 两张图片进行比较的结果 res = face_recognition.compare_faces([know_encode], unknow_encode, tolerance=0.5) if res[0]: flag = True name = know_people.split(".")[0] break if flag: print(f'{name}匹配成功!') else: print(f'匹配失败') name = "UNKNOWN" # 绘制人脸特征点和矩形框 for (x1, y1, w1, h1) in face_location1: cv2.rectangle(know, (y1, x1), (h1, w1), (255, 0, 0), 2) cv2.putText(know, name, (y1 - 10, x1 - 10), cv2.FONT_HERSHEY_COMPLEX, 0.8, (0, 255, 0), 2) for face_landmarks in face_landmarks_list1: for facial_feature in face_landmarks.keys(): for pt_pos in face_landmarks[facial_feature]: cv2.circle(know, pt_pos, 1, (192, 192, 192), 2) for (x1, y1, w1, h1) in face_location2: cv2.rectangle(unknow, (y1, x1), (h1, w1), (255, 0, 0), 2) cv2.putText(unknow, name, (y1 - 10, x1 - 10), cv2.FONT_HERSHEY_COMPLEX, 0.8, (0, 255, 0), 2) for face_landmarks in face_landmarks_list2: for facial_feature in face_landmarks.keys(): for pt_pos in face_landmarks[facial_feature]: cv2.circle(unknow, pt_pos, 1, (192, 192, 192), 2) # 显示图片 cv2.imshow("known", know) cv2.imshow("unknown", unknow) cv2.waitKey(0) if __name__ == '__main__': face_select()

2023-06-02 上传