Android: How to use webcam in emulator?

匿名 (未验证) 提交于 2019-12-03 02:26:02

问题:

I'm connecting a webcam to my emulator by setting the front camera to "webcam0" in the AVD Manager. When I start the emulator's camera application, I get the error

CameraService::connect X (pid 702) rejected (invalid cameraId 0). 

Here's the relevant portion of the Android source code:

sp CameraService::connect(     const sp& cameraClient, int cameraId) {      int callingPid = getCallingPid();      [...]      if (cameraId = mNumberOfCameras) {         LOGE("CameraService::connect X (pid %d) rejected (invalid cameraId %d).",             callingPid, cameraId);         return NULL;     }      [...] } 

The webcam has been correctly assigned an ID of 0 because there's only 1 camera. However, mNumberOfCameras is presumably still 0. This means that the camera is being registered by the emulator, but it hasn't bothered to update the number of connected cameras.

How can I connect a webcam so that it will be properly recognized by the emulator?

Edit: the command emulator -webcam-list -avd in \android-sdks\tools gives the result:

List of web cameras connected to the computer: Camera `webcam0` is connected to device `AndroidEmulatorVC0` on channel 0 using pixel format `BGR4` 

When I launch the webcam from Eclipse's AVD manager or using emulator -camera-front webcam0 -avd , I get the following window:

Edit 2: This seems to be a bug in the emulator. The suggested answer tells you what to do to set up the camera, but doesn't solve the problem for me. I ultimately solved it by using a laptop with a built-in webcam. Perhaps another USB webcam might have worked as well.

回答1:

UPDATE

In Android Studio AVD:

  1. Open AVD Manager:

  1. Add/Edit AVD:

  1. Click Advanced Settings in the bottom of the screen:

  1. Set your camera of choice as the front/back cameras:



回答2:

Follow the below steps in Eclipse.

  1. Goto -> AVD Manager
  2. Create/Edit the AVD.
  3. Hardware > New:
  4. Configures camera facing back
  5. Click on the property value and choose = "webcam0".
  6. Once done all the above the webcam should be connected. If it doesnt then you need to check your WebCam drivers.

Check here for more information : How to use web camera in android emulator to capture a live image?



回答3:

I suggest you to look at this highly rated blog post which manages to give a solution to the problem you're facing :

http://www.inter-fuser.com/2009/09/live-camera-preview-in-android-emulator.html

His code is based on the current Android APIs and should work in your case given that you are using a recent Android API.



回答4:

I would suggest checking the drivers and updating them if required.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!