网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

详解Java如何实现调用计算机摄像头拍照

小编这次要给大家分享的是详解Java如何实现调用计算机摄像头拍照,文章内容丰富,感兴趣的小伙伴可以来了解一下,希望大家阅读完这篇文章之后能够有所收获。

创新互联专注于中大型企业的成都网站设计、网站建设和网站改版、网站营销服务,追求商业策划与数据分析、创意艺术与技术开发的融合,累计客户1000多家,服务满意度达97%。帮助广大客户顺利对接上互联网浪潮,准确优选出符合自己需要的互联网运用,我们将一直专注成都品牌网站建设和互联网程序开发,在前进的路上,与客户一起成长!

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

新建Spring Boot项目

详解Java如何实现调用计算机摄像头拍照

pop.xml

<?xml version="1.0" encoding="UTF-8"?>

  4.0.0
  
    org.springframework.boot
    spring-boot-starter-parent
    2.2.5.RELEASE
     
  
  me.muphy
  recorder
  0.0.1-SNAPSHOT
  recorder
  Demo project for Spring Boot

  
    1.8
  

  
    
      org.springframework.boot
      spring-boot-starter-web
    

    
      com.github.sarxos
      webcam-capture
      0.3.12
    

    
      org.springframework.boot
      spring-boot-starter-test
      test
      
        
          org.junit.vintage
          junit-vintage-engine
        
      
    
  

  
    
      
        org.springframework.boot
        spring-boot-maven-plugin
      
    
  

server.port=8080

#保存根路径

record.path=E:/workspace/share/

index.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 "
" + msg + "
"; } }

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()) {//如果文件不存在,则创建该目录
      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);
  }

}

当前电脑没有摄像头,因此是正常的

详解Java如何实现调用计算机摄像头拍照

看完这篇关于详解Java如何实现调用计算机摄像头拍照的文章,如果觉得文章内容写得不错的话,可以把它分享出去给更多人看到。


分享名称:详解Java如何实现调用计算机摄像头拍照
分享地址:http://bjjierui.cn/article/gihdps.html

其他资讯