java获得信息摄像头拍照,在java中捕获来自网络摄像头的图像?

How can I continuously capture images from a webcam?

I want to experiment with object recognition (by maybe using java media framework).

I was thinking of creating two threads

one thread:

Node 1: capture live image

Node 2: save image as "1.jpg"

Node 3: wait 5 seconds

Node 4: repeat...

other thread:

Node 1: wait until image is captured

Node 2: using the "1.jpg" get colors

from every pixle

Node 3: save data in arrays

Node 4: repeat...

解决方案

This JavaCV implementation works fine.

Code:

import org.bytedeco.javacv.*;

import static org.bytedeco.javacpp.opencv_core.IplImage;

import static org.bytedeco.javacpp.opencv_core.cvFlip;

import static org.bytedeco.javacpp.opencv_imgcodecs.cvSaveImage;

/**

* Created by gtiwari on 1/3/2017.

*/

public class Test implements Runnable {

final int INTERVAL = 100;///you may use interval

CanvasFrame canvas = new CanvasFrame("Web Cam");

public Test() {

canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

}

public void run() {

FrameGrabber grabber = new VideoInputFrameGrabber(0); // 1 for next camera

OpenCVFrameConverter.ToIplImage converter = new OpenCVFrameConverter.ToIplImage();

IplImage img;

int i = 0;

try {

grabber.start();

while (true) {

Frame frame = grabber.grab();

img = converter.convert(frame);

//the grabbed frame will be flipped, re-flip to make it right

cvFlip(img, img, 1);// l-r = 90_degrees_steps_anti_clockwise

//save

cvSaveImage((i++) + "-aa.jpg", img);

canvas.showImage(converter.convert(img));

Thread.sleep(INTERVAL);

}

} catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

Test gs = new Test();

Thread th = new Thread(gs);

th.start();

}

}

You can modify the codes and be able to save the images in regular interval and do rest of the processing you want.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值