电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術(shù)文章
文章詳情頁

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

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

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

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

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

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

新建Spring Boot項目

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

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

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

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

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

標簽: Java
相關(guān)文章:
主站蜘蛛池模板: 中药超微粉碎机(中药细胞级微粉碎)-百科| 深圳律师咨询_深圳律师事务所_华荣【免费在线法律咨询】网 | 999范文网_优质范文下载写作帮手 | 新材料分散-高速均质搅拌机-超声波分散混合-上海化烁智能设备有限公司 | 邢台人才网_邢台招聘网_邢台123招聘【智达人才网】 | 骨灰存放架|骨灰盒寄存架|骨灰架厂家|智慧殡葬|公墓陵园管理系统|网上祭奠|告别厅智能化-厦门慈愿科技 | 卫浴散热器,卫浴暖气片,卫生间背篓暖气片,华圣格浴室暖气片 | 不锈钢闸阀_球阀_蝶阀_止回阀_调节阀_截止阀-可拉伐阀门(上海)有限公司 | 工业铝型材生产厂家_铝合金型材配件批发精加工定制厂商 - 上海岐易铝业 | 绿叶|绿叶投资|健康产业_绿叶投资集团有限公司 | 水质监测站_水质在线分析仪_水质自动监测系统_多参数水质在线监测仪_水质传感器-山东万象环境科技有限公司 | SF6环境监测系统-接地环流在线监测装置-瑟恩实业 | 船用泵,船用离心泵,船用喷射泵,泰州隆华船舶设备有限公司 | 美能达分光测色仪_爱色丽分光测色仪-苏州方特电子科技有限公司 | 全自动在线分板机_铣刀式在线分板机_曲线分板机_PCB分板机-东莞市亿协自动化设备有限公司 | 阜阳在线-阜阳综合门户| 全自动真空上料机_粉末真空上料机_气动真空上料机-南京奥威环保科技设备有限公司 | 上海风淋室_上海风淋室厂家_上海风淋室价格_上海伯淋 | 热回收盐水机组-反应釜冷水机组-高低温冷水机组-北京蓝海神骏科技有限公司 | 冷凝锅炉_燃气锅炉_工业燃气锅炉改造厂家-北京科诺锅炉 | Dataforth隔离信号调理模块-信号放大模块-加速度振动传感器-北京康泰电子有限公司 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库-首页-东莞市傲马网络科技有限公司 | 磁力去毛刺机_去毛刺磁力抛光机_磁力光饰机_磁力滚抛机_精密金属零件去毛刺机厂家-冠古科技 | 泰安塞纳春天装饰公司【网站】 | 杭州公司变更法人-代理记账收费价格-公司注销代办_杭州福道财务管理咨询有限公司 | 滁州高低温冲击试验箱厂家_安徽高低温试验箱价格|安徽希尔伯特 | 老城街小面官网_正宗重庆小面加盟技术培训_特色面馆加盟|牛肉拉面|招商加盟代理费用多少钱 | 常州翔天实验仪器厂-恒温振荡器-台式恒温振荡器-微量血液离心机 恒温恒湿箱(药品/保健品/食品/半导体/细菌)-兰贝石(北京)科技有限公司 | 【铜排折弯机,钢丝折弯成型机,汽车发泡钢丝折弯机,线材折弯机厂家,线材成型机,铁线折弯机】贝朗折弯机厂家_东莞市贝朗自动化设备有限公司 | 品牌广告服务平台,好排名,好流量,好生意。 | 桁架楼承板-钢筋桁架楼承板-江苏众力达钢筋楼承板厂 | 智能门锁电机_智能门锁离合器_智能门锁电机厂家-温州劲力智能科技有限公司 | 企小优-企业数字化转型服务商_网络推广_网络推广公司 | 无轨电动平车_轨道平车_蓄电池电动平车★尽在新乡百特智能转运设备有限公司 | 九爱图纸|机械CAD图纸下载交流中心| 办公室家具公司_办公家具品牌厂家_森拉堡办公家具【官网】 | 智能化的检漏仪_气密性测试仪_流量测试仪_流阻阻力测试仪_呼吸管快速检漏仪_连接器防水测试仪_车载镜头测试仪_奥图自动化科技 | 北京网络营销推广_百度SEO搜索引擎优化公司_网站排名优化_谷歌SEO - 北京卓立海创信息技术有限公司 | 整车VOC采样环境舱-甲醛VOC预处理舱-多舱法VOC检测环境仓-上海科绿特科技仪器有限公司 | 精密五金加工厂-CNC数控车床加工_冲压件|蜗杆|螺杆加工「新锦泰」 | 查分易-成绩发送平台官网|