如何从网络摄像头(在 Java 中)捕获视频?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2004405/
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 capture video from webcam(in java)?
提问by Ishan
I want to develop an application in java to capture video from webcam and store it onto a particular location.Can anyone provide me the working code?
我想用java开发一个应用程序来从网络摄像头捕获视频并将其存储到特定位置。谁能提供工作代码?
What type(usb,ip etc..) of webcam is the best in order to develop the application.
哪种类型(usb、ip 等)的网络摄像头最适合开发应用程序。
Please help me. how to proceed?
请帮我。如何进行?
采纳答案by Mina Nagy
Check out David's solution using JMF: http://www.mutong.com/fischer/java/usbcam/
使用 JMF 查看 David 的解决方案:http: //www.mutong.com/fischer/java/usbcam/
回答by Lily Chung
I found that the best way is by using the JMyronlibrary with a USB webcam. You will have to mess around with the dll's though because it uses native code... there's a working example somewhere if you google for it (I don't know exactly where) but I know that you need the dll's in your path. Download the Processing library and find the dll's and the jar.
我发现最好的方法是使用带有 USB 网络摄像头的JMyron库。您将不得不处理 dll,因为它使用本机代码……如果您在某处使用 google 搜索它(我不知道确切位置),那么在某处有一个工作示例,但我知道您的路径中需要 dll。下载 Processing 库并找到 dll 和 jar。
import JMyron.JMyron;
//initializer
int width=100;//insert your numbers here
int height=100;
JMyron jmyron = new JMyron();
jmyron.start(width,height);
//in a loop
jmyron.update();
int[] image = jmyron.image();
image will be an int[] with length width*height. it stores the pixels row-by-row, so the first width
pixels will be the first row, the second width
pixels will be the second row, and so on.
图像将是一个长宽*高的 int[]。它逐行存储像素,因此第一个width
像素将是第一行,第二个width
像素将是第二行,依此类推。
回答by Bartosz Firyn
I would recommend using webcam-captureproject (I'm the author). There is a example of how to record video from webcam device - you can find it here. This project can handle embedded camera device as well as those connected to USB or IP cameras. It is working on most operating systems (Windows XP, Vista, 7, 8, Linux, Mac OS, Raspbian, etc) and you don't have to install any additional software to run it. The choice is yours.
我建议使用网络摄像头捕获项目(我是作者)。有一个关于如何从网络摄像头设备录制视频的示例 - 您可以在此处找到它。该项目可以处理嵌入式摄像头设备以及连接到 USB 或 IP 摄像头的设备。它适用于大多数操作系统(Windows XP、Vista、7、8、Linux、Mac OS、Raspbian 等),您无需安装任何其他软件即可运行它。这是你的选择。
I would not recommend using JMF - is completely outdated and you have to install it on your PC first, so if you consider your application to be portable, you have to have this in your mind too.
我不建议使用 JMF - 它已经完全过时了,您必须先将它安装在您的 PC 上,所以如果您认为您的应用程序是可移植的,那么您也必须考虑到这一点。