欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java調(diào)用計算機攝像頭拍照實現(xiàn)過程解析

 更新時間:2020年05月26日 10:52:46   作者:明月心~  
這篇文章主要介紹了Java調(diào)用計算機攝像頭拍照實現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

Java調(diào)用計算機攝像頭照相(Rest API的頁面操作)

使用開源組件webcam-capture:https://github.com/sarxos/webcam-capture

項目源碼GitHub:https://github.com/muphy1112/RuphyRecorder

本例子使用基于Java rest API的頁面操作,方便遠程拍照

新建Spring Boot項目

pop.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.2.5.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <groupId>me.muphy</groupId>
  <artifactId>recorder</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <name>recorder</name>
  <description>Demo project for Spring Boot</description>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>

    <dependency>
      <groupId>com.github.sarxos</groupId>
      <artifactId>webcam-capture</artifactId>
      <version>0.3.12</version>
    </dependency>

    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-test</artifactId>
      <scope>test</scope>
      <exclusions>
        <exclusion>
          <groupId>org.junit.vintage</groupId>
          <artifactId>junit-vintage-engine</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
      </plugin>
    </plugins>
  </build>

</project>

server.port=8080

#保存根路徑

record.path=E:/workspace/share/

index.html

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>莫非照相機</title>
</head>
<body>
<div>
  <div><span><a href="/tp" rel="external nofollow" >拍照</a></span></div>
</div>
</body>
</html>

CameraController.java

package me.muphy.camera;

import me.muphy.servicce.CameraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CameraController {

  @Autowired
  private CameraService cameraService;

  @GetMapping("/tp")
  public String takePictures(String[] args) {
    String msg = cameraService.takePictures();
    return "<div><span>" + msg + "</span></div><div>" +
        "<span><a href=\"/ll?d=/picture\" >點擊查看所有照片</a></span>" +
        "<span style=\"margin-left: 20px;\"><a href=\"/\" >返回首頁</a></span></div>";
  }
}

CameraService.java

package me.muphy.servicce;

import com.github.sarxos.webcam.Webcam;
import com.github.sarxos.webcam.WebcamResolution;
import com.github.sarxos.webcam.WebcamUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;

@Service
public class CameraService {

  @Value("${download.path:E:/workspace/download/}")
  private String downloadPath;

  public String takePictures() {
    Webcam webcam = Webcam.getDefault();
    if (webcam == null) {
      return "沒有找到攝像設備!";
    }
    String filePath = downloadPath + "/picture/" + new SimpleDateFormat("yyyy-MM-dd").format(new Date());
    File path = new File(filePath);
    if (!path.exists()) {//如果文件不存在,則創(chuàng)建該目錄
      path.mkdirs();
    }
    String time = new SimpleDateFormat("yyyMMdd_HHmmss").format(new Date());
    File file = new File(filePath + "/" + time + ".jpg");
    webcam.setViewSize(WebcamResolution.VGA.getSize());
    WebcamUtils.capture(webcam, file);
    return "拍照成功!";
  }
}

CameraApplication.java

package me.muphy;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class CameraApplication {

  public static void main(String[] args) {
    SpringApplication.run(CameraApplication.class, args);
  }

}

當前電腦沒有攝像頭,因此是正常的

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

  • Java即將引入新對象類型來解決內(nèi)存使用問題

    Java即將引入新對象類型來解決內(nèi)存使用問題

    這篇文章主要介紹了Java即將引入新對象類型來解決內(nèi)存使用問題,文章通過圍繞主題的相關資料展開詳細內(nèi)容,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-05-05
  • java單例五種實現(xiàn)模式解析

    java單例五種實現(xiàn)模式解析

    這篇文章主要介紹了java單例五種實現(xiàn)模式解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-09-09
  • java+jsp+struts2實現(xiàn)發(fā)送郵件功能

    java+jsp+struts2實現(xiàn)發(fā)送郵件功能

    這篇文章主要為大家詳細介紹了java+jsp+struts2實現(xiàn)發(fā)送郵件功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Spring Boot XSS 攻擊過濾插件使用

    Spring Boot XSS 攻擊過濾插件使用

    這篇文章主要介紹了Spring Boot XSS 攻擊過濾插件使用,本文給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • Maven的pom.xml中resources標簽的用法

    Maven的pom.xml中resources標簽的用法

    本文主要介紹了Maven的pom.xml中resources標簽的用法,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2023-07-07
  • Java如何取掉json數(shù)據(jù)中值為null的屬性字段

    Java如何取掉json數(shù)據(jù)中值為null的屬性字段

    這篇文章主要介紹了Java如何取掉json數(shù)據(jù)中值為null的屬性字段,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • Spring Boot 2.2 正式發(fā)布,大幅性能提升 + Java 13 支持

    Spring Boot 2.2 正式發(fā)布,大幅性能提升 + Java 13 支持

    隨著 Spring Framework 5.2.0 成功發(fā)布之后,Spring Boot 2.2 也緊跟其后,發(fā)布了第一個版本:2.2.0。下面就來一起來看看這個版本都更新了些什么值得我們關注的內(nèi)容
    2019-10-10
  • 簡單易懂的MyBatis分庫分表方案分享

    簡單易懂的MyBatis分庫分表方案分享

    這篇文章主要給大家介紹了關于MyBatis分庫分表方案的相關資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者使用MyBatis具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-03-03
  • 區(qū)分Java中的ArrayList和LinkedList

    區(qū)分Java中的ArrayList和LinkedList

    這篇文章主要介紹了如何區(qū)分Java中ArrayList和LinkedList,文中講解非常細致,代碼幫助大家更好的理解和學習,感興趣的朋友可以了解下
    2020-06-06
  • springboot接入微信app支付的方法

    springboot接入微信app支付的方法

    本文使用springboot集成微信支付服務,包含微信統(tǒng)一支付訂單接口,以及支付回調(diào)接口等,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2021-05-05

最新評論