在 Java 中显示网络摄像头
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6821656/
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
Display Webcam In Java
提问by Michael Schwartz
I just started Java last week so I'm just getting the fundamentals down at the moment as I have a lot to learn (btw I'm using Eclipse on Ubuntu 11.04 if that helps). However I do a lot of screencasting, and I display my webcam in a lot of the videos that I do. So later on I would like to make a simple app that just displays the webcam. Not anything else.
我上周刚开始学习 Java,所以我现在只是在学习基础知识,因为我有很多东西要学(顺便说一句,如果有帮助,我正在 Ubuntu 11.04 上使用 Eclipse)。但是,我做了很多截屏,并且在我做的很多视频中都展示了我的网络摄像头。所以稍后我想制作一个只显示网络摄像头的简单应用程序。不是别的。
So I'm asking this question now so not only will I remember what my goal is, but also so when I feel I'm ready, and confident to work on this I will know where to go.
所以我现在问这个问题,这样我不仅会记得我的目标是什么,而且当我觉得我准备好了,并且有信心在这方面工作时,我会知道去哪里。
I don't want any code, but a reference on where to go. I'd like to just use Java. Although one of my co workers told me to look into FMJ, and JMF. However not knowing what these are I assume their like add-ons for Java, but I'd like to just stick with Java alone if it's possible.
我不想要任何代码,而是关于去哪里的参考。我只想使用Java。虽然我的一位同事告诉我调查 FMJ 和 JMF。然而,我不知道这些是什么,我认为他们喜欢 Java 的附加组件,但如果可能的话,我只想单独使用 Java。
Additionally like I said I'm still new to Java, and am learning from thenewboston's tutorials on YouTube (Currently at http://www.youtube.com/watch?v=XqTg2buXS5o) so if you know of any other resources to help new Java programmers like myself, and others it'd be greatly appreciated.
另外,就像我说的,我还是 Java 新手,并且正在从 YouTube 上的 thenewboston 教程中学习(目前位于http://www.youtube.com/watch?v=XqTg2buXS5o)所以如果您知道任何其他资源可以帮助新像我这样的 Java 程序员和其他人将不胜感激。
回答by Jim Morris
I have used lti-civil, which seems to work quite well for video capture.
我使用了lti-civil,它似乎非常适合视频捕获。
I have used it on Windows and linux, I have not tested it on Mac but it says it works there too.
我已经在 Windows 和 linux 上使用过它,我没有在 Mac 上测试过它,但它说它也可以在那里工作。
It does not need to be preinstalled, as it is a jar and a dll/so which can be downloaded with the Java application, or run via a JNLP webstart which supports native libraries.
它不需要预先安装,因为它是一个 jar 和一个 dll/so,可以与 Java 应用程序一起下载,或者通过支持本机库的 JNLP webstart 运行。
There are no 100% pure Java libraries that can capture video, so all the options (including JMF) require a native component (.dll or .so).
没有可以捕获视频的 100% 纯 Java 库,因此所有选项(包括 JMF)都需要本机组件(.dll 或 .so)。
回答by woliveirajr
JMF is a library for Java using Medias.
JMF 是一个使用 Medias 的 Java 库。
Java is much bigger than just a programing language, don't be afraid of using it's libraries to add functionalities.
Java 不仅仅是一种编程语言,不要害怕使用它的库来添加功能。
Take a look at some examples: http://www.mutong.com/fischer/java/usbcam/and http://www.java-forums.org/new-java/40115-capturing-video-webcam-jmf.html
看一些例子:http: //www.mutong.com/fischer/java/usbcam/和http://www.java-forums.org/new-java/40115-capturing-video-webcam-jmf。 html
回答by Bartosz Firyn
You can use ready-to-use WebcamPanel
Swing components from Webcam Capture APIproject (I'm the author). The project is portable and works well on 32- and 64-bit architectures of Windows, Linux, Mac OS, as well as ARM devices like e.g. Raspberry Pi (both armel and armhf).
您可以使用WebcamPanel
来自Webcam Capture API项目(我是作者)的现成的Swing 组件。该项目是可移植的,并且在 Windows、Linux、Mac OS 以及 ARM 设备(例如 Raspberry Pi(armel 和 armhf))的 32 位和 64 位体系结构上运行良好。
Example code below will display image from webcam inside JFrame
window (FPS rate is configurable):
下面的示例代码将在JFrame
窗口内显示来自网络摄像头的图像(FPS 速率可配置):
JPanel panel = new WebcamPanel(Webcam.getDefault());
JFrame window = new JFrame("Test webcam capture");
window.add(panel);
window.pack();
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JARs are available in Maven Central but if you are not using Maven you can also download separate ZIP which consists of all required dependencies (all necessary 3rd-party JARs).
JAR 在 Maven Central 中可用,但如果您不使用 Maven,您也可以下载单独的 ZIP,其中包含所有必需的依赖项(所有必需的 3rd-party JAR)。
回答by Javier
Below an implementation using Marvin Framework. This framework provides a set of plug-insfor real time video processing.
下面是使用Marvin Framework的实现。该框架提供了一组用于实时视频处理的插件。
package video.simpleVideoTest;
import javax.swing.JFrame;
import marvin.gui.MarvinImagePanel;
import marvin.image.MarvinImage;
import marvin.video.MarvinJavaCVAdapter;
import marvin.video.MarvinVideoInterface;
public class SimpleVideoTest extends JFrame implements Runnable{
private MarvinVideoInterface videoAdapter;
private MarvinImage image;
private MarvinImagePanel videoPanel;
public SimpleVideoTest(){
super("Simple Video Test");
// Create the VideoAdapter and connect to the camera
videoAdapter = new MarvinJavaCVAdapter();
videoAdapter.connect(1);
// Create VideoPanel
videoPanel = new MarvinImagePanel();
add(videoPanel);
// Start the thread for requesting the video frames
new Thread(this).start();
setSize(800,600);
setVisible(true);
}
public static void main(String[] args) {
SimpleVideoTest t = new SimpleVideoTest();
t.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
@Override
public void run() {
while(true){
// Request a video frame and set into the VideoPanel
image = videoAdapter.getFrame();
videoPanel.setImage(image);
}
}
}
回答by Saher Ahwal
回答by user3307849
You can use this using java swings.
您可以使用 java swings 来使用它。
You can find an article about this on this blog, geekscab.comSorry i dont know the exact url, So you have to search the blog
你可以在这个博客上找到一篇关于这个的文章,geekscab.com对不起,我不知道确切的网址,所以你必须搜索博客