午夜剧场伦理_日本一道高清_国产又黄又硬_91黄色网战_女同久久另类69精品国产_妹妹的朋友在线

您的位置:首頁技術文章
文章詳情頁

Java調用計算機攝像頭拍照實現過程解析

瀏覽:197日期:2022-09-01 09:09:22

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

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

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

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

新建Spring Boot項目

Java調用計算機攝像頭拍照實現過程解析

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='http://www.leifengta.com.cn/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;@RestControllerpublic 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='http://www.leifengta.com.cn/ll?d=/picture' >點擊查看所有照片</a></span>' +'<span style='margin-left: 20px;'><a href='http://www.leifengta.com.cn/' >返回首頁</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;@Servicepublic 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()) {//如果文件不存在,則創建該目錄 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;@SpringBootApplicationpublic class CameraApplication { public static void main(String[] args) { SpringApplication.run(CameraApplication.class, args); }}

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

Java調用計算機攝像頭拍照實現過程解析

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: Java
相關文章:
主站蜘蛛池模板: 日韩视频免费看 | 欧美日韩国产一区 | 日本久久网站 | 国产成人av在线 | 日本天堂在线播放 | 91欧美在线 | 美女福利在线观看 | 亚洲大片免费看 | 久久久夜色精品亚洲 | 久久在线视频免费观看 | 丁香久久综合 | 国产色图片 | 日韩黄色在线视频 | 亚洲女优在线观看 | 又黄又爽又色视频 | 黄色网页在线观看 | 爱草av | 九一在线视频 | 色婷婷影院 | 国产精品自拍网站 | 成人激情视频网站 | 激情综合五月婷婷 | 国产成人精品123区免费视频 | av免费网站在线观看 | 成人在线免费视频观看 | 成人羞羞免费 | 亚洲少妇色图 | 国产婷婷色 | 999国产精品视频 | 夜夜操天天 | 国产精品一区二区免费看 | 伊人春色在线观看 | 日韩精品久久久久久久 | 国产亚洲精 | 麻豆成人入口 | 欧美午夜精品久久久久久人妖 | 中文字字幕在线中文 | 92久久| 欧美日韩综合在线 | 国产午夜在线观看 | 91中文在线观看 |