windows 如何从网络摄像头拍摄单个快照?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1078689/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to take single snapshots from a webcam?
提问by Burkhard
I want to take a snapshot with my webcam using java and save it to a jpg file. What are the steps needed to do so? A tutorial would be greatly appreciated.
我想使用 java 用我的网络摄像头拍摄快照并将其保存为 jpg 文件。这样做需要哪些步骤?一个教程将不胜感激。
Greetings,
Burkhard
你好,
伯克哈德
回答by Burkhard
the JMF (Java Media Framework) is a good starting point. However, I did not succeed with it.
JMF(Java 媒体框架)是一个很好的起点。但是,我没有成功。
I finally found the solution here.
我终于在这里找到了解决方案。
The important part being:
重要的部分是:
Buffer buf = frameGrabber.grabFrame();
// Convert frame to an buffered image so it can be processed and saved
Image img = (new BufferToImage((VideoFormat) buf.getFormat()).createImage(buf));
buffImg = new BufferedImage(img.getWidth(this), img.getHeight(this), BufferedImage.TYPE_INT_RGB);
//TODO saving the buffImg
回答by moxn
what you are looking for might be the Java Media Framework (JMF). See the Sun Tutorial. I hope that helps.
您正在寻找的可能是 Java 媒体框架 (JMF)。请参阅Sun 教程。我希望这有帮助。
回答by extjstutorial.info
I prefer using JMyron instead of JMF. JMyron is easy to use for accessing webcam. To save the captured image you just need to save the BufferedImage using ImageIO.write(); this blog post How To Use Webcam Using Javais usefull to start using JMyron.
我更喜欢使用 JMyron 而不是 JMF。JMyron 很容易用于访问网络摄像头。要保存捕获的图像,您只需要使用 ImageIO.write() 保存 BufferedImage;这篇博客文章How To Use Webcam Using Java对开始使用 JMyron 很有用。
回答by Bartosz Firyn
Try webcam-captureproject.
尝试网络摄像头捕获项目。
This code will take a snapshot from webcam (embedded, connected to USB or IP camera) and save it into JPG file:
此代码将从网络摄像头(嵌入的、连接到 USB 或 IP 摄像头)拍摄快照并将其保存为 JPG 文件:
Webcam webcam = Webcam.getDefault();
webcam.open()
BufferedImage image = webcam.getImage();
ImageIO.write(image, "JPG", new File("test.jpg"));