How to take single snapshots from a webcam?

笑着哭i 提交于 2019-11-28 10:03:16

问题


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.

Greetings,
Burkhard


回答1:


the JMF (Java Media Framework) is a good starting point. However, I did not succeed with it.

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



回答2:


what you are looking for might be the Java Media Framework (JMF). See the Sun Tutorial. I hope that helps.




回答3:


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.




回答4:


Try webcam-capture project.

This code will take a snapshot from webcam (embedded, connected to USB or IP camera) and save it into JPG file:

Webcam webcam = Webcam.getDefault();
webcam.open()
BufferedImage image = webcam.getImage();
ImageIO.write(image, "JPG", new File("test.jpg"));


来源:https://stackoverflow.com/questions/1078689/how-to-take-single-snapshots-from-a-webcam

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!