使用带有java swing的笔记本电脑摄像头
如何在ubuntu操作系统中使用java中的swing来使用摄像头请给我一些通过java使用摄像头的示例和指南使用带有java swing的笔记本电脑摄像头,java,swing,camera,Java,Swing,Camera,如何在ubuntu操作系统中使用java中的swing来使用摄像头请给我一些通过java使用摄像头的示例和指南 public static void main(String[] args) { CamDemo t = new CamDemo(); t.getCam(); } public void getCam() { try { /* Grab the default web cam */ MediaLocator ml = new
public static void main(String[] args) {
CamDemo t = new CamDemo();
t.getCam();
}
public void getCam() {
try {
/* Grab the default web cam */
MediaLocator ml = new MediaLocator("vfw://0");
DataSource ds = Manager.createDataSource(ml);
requestFormatResolution(ds);
Player p = Manager.createRealizedPlayer(ds);
p.start();
Thread.currentThread().sleep(1000);
JFrame jfrm = new JFrame("Testing Webcam");
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
if (p.getVisualComponent() != null)
jfrm.getContentPane().add(p.getVisualComponent());
if (p.getControlPanelComponent() != null)
jfrm.getContentPane().add(p.getControlPanelComponent(),
BorderLayout.SOUTH);
jfrm.pack();
jfrm.setLocationRelativeTo(null);
jfrm.setVisible(true);
jfrm.setSize(320, 240);
} catch (Exception e) {
e.printStackTrace();
}
}
public boolean requestFormatResolution(DataSource ds) {
if (ds instanceof CaptureDevice) {
FormatControl[] fcs = ((CaptureDevice) ds).getFormatControls();
for (FormatControl fc : fcs) {
Format[] formats = ((FormatControl) fc).getSupportedFormats();
for (Format format : formats) {
if ((format instanceof VideoFormat)
&& (((VideoFormat) format).getSize().getHeight() <= 240)
&& (((VideoFormat) format).getSize().getWidth() <= 320)) {
((FormatControl) fc).setFormat(format);
return true;
}
}
}
}
return false;
}
}
(jmf)是您正在寻找的。使用project
作者提供的API使用示例:
Webcam buildin = Webcam.getWebcams().get(0); // build-in laptop camera
Webcam usb = Webcam.getWebcams().get(1); // usb camera
BufferedImage image1 = buildin.getImage();
BufferedImage image2 = usb.getImage(); // do with image1 and image2 whatever you want
到目前为止你都尝试了什么?可能重复了当你得到javafxHello先生我没有得到任何相机集成的例子,所以请告诉我一个例子……提前谢谢。你已经得到了一些例子,但“不能使用它们”。你到底尝试了什么,你的研究成果在哪里?我们不是来为你写的。向我们展示您尝试过的内容、相关代码以及您遇到的具体问题。请仔细阅读并看看这里的图片。然后回答你的问题,并提供所有必要的细节。投票结束,因为这是暂时的话题。我在谷歌上搜索了Java网络摄像头,找到了大量的代码。我只需要一个例子来使用摄像头。有人能帮我吗?没有。自己做一些研究。表现出一些努力,伙计+1对于这一点,这是一个很大的帮助,但我认为他希望你为他写这篇文章,或者找一个已经完成所有工作的例子。这就是你所得到的帮助,嗯?事实上SARXOS API是很棒的API,我也尝试过jmf,但最好使用SARXOS,因为它简单可靠。感谢很多朋友…实际上这个例子太大了,无法与我的项目集成…所以请给我一个小而简单的学习例子…再次感谢…而且我不是能够导入SARXOS网络摄像头示例给出的项目…@Gopal00005实际上这个示例太大,无法与我的项目集成真的吗?四行太大了?哦,上帝,这正在变成一场闹剧。我想他希望你为他做所有的工作。四行是一个疯狂的代码量(叹气),所以你可以理解为什么你应该飞到OP,握着他们的手,只有3行代码!回答这个问题和处理我在这里见过的最懒的海报之一都是+1!但是,先生,我不知道如何使用SARXOS示例,请您详细说明如何使用它…我的意思是一步一步…因为我无法使用SARXOS。很抱歉,但我对Java还不熟悉。
Webcam buildin = Webcam.getWebcams().get(0); // build-in laptop camera
Webcam usb = Webcam.getWebcams().get(1); // usb camera
BufferedImage image1 = buildin.getImage();
BufferedImage image2 = usb.getImage(); // do with image1 and image2 whatever you want