最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

項(xiàng)目源碼GitHub:https://github.com/muphy1112/RuphyRecorder

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

新建Spring Boot項(xiàng)目

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>莫非照相機(jī)</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\" >點(diǎn)擊查看所有照片</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 "沒有找到攝像設(shè)備!";
    }
    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);
  }

}

當(dāng)前電腦沒有攝像頭,因此是正常的

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(54)

    Java日常練習(xí)題,每天進(jìn)步一點(diǎn)點(diǎn)(54)

    下面小編就為大家?guī)硪黄狫ava基礎(chǔ)的幾道練習(xí)題(分享)。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧,希望可以幫到你
    2021-08-08
  • SpringBoot實(shí)現(xiàn)人臉識(shí)別等多種登錄方式

    SpringBoot實(shí)現(xiàn)人臉識(shí)別等多種登錄方式

    本文主要介紹了SpringBoot實(shí)現(xiàn)人臉識(shí)別等多種登錄方式,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2022-05-05
  • 引入QQ郵箱發(fā)送驗(yàn)證碼進(jìn)行安全校驗(yàn)功能實(shí)現(xiàn)

    引入QQ郵箱發(fā)送驗(yàn)證碼進(jìn)行安全校驗(yàn)功能實(shí)現(xiàn)

    最近遇到這樣的需求用戶輸入自己的郵箱,點(diǎn)擊獲取驗(yàn)證碼,后臺(tái)會(huì)發(fā)送一封郵件到對(duì)應(yīng)郵箱中,怎么實(shí)現(xiàn)呢?下面小編給大家?guī)砹艘隥Q郵箱發(fā)送驗(yàn)證碼進(jìn)行安全校驗(yàn)功能,需要的朋友可以參考下
    2023-02-02
  • Mybatis 多對(duì)一查詢的實(shí)現(xiàn)方法

    Mybatis 多對(duì)一查詢的實(shí)現(xiàn)方法

    這篇文章主要介紹了Mybatis 多對(duì)一查詢,本文通過場(chǎng)景分析示例代碼相結(jié)合給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2022-02-02
  • IDEA插件推薦之Maven-Helper的教程圖解

    IDEA插件推薦之Maven-Helper的教程圖解

    這篇文章主要介紹了IDEA插件推薦之Maven-Helper的相關(guān)知識(shí),本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考
    2020-07-07
  • Java實(shí)現(xiàn)的剪刀石頭布游戲示例

    Java實(shí)現(xiàn)的剪刀石頭布游戲示例

    這篇文章主要介紹了Java實(shí)現(xiàn)的剪刀石頭布游戲,涉及java隨機(jī)數(shù)生成及邏輯判定等相關(guān)操作技巧,需要的朋友可以參考下
    2017-12-12
  • Spring Batch讀取txt文件并寫入數(shù)據(jù)庫的方法教程

    Spring Batch讀取txt文件并寫入數(shù)據(jù)庫的方法教程

    這篇文章主要給大家介紹了Spring Batch讀取txt文件并寫入數(shù)據(jù)庫的方法,SpringBatch 是一個(gè)輕量級(jí)、全面的批處理框架。這里我們用它來實(shí)現(xiàn)文件的讀取并將讀取的結(jié)果作處理,處理之后再寫入數(shù)據(jù)庫中的功能。需要的朋友可以參考借鑒,下面來一起看看吧。
    2017-04-04
  • SpringBoot自定義Starter的教程指南

    SpringBoot自定義Starter的教程指南

    SpringBoot的Starter自動(dòng)配置機(jī)制極大地簡(jiǎn)化了依賴管理和應(yīng)用配置,使得開發(fā)者可以以最少的配置快速啟動(dòng)和運(yùn)行Spring應(yīng)用,有時(shí),標(biāo)準(zhǔn)的Starter可能無法滿足特定需求,需要?jiǎng)?chuàng)建自定義Starter,所以本文給大家介紹了SpringBoot自定義Starter的教程指南
    2024-11-11
  • Spring Boot 定制與優(yōu)化內(nèi)置的Tomcat容器實(shí)例詳解

    Spring Boot 定制與優(yōu)化內(nèi)置的Tomcat容器實(shí)例詳解

    本文主要記錄對(duì)內(nèi)置容器優(yōu)化和定制的方式,用于自己加深對(duì)SpringBoot理解。本文給大家介紹的非常詳細(xì),具有參考借鑒價(jià)值,需要的朋友參考下吧
    2017-12-12
  • javaDSL簡(jiǎn)單實(shí)現(xiàn)示例分享

    javaDSL簡(jiǎn)單實(shí)現(xiàn)示例分享

    DSL領(lǐng)域定義語言,用來描述特定領(lǐng)域的特定表達(dá)。比如畫圖從起點(diǎn)到終點(diǎn);路由中的從A到B。這是關(guān)于畫圖的一個(gè)簡(jiǎn)單實(shí)現(xiàn)
    2014-03-03

最新評(píng)論

龙川县| 津市市| 独山县| 蓝山县| 临城县| 大安市| 齐齐哈尔市| 延庆县| 鄂托克旗| 济宁市| 楚雄市| 南岸区| 雷波县| 三亚市| 深圳市| 泌阳县| 天镇县| 锦屏县| 水城县| 九江县| 中超| 株洲县| 呼伦贝尔市| 栾川县| 开封市| 敖汉旗| 庆城县| 绩溪县| 禄丰县| 辽阳县| 定安县| 共和县| 乌兰察布市| 甘谷县| 于都县| 措勤县| 会同县| 古蔺县| 互助| 东阳市| 革吉县|