Android Question How can I use a USB camera ?

laviniut

Active Member
Licensed User
Longtime User
I bought a chinese USB HD webcam which is working fine on windows xp and windows 7 without any driver. I tried to connect to my samsung galaxy s2 but I have not seen my usb camera in any camera application. Maybe is a HID device. So, how can I use a USB camera ?
 

hayderOICO

Member
Licensed User
Longtime User
I was going through the source code of the simplewebcamapp to get clues...

https://bitbucket.org/neuralassembl...era/simplewebcam/CameraPreview.java?at=master


and I found this bit which was interesting...

B4X:
// /dev/videox (x=cameraId+cameraBase) is used.
    // In some omap devices, system uses /dev/video[0-3],
    // so users must use /dev/video[4-].
    // In such a case, try cameraId=0 and cameraBase=4
    private int cameraId=0;
    private int cameraBase=0;

Ok. So CameraID is not a camera Identifier as such!! It is simply telling you the ORIENTATION of the CAMERA!
http://developer.android.com/reference/android/hardware/Camera.CameraInfo.html

so it is a simple 0 for back and 1 for front. OK. That clears it!

so in theory the camera identifier is through a value called "cameraBase" which corresponds to the /dev/videoX number... i.e
/dev/video0 = cameraBase 0
/dev/video3 = camerabase 3


but I can find nothing about this mythical "cameraBase" on android Dev?????except for this... https://android.googlesource.com/platform/frameworks/av/ /34242ac/camera/CameraBase.cpp


then I found that they are using a C (NDK) app to access /dev/videoX directly....

https://bitbucket.org/neuralassembl...8a11eb7514e8db75967/jni/ImageProc.c?at=master

My question is, can I use the above NDK snippet with B4A? I already created a large codebase for a program in B4A and I'd rather not have to recode everything in the Java SDK...
 
Last edited:
Upvote 0

hayderOICO

Member
Licensed User
Longtime User
after reading through the "hoops" I'd have to jump through to make an NDK program work... I am back to square one...

If there is a way we can "enable" and "disable" what cameras the android OS "sees" then it also solves everyone's issues with having to use the simplewebcam / dashcam apps.... since they'd be able to use the built in and all third party camera apps with their webcams!

this would be a great feature and is worth investigating for many people as it opens up useful new functionality and use cases for the android tabs.


from reading the android documentation, I can see that "CameraID" actually has only a 0 or 1 value corresponding to a "front" or "back" camera... so adding extra camera profiles in media_profiles.xml seems redundant?

The best approach to take is to:
1- disable the existing cameras
2- set the USB cameras as cameraId 0 / 1 .

That way compatibility with all android camera apps is maintained since they would find cameras using the simple cameraID tag, and everyone would be able to use their USB camera with all existing camera apps.

Perhaps they would need a separate "media_profiles.xml" file called "media_profiles2.xml" and the "camera toggle" program renames the "built in" media_profiles.xml file, then changes the "USB media_profiles.xml" to media_profiles.xml...

once the user is finished and wants to go back to using the built in cams, the program can swap the media_profiles.xml files back again.

Of course this would need a rooted handset/tablet?



now the question is, how do I go about doing this? I am guessing somewhere within the android system it uses V4L2 and thus /dev/video0 / 1 / 2 to set the CameraId that all android apps access. but where is that?
 
Upvote 0

hayderOICO

Member
Licensed User
Longtime User
sadly I've given up doing this. Went back to using an embedded linux device with the camera application instead and it lets me easily use simpleCV and openCV via simple python scripts. Will await to see if any new ROMs for android devices would support the ability to control additional cameras natively.
 
Upvote 0

Similar Threads

Top