如何在 android 模拟器中使用网络摄像头捕捉实时图像?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1276450/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:53:29  来源:igfitidea点击:

How to use web camera in android emulator to capture a live image?

androidcamerasimulator

提问by Kumar

As far as i know, Android emulator doesn't have a camera. To capture a live image we have to use the web camera. I have seen code in this web siteto use the web camera in the android emulator to capture an image, but I don't know how to use this code.

据我所知,Android 模拟器没有摄像头。要捕获实时图像,我们必须使用网络摄像头。我在这个网站上看到过使用android模拟器中的网络摄像头来捕获图像的代码,但我不知道如何使用这段代码。

采纳答案by Leo Jweda

  1. Download all the source files listed on the page: CameraSource, GenuineCamera, HttpCamera, SocketCamera, BitmapCamera, and WebcamBroadcaster.
  2. Create a package in your project called com.tomgibara.android.camera and place the first 4 source files inside.
  3. Download JMF from hereand install it.
  4. Compile WebcamBroadcaster using the following command: "C:\Program Files (x86)\Java\jdk1.6.0_15\bin\javac.exe" -classpath "C:\Program Files (x86)\JMF2.1.1e\lib" WebcamBroadcaster.java or what's equivalent to it.
  5. Run it with the following command and keep it running: java "-Djava.library.path=C:\Program Files (x86)\JMF2.1.1d\lib" WebcamBroadcaster
  6. Use the following code in your program:
  1. 下载页面上列出的所有源文件:CameraSource、GenuineCamera、HttpCamera、SocketCamera、BitmapCamera 和 WebcamBroadcaster。
  2. 在您的项目中创建一个名为 com.tomgibara.android.camera 的包,并将前 4 个源文件放入其中。
  3. 这里下载 JMF并安装它。
  4. 使用以下命令编译 WebcamBroadcaster: "C:\Program Files (x86)\Java\jdk1.6.0_15\bin\javac.exe" -classpath "C:\Program Files (x86)\JMF2.1.1e\lib" WebcamBroadcaster .java 或等效于它的东西。
  5. 使用以下命令运行并保持运行: java "-Djava.library.path=C:\Program Files (x86)\JMF2.1.1d\lib" WebcamBroadcaster
  6. 在您的程序中使用以下代码:
CameraSource cs = new SocketCamera("192.168.0.100", 9889, 320, 240, true);
if (!cs.open()) { 
/* deal with failure to obtain camera */ 
} 
while(/*some condition*/) {   
cs.capture(canvas) //capture the frame onto the canvas
}
cs.close();
CameraSource cs = new SocketCamera("192.168.0.100", 9889, 320, 240, true);
if (!cs.open()) { 
/* deal with failure to obtain camera */ 
} 
while(/*some condition*/) {   
cs.capture(canvas) //capture the frame onto the canvas
}
cs.close();

PS: I haven't been able to test this because I'm getting an error when I run WebcamBroadcaster.

PS:我无法对此进行测试,因为我在运行WebcamBroadcaster.

PPS: I just started experimenting with Android today so all this could be wrong.

PPS:我今天才开始尝试 Android,所以这一切都可能是错误的。