如何使用网络摄像头在Android模拟器捕获实时图像?

如何使用网络摄像头在Android模拟器捕获实时图像?

问题描述:

据我所知,Android模拟器没有摄像头。要捕获实时图像,我们必须使用网络摄像头。我已在此网站中看到代码,以在Android模拟器中使用网络摄像头捕获图像,但我不知道如何使用此代码。

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 site to use the web camera in the android emulator to capture an image, but I don't know how to use this code.


  1. 在页面上列出的源文件:CameraSource,GenuineCamera,HttpCamera,SocketCamera,BitmapCamera和WebcamBroadcaster。

  2. 在项目中创建一个名为com.tomgibara.android.camera的包, 4个源文件。


  3. 使用以下命令编译WebcamBroadcaster:C:\Program Files(x86)\Java\\ \\jdk1.6.0_15\bin\javac.exe-classpathC:\Program Files(x86)\JMF2.1.1e\libWebcamBroadcaster.java或与之相当的内容。

  4. 使用以下命令运行它并保持其运行:java-Djava.library.path = C:\Program Files(x86)\JMF2.1.1d\libWebcamBroadcaster

  5. 在您的程序中使用以下代码:

  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 here and 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:




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:我无法测试当我运行 WebcamBroadcaster 时出现错误。

PPS:我刚刚开始使用Android可能是错误的。

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