人脸库对比(百度人脸识别)(Java版)

article/2025/10/9 18:27:25

系列文章:
    一、JavaFX摄像:https://blog.csdn.net/haoranhaoshi/article/details/85880893
    二、JavaFX拍照:https://blog.csdn.net/haoranhaoshi/article/details/85930981
    三、百度人脸识别--人脸对比:https://blog.csdn.net/haoranhaoshi/article/details/85954440
    四、人脸库对比:https://blog.csdn.net/haoranhaoshi/article/details/86302313

补充:
    解决WebCam框架中摄像模糊:https://blog.csdn.net/haoranhaoshi/article/details/87713878
    Java 摄像(依靠开源框架WebCam)(Swing方式):https://blog.csdn.net/haoranhaoshi/article/details/87714541
    
下载资源:

    Java摄像开源框架(文档、案例、Jar包)、个人项目工程(JavaFX)、原始实例(JavaFX):https://download.csdn.net/download/haoranhaoshi/10898408

    摄像、拍照、人脸识别、人脸库对比: https://download.csdn.net/download/haoranhaoshi/10911079    

本篇在系列文章三的基础上进行扩展,拍照存储后产生人脸库,人脸图片保存时命名为个人姓名,点击人脸识别在人脸库中进行对比,展示对比结果。如果人脸库中有重复的人脸,也可在对比结果中检测到。
人脸库对比效果:


项目为IDEA搭建,终极工程可在如下地址下载(包括Java摄像、拍照、人脸识别、人脸库对比):
https://download.csdn.net/download/haoranhaoshi/10911079
(为了赚两积分,就不上GitHub了?,当然,Github上也有不少博主优秀工程https://github.com/haoranhaoshi)

import com.github.sarxos.webcam.Webcam;
import facematch.FaceMatch;
import javafx.application.Application;
import javafx.application.Platform;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.value.ObservableValue;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.concurrent.Task;
import javafx.embed.swing.SwingFXUtils;
import javafx.geometry.Insets;
import javafx.geometry.Orientation;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.FlowPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
import org.json.JSONException;
import org.json.JSONObject;import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;/*** 推荐JDK8及以上(适应lambda表达式),需导入lib下三个Jar包,支持摄像头选择、开始摄像、停止摄像、拍照存储、人脸识别*/
public class MyFaceMatch extends Application {/*** 拍照存储的文件路径*/String cameraImgFolderPath = new File("").getAbsolutePath() + "/src/userimage/";/*** 人脸识别临时存储的文件路径*/String faceImgFolderPath = new File("").getAbsolutePath() + "/src/tempimage/";private class WebCamInfo {private String webCamName;private int webCamIndex;public String getWebCamName() {return webCamName;}public void setWebCamName(String webCamName) {this.webCamName = webCamName;}public int getWebCamIndex() {return webCamIndex;}public void setWebCamIndex(int webCamIndex) {this.webCamIndex = webCamIndex;}@Overridepublic String toString() {return "摄像头" + (Integer.parseInt(webCamName.split("Integrated Webcam ")[1]) + 1);}}private FlowPane bottomCameraControlPane;private FlowPane topPane;private BorderPane root;private String cameraListPromptText = "选择摄像头:";private ImageView imgWebCamCapturedImage;private Webcam webCam = null;private boolean stopCamera = false;private BufferedImage grabbedImage;private ObjectProperty<Image> imageProperty = new SimpleObjectProperty<Image>();private BorderPane webCamPane;private Button btnCamreaStop;private Button btnCamreaStart;private Button btnCamreaGetImage;private Button btnFaceMatch;@Overridepublic void start(Stage primaryStage) {primaryStage.setTitle("摄像");root = new BorderPane();topPane = new FlowPane();topPane.setAlignment(Pos.CENTER);topPane.setHgap(20);topPane.setOrientation(Orientation.HORIZONTAL);topPane.setPrefHeight(40);root.setTop(topPane);webCamPane = new BorderPane();webCamPane.setStyle("-fx-background-color: #ccc;");imgWebCamCapturedImage = new ImageView();webCamPane.setCenter(imgWebCamCapturedImage);root.setCenter(webCamPane);createTopPanel();bottomCameraControlPane = new FlowPane();bottomCameraControlPane.setOrientation(Orientation.HORIZONTAL);bottomCameraControlPane.setAlignment(Pos.CENTER);bottomCameraControlPane.setHgap(20);bottomCameraControlPane.setVgap(10);bottomCameraControlPane.setPrefHeight(40);bottomCameraControlPane.setDisable(true);createCameraControls();root.setBottom(bottomCameraControlPane);primaryStage.setScene(new Scene(root));primaryStage.setHeight(700);primaryStage.setWidth(600);primaryStage.centerOnScreen();primaryStage.show();Platform.runLater(() ->setImageViewSize());}protected void setImageViewSize() {double height = webCamPane.getHeight();double width = webCamPane.getWidth();imgWebCamCapturedImage.setFitHeight(height);imgWebCamCapturedImage.setFitWidth(width);imgWebCamCapturedImage.prefHeight(height);imgWebCamCapturedImage.prefWidth(width);imgWebCamCapturedImage.setPreserveRatio(true);}private void createTopPanel() {int webCamCounter = 0;Label lbInfoLabel = new Label("选择摄像头:");ObservableList<WebCamInfo> options = FXCollections.observableArrayList();topPane.getChildren().add(lbInfoLabel);for (Webcam webcam : Webcam.getWebcams()) {WebCamInfo webCamInfo = new WebCamInfo();webCamInfo.setWebCamIndex(webCamCounter);webCamInfo.setWebCamName(webcam.getName());options.add(webCamInfo);webCamCounter++;}ComboBox<WebCamInfo> cameraOptions = new ComboBox<>();cameraOptions.setItems(options);cameraOptions.setPromptText(cameraListPromptText);cameraOptions.getSelectionModel().selectedItemProperty().addListener((ObservableValue<? extends WebCamInfo> arg0, WebCamInfo arg1, WebCamInfo arg2) -> {if (arg2 != null) {System.out.println("WebCam Index: " + arg2.getWebCamIndex() + ": WebCam Name:" + arg2.getWebCamName());initializeWebCam(arg2.getWebCamIndex());}});topPane.getChildren().add(cameraOptions);}protected void initializeWebCam(final int webCamIndex) {Task<Void> webCamTask = new Task<Void>() {@Overrideprotected Void call() {if (webCam != null) {disposeWebCamCamera();}webCam = Webcam.getWebcams().get(webCamIndex);webCam.open();startWebCamStream();return null;}};Thread webCamThread = new Thread(webCamTask);webCamThread.setDaemon(true);webCamThread.start();bottomCameraControlPane.setDisable(false);btnCamreaStart.setDisable(true);}protected void startWebCamStream() {stopCamera = false;Task<Void> task = new Task<Void>() {@Overrideprotected Void call() {while (!stopCamera) {try {if ((grabbedImage = webCam.getImage()) != null) {Platform.runLater(() -> {Image mainiamge = SwingFXUtils.toFXImage(grabbedImage, null);imageProperty.set(mainiamge);});grabbedImage.flush();}} catch (Exception e) {e.printStackTrace();}}return null;}};Thread th = new Thread(task);th.setDaemon(true);th.start();imgWebCamCapturedImage.imageProperty().bind(imageProperty);}private void createCameraControls() {btnCamreaStop = new Button();btnCamreaStop.setOnAction(event -> stopWebCamCamera());btnCamreaStop.setText("停止摄像");btnCamreaStart = new Button();btnCamreaStart.setOnAction(event -> startWebCamCamera());btnCamreaStart.setText("开始摄像");btnCamreaGetImage = new Button();btnCamreaGetImage.setOnAction(event -> getImagine());btnCamreaGetImage.setText("拍照存储");btnFaceMatch = new Button();btnFaceMatch.setOnAction(event -> faceMatch());btnFaceMatch.setText("人脸识别");bottomCameraControlPane.getChildren().add(btnCamreaStart);bottomCameraControlPane.getChildren().add(btnCamreaStop);bottomCameraControlPane.getChildren().add(btnCamreaGetImage);bottomCameraControlPane.getChildren().add(btnFaceMatch);}protected void faceMatch(){Image image = imgWebCamCapturedImage.getImage();String faceImgPath = faceImgFolderPath + "tempImg" + ".png";try {File file = new File(faceImgPath);ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);} catch (IOException e) {e.printStackTrace();}File[] fileArray = new File(cameraImgFolderPath).listFiles();String ak = "PSce6S7M7WVRVyIux15iDToC";String sk = "fvzwcYociG2GYnsZppKqEbSlUDQaQ9Sd";List<String> faceMathPersonNameList = new ArrayList<>();for(int i = 0;i < fileArray.length;i++){String personImg = fileArray[i].getName();String storeImgPath = cameraImgFolderPath + personImg;String result = FaceMatch.match(ak, sk, faceImgPath, storeImgPath);try {String score = new JSONObject(result).getJSONObject("result").getString("score");// 阈值为80,高于80分判断为同一人if(Double.parseDouble(score) >= 80){faceMathPersonNameList.add(personImg.split("\\.")[0]);}} catch (JSONException e) {e.printStackTrace();}}String alertContent = "在拍照存储中没有匹配者!";for(int i = 0;i < faceMathPersonNameList.size();i++){String nameAbout = i < faceMathPersonNameList.size() - 1 ? (faceMathPersonNameList.get(i) + "、") : (faceMathPersonNameList.get(i) + "。");alertContent = i == 0 ? ("在拍照存储中找到匹配者,姓名为:" + nameAbout) : (alertContent + nameAbout);}Alert alert = new Alert(Alert.AlertType.INFORMATION, "", ButtonType.CLOSE);alert.setHeaderText(alertContent);alert.show();}protected void getImagine() {Image image = imgWebCamCapturedImage.getImage();ImageView imageView = new ImageView(image);Label label = new Label("图片名称:");TextField textField = new TextField();HBox hBox = new HBox(5);hBox.setAlignment(Pos.CENTER);hBox.getChildren().addAll(label, textField);Button button = new Button("保存");Stage stage = new Stage();button.setOnAction(event -> {try {File file = new File(cameraImgFolderPath + textField.getText() + ".png");ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);} catch (IOException e) {e.printStackTrace();}stage.close();});VBox vBox = new VBox(10);vBox.setAlignment(Pos.CENTER);vBox.setPadding(new Insets(10,10,10,10));vBox.getChildren().addAll(imageView, hBox, button);stage.setScene(new Scene(vBox));stage.show();}protected void disposeWebCamCamera() {stopCamera = true;webCam.close();Webcam.shutdown();btnCamreaStart.setDisable(true);btnCamreaStop.setDisable(true);}protected void startWebCamCamera() {stopCamera = false;startWebCamStream();btnCamreaStop.setDisable(false);btnCamreaStart.setDisable(true);}protected void stopWebCamCamera() {stopCamera = true;btnCamreaStart.setDisable(false);btnCamreaStop.setDisable(true);}public static void main(String[] args) {launch(args);}
}

 


http://chatgpt.dhexx.cn/article/qGEdGdt1.shtml

相关文章

人脸识别接口_DS-K5603-Z 海康威视人员通道人脸识别组件 1万人脸库 10.1英寸LCD触摸显示屏_DS-K5603-Z_DS-K5603-Z...

DS-K5603-Z 海康威视人员通道人脸识别组件 英寸LCD触摸显示屏 支持10000人脸库 支持人脸识别、刷卡或相互组合的识别方式,1:1比对时间≤1S/人,1:N比对时间≤人 DS-K5603-Z DS-K5603-Z海康人脸识别组件海康人脸识别组件 DS-K5603-Z 产品简介 DS-K5603-Z人脸识别组件是一款高…

python+opencv人脸识别(用耶鲁大学的Yale人脸库训练cnn)3

用耶鲁大学的Yale人脸库&#xff0c;里面包含15个人&#xff0c;每人11张照片&#xff0c;主要包括光照条件的变化&#xff0c;表情的变化&#xff0c;接下来我会把自己的几张照片混进去&#xff0c;看看训练过后能不能被神经网络良好的识别。https://blog.csdn.net/weixin_393…

百度智能云人脸库的创建与使用

搜索百度智能云人脸识别云服务 点立即使用,再登百度之类的账号 创建应用 新建组 添加图片

阿里云实现人脸登录(人脸库 OSS)

我自认为不想做curd程序员&#xff0c;但是免不了的会对数据基本原子操作进行处理&#xff0c;项目开发过程中的增删改查少不了的&#xff0c;但是又不甘心于curd下去&#xff0c;所以想要在掌握现有知识的基础上&#xff0c;甚至逼迫自己去学习一些东西&#xff0c;去接触新的…

毕业设计 - 基于JAVA人脸识别管理系统(人脸搜索与人脸库管理)

文章目录 【背景/简介】【技术框架】【核心开发】【功能展示】一、人脸库管理二、人脸识别记录管理 【核心代码】【总结】 基于JAVA的人脸识别管理系统作品分享一下&#xff0c;希望能帮助到有需要的同学们。 【背景/简介】 人脸搜索与人脸库管理主要用在人脸通用场景&#xf…

定位基本方法 3

节点定位方法 3. 基于移动 BS 的定位 在基于静态信标节点的定位方法中&#xff0c;定位系统的定位精度与静态信标节点的部署密度和质量直接相关。为了获得好的定位精度&#xff0c;就需要在部署区域中放置大量的静态信标节点&#xff0c;这势必会导致定位成本的大幅上升。为此…

定位基本方法 1

节点定位方法 1. 节点定位的计算 在 WSNs 的定位中&#xff0c;未知节点通过一定的技术和方法能够获得定位自身所需的坐标、角度或距离信息&#xff0c;从而利用节点位置的计算方法计算自身位置。下面我们将介绍几种较为典型的位置计算方法&#xff1a;三边测量法、三角测量法…

浅谈自适应滤波器---(快速RLS算法)

在上一篇博客中&#xff08;浅谈自适应滤波器&#xff09;我给大家介绍了关于自适应滤波器的一些入门级的知识&#xff0c;并分析了常规RLS算法单次迭代的计算量级为O[N2]&#xff0c;当阶数N增大时相应的计算量显著增大&#xff0c;为了将计算量级降低到O[N]&#xff0c;人们提…

图像处理自适应滤波

图像处理基础(2)&#xff1a;自适应中值滤波器(基于OpenCV实现) 标签&#xff1a; opencv滤波器 2017-02-08 19:44 986人阅读 评论(0) 收藏 举报 分类&#xff1a; DIP&#xff08;8&#xff09; 版权声明&#xff1a;本文为博主原创文章&#xff0c;未经博主允许不得转载…

自适应滤波器及其应用 - 自适应噪声抵消器

传统IIR和FIR滤波器在处理输入信号的过程中滤波器参数固定&#xff0c;当环境发生变化时&#xff0c;滤波器无法实现原先设定的目标。自适应滤波器根据当前自身的状态和环境调整滤波器权系数。 1 自适应滤波器理论 其中&#xff0c;x(n)是输入信号&#xff0c;y(n)是输出信号&…

自适应数字滤波器

文章目录 前言一、自适应滤波器的特点和构成二、最陡下降法三、最小均方算法(LMS)总结 前言 本文的主要内容是自适应数字滤波器的介绍&#xff0c;包含其特点与构成、最陡下降法、最小均方算法以及最小二乘算法等内容。 一、自适应滤波器的特点和构成 自适应滤波器的特点&…

浅谈自适应滤波器---(自适应陷波器)

陷波器顾名思义就是对特定频率的信号有着很强的衰减的滤波器&#xff0c;也即阻带带宽极窄的带阻滤波器。在传统的数字陷波器设计中&#xff0c;为了能使某一频率信号得到足够大的衰减&#xff0c;通常的做法就是把阶数选的足够高来达到很大的衰减&#xff1b;但同时计算量也变…

自适应滤波器及LMS自适应算法的理解

分享一篇以前写现代信号处理的课程论文。 ————————————————————

自适应中值滤波器和自适应局部(均值)滤波器的设计 python+matlab各实现

要求是&#xff1a;自适应中值滤波器和自适应均值滤波器的设计&#xff0c;分别使用python和matlab去实现 一.原理 1.自适应中值滤波器 2.自适应局部滤波器&#xff0c;也叫自适应均值滤波器 二.设计流程 1.自适应中值滤波器 ①生成椒盐噪声 利用rand()函数生成[0,1]的随…

自适应滤波去噪

自适应滤波器具有在未知环境下良好的运作并跟踪输入统计量随时间变化的能力。尽管对于不同的应用有不同的实现结构&#xff0c;但是他们都有一个基本的特征&#xff1a;输入向量X(n)和期望响应d(n)被用来计算估计误差e(n)&#xff0c;即e(n)d(n)-X(n)&#xff0c;并利用此误差信…

自适应滤波(LMS,RLS)

1.背景及相关知识介绍 自适应滤波存在于信号处理、控制、图像处理等许多不同领域&#xff0c;它是一种智能更有针对性的滤波方法&#xff0c;通常用于去噪。 图中x&#xff08;j&#xff09;表示 j 时刻的输入信号值&#xff0c;y&#xff08;j&#xff09;表示 j 时刻的输出信…

自适应滤波

自适应阵列处理是一种空间滤波技术&#xff0c;它包含空间阵列和自通应处理两个部分。根据空时等效性原理&#xff0c;从理论上来讲&#xff0c;时域的各种统计自适应信号处理技术均可应用于空域的自适应阵列处理 自适应滤波已在时域处理中广为应用&#xff0c;其实现可以来用…

matlab编程实现自适应均值滤波和自适应中值滤波

matlab编程实现自适应滤波器 一、自适应均值滤波器1. 原理部分&#xff1a;2. 程序代码3. 结果对比 二、自适应中值滤波1. 原理部分2.程序代码3. 结果对比 一、自适应均值滤波器 1. 原理部分&#xff1a; 加入噪声&#xff1a; 原理&#xff1a; 将图片灰度化&#xff0c;然后…

自适应滤波器之横向滤波器

本文对横向滤波器作以介绍&#xff0c;如有表述不当之处欢迎批评指正。欢迎任何形式的转载&#xff0c;但请务必注明出处。 目录 1. 横向滤波器1.1. 概念1.2. 举例 2. 参考文献 1. 横向滤波器 1.1. 概念 横向滤波器&#xff08;transversal filter&#xff09;&#xff0c;也…

自适应中值滤波及实现

前言 无意中看到了一篇比较老的论文&#xff0c;Adaptive median filters: new algorithms and results。感兴趣的可以下载下来看看。主要就是提出了一种自适应中值滤波算法&#xff0c;这个算法是很经典的中值滤波算法的改进版本&#xff0c;自动选择滤波器的大小&#xff0c…