Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use USB Camera on Android application

I need to display a video transmitted by an USB Camera connected to my tablet on Android 3.2.

How can I do this?

I can't use the tablet's camera, because my tablet is fixed on board.

like image 468
neoffreeman Avatar asked Jan 22 '12 19:01

neoffreeman


People also ask

Can you use a USB camera on Android phone?

The Android platform supports the use of plug-and-play USB cameras (that is, webcams) using the standard Android Camera2 API and the camera HIDL interface. Webcams generally support USB video class (UVC) drivers and on Linux, the standard Video4Linux (V4L) driver is used to control UVC cameras.

How do I make my USB camera my default camera Android?

Go to Settings > Applications > Default Applications and delete all entries pertaining to your camera. That should reset the phone to ask you what camera to use for certain processes.

How can I use my USB camera as a webcam?

Connect one to your PC or Mac via USB, then plug your camera in via HDMI, and you'll be able to use it as a webcam. You'll need to spend some more money, but if you already own a nice camera without its own webcam support app, you might find them to be better investments than a standalone webcam.


2 Answers

(I wrote this in 2012 when there was no support for USB camera. I am not working on Android anymore.. so I cannot explain how to do it with the API of latest Android. If you know any better solution please post it here.)

The discussion holds true only if the sensor inside USB camera is UVC compliant(most of todays' cameras are compliant).

As of the date of this post(March 1 2012), there are no default Android API's available for working on external camera. So if you are serious about the project, the work you do would involve writing a firmware that talks to the kernel drivers and then displaying the data on the Android application layer.

When you insert a USB camera, There are few things that you need to check first.

1) Is your camera getting power from USB port?(For this to happen your USB port should have USB-OTG support- USB port can act both as target and host, Check whether the lights on camera(if any) are glowing or not?)

2) Is node getting created in /dev directory?(Only in case the kernel has v4l2 and UVC support enabled,node will be created). If node is getting created, now you have access to the real hardware that is USB camera and your job is going to be easy from here on. to check do ls -l /dev/v* inside the android file system and check whether video0 or video1 is being created.

4) If node is created, you need to write a firmware(UVC) and acquire a frame from the real hardware. It(UVC) supports different ioctl calls that talk to the v4l2 layer in the kernel and will fetch you the frames.

These frames would be mostly of format YUYV422 or YUYV420 format.

Once you receive the frames, convert into RGB or Jpeg (Android has support to convert ) and display on the canvas or imageview whichever you like.

For recording you might have to use ffmpeg for encoding. This will convert the images into video.

like image 112
Sandeep Avatar answered Oct 07 '22 10:10

Sandeep


One thing worth checking before you get started is whether your USB cable works with a mouse, keyboard, and USB Drive (you will need to StickMount app on some devices to get the USB drive working).

I am also looking to get a USB webcam working on Android and am trying to reproduce what was done at http://brain.cc.kogakuin.ac.jp/research/usb-e.html. Lastly I heard that Bluetooth webcams work out of the box.

like image 41
bbodenmiller Avatar answered Oct 07 '22 11:10

bbodenmiller