系列文章:
    一、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);}
}

人脸库对比(百度人脸识别)(Java版)相关推荐

  1. 人工智能,百度AI人脸识别java版

    人工智能,百度AI人脸识别java版 需求:人脸识别登录,人脸就需要有人脸的照片,数据库建一个字段face保存用户人脸的照片,jquery.webcam.js实现调用摄像头拍照,然后后端接受base6 ...

  2. 大华sdk(java)上传人脸图片到人脸库,订阅人脸识别对比

    上传人脸图片到人脸库 controller: @RestController @RequestMapping("/facePicture") public class FacePi ...

  3. 京东商城(360Buy)价格识别 java版

    上一篇介绍到 利用Jsoup抓取各个电商网站的信息 不过有时候会遇到价格是图片的问题 这时候你只能得到一张图片了 如果有个能把图片解析出来那该多爽啊 去百度一搜"京东(360Buy)价格识别 ...

  4. 开源人脸库,免费的人脸识别face recognition

    这个库安装起来稍微有点麻烦 第一步下载微软的VS2019社区版即可 第二部配置c++环境,在VS中配置c++的环境 第三步 pip install cmake pip install dlib pip ...

  5. 百度API提交Java版,让你的网站快速收录提高排名

    作者: C you again,从事软件开发 努力在IT搬砖路上的技术小白 公众号: [C you again],分享计算机类毕业设计源码.IT技术文章.游戏源码.网页模板.程序人生等等.公众号回复 ...

  6. 百度车牌识别API-Python版

    https://www.bilibili.com/read/cv7920227 SDK文档:https://ai.baidu.com/ai-doc/OCR/3k3h7yeqa 支持Python版本:2 ...

  7. 12306登录验证码识别(Java版)

    懒惰是程序员的第一生产力 源码地址 1 服务器性能差,不要频繁请求(做了熔断保护处理) 2 上传标准图片 3 添加了爬虫爬取验证功能,设置了ajax返回数据的css样式 窝在家里没事干- python ...

  8. python车牌识别算法_百度车牌识别API-Python版

    支持Python版本:2.7.+ ,3.+ 安装使用Python SDK有如下方式: 如果已安装pip,执行pip install baidu-aip即可. 如果已安装setuptools,执行pyt ...

  9. 使用百度云接口API和人脸库完成本地合影图片的多人脸识别--V3版接口Python语言

    百度接口人脸检测,识别率很高,而且操作简单.网上百度还未见到借助百度云接口API和人脸库完成本地合影图片的多人脸识别,本人编写的代码可以实现,但觉得不够简洁,代码数还可以精减,欢迎交流. 1.准备工作 ...

  10. 微信小程序之百度人脸识别系统-人脸登录前后端代码

    前面写了人脸注册的功能.现在再来实现人脸登录的功能就要简单得多了,还是先上PHP部分的代码: PHP代码(搜索人脸库并返回对比结果) <?php date_default_timezone_se ...

最新文章

  1. 8.公有继承 保护继承 私有继承
  2. KEILC51警告:WARNING L15: MULTIPLE CALL TO SEGMENT
  3. flink运行原理_浅谈Flink分布式运行时和数据流图的并行化
  4. 页眉中字数未满但自动换行
  5. HDU-1068Girls and Boys(二分匹配)
  6. linux常用命令之压缩打包
  7. 中国联通沃支付echop支付插件
  8. Linux下安装Eclipse的PHP插件(PHPEclipse)
  9. linux添加usb扫描枪,抓取扫描枪扫描数据的案例
  10. Data truncation: Data too long for column 'xxx' at row 1
  11. 采购申请PR和采购订单PO的关系
  12. 图片随鼠标滑轮滚动变大变小
  13. 一篇文章搞懂设计模式
  14. ios点击大头针气泡不弹出_高德 ios 自定义气泡添加点击事件无效问题
  15. 第95篇 ES之安装Elastica及总结安装Elastica
  16. 满意度模型及其应用——客户满意度
  17. 破解工具ida解决乱码问题
  18. 这些超级好用的浏览器插件,还有很多人都不知道
  19. 阿里云服务器如何开放端口
  20. 结构化程序设计和面向对象程序设计的特点及优缺点

热门文章

  1. vue+springboot实现登录验证码(前后端分离)
  2. Java Hook简洁实用教程
  3. linux模拟发包工具,linux发包软件-线不是一个压力测试工具的linux以上收缩服务器可...
  4. 3500个常用汉字列表
  5. Java练手小游戏集结,你还在等什么
  6. Office文件格式兼容包FileFormatConverters(office 2010)
  7. XP系统安装python
  8. ajax和jquery教程pdf,jquery ajax教程pdf
  9. 贪心算法及几个常用的例题
  10. 天锐绿盾加密软件如何制作外发文件