问题
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.
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.
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.
回答1:
I have used lti-civil, which seems to work quite well for video capture.
I have used it on Windows and linux, I have not tested it on Mac but it says it works there too.
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.
There are no 100% pure Java libraries that can capture video, so all the options (including JMF) require a native component (.dll or .so).
回答2:
JMF is a library for Java using Medias.
Java is much bigger than just a programing language, don't be afraid of using it's libraries to add functionalities.
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
回答3:
Below an implementation using Marvin Framework. This framework provides a set of plug-ins for real time video processing.
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);
}
}
}
回答4:
You can use ready-to-use WebcamPanel
Swing components from Webcam Capture API project (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).
Example code below will display image from webcam inside JFrame
window (FPS rate is configurable):
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).
回答5:
Download JMF from here
And you can start learning the JMF framework from here
回答6:
You can use this using java swings.
You can find an article about this on this blog, geekscab.com Sorry i dont know the exact url, So you have to search the blog
来源:https://stackoverflow.com/questions/6821656/display-webcam-in-java