• Stars
    star
    323
  • Rank 130,051 (Top 3 %)
  • Language
    C
  • License
    BSD 3-Clause "New...
  • Created over 11 years ago
  • Updated about 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Android library to access a USB webcam feed

Android Webcam Library

This project is an Android library to provide an API to access an external USB webcam that supports UVC. The library provides an in-process service (WebcamManager) so that multiple parts of an application can share the same webcam.

The library also provides an example View that can be used directly in a layout, the WebcamPreview.

Problems?

Instead of an FAQ, if you can't get the library to work, try one of these suggestions. Unfortunately video is fairly non-standard across Android OS builds and web cams, so I can't provide very good support.

I don't have a /dev/video0 on my Android tablet or phone.

You may need to change the device name in code to match what your camera appears as in the filesystem (#5).

My device is missing the kernel drivers.

A tip from Borja:

I write you again because finally i managed to have external webcam working on my device. I's not a v4l2 related problem. I's because samsung devices do not have uvcvideo module in their kernel. All new devices have v4l2 intalled in kernel but not uvcvideo.ko that is the driver (module) to get comunication between linux kernel and uvc compliant web camera. I had to recompile a custom kernel to enable USB_VIDEO_CLASS option. With new kernel i have no problems to get frames from my camera with an app named dashcam. Now i'm going to test openxc/android-webcam to try get video in my app.

I get an error about insufficient permissions on the video device

Make sure the /dev/video0 file has permissions of at least 0660, is owned by the media user and the group camera. Also add the CAMERA permissions to your app's manifest.

NativeWebcamJNI(2427): VIDIOC_DQBUF error 9, Bad file number

Based on #13, try changing this:

// Change this
//*fd = open(dev_name, O_RDWR | O_NONBLOCK, 0);
// To this:
*fd = open(dev_name, O_RDWR);

Dependencies

Installation

  • Clone the Git repository
  • Run ndk-build in the android-webcam/android-webcam-library folder to compile the native library
  • Reference the library from your Android application

With Maven:

To install the library to your local Maven repository, so other apps can reference it:

$ cd android-webcam
$ cd android-webcam-library; ndk-build && cd ..
$ mvn install -pl android-webcam-library -am

Usage

To install the example application, first install the library, then:

$ mvn package android:deploy android:run -pl example

To just display the webcam image, add this to your app's layout:

<com.ford.openxc.webcam.WebcamPreview
        android:id="@+id/cp" android:layout_width="fill_parent"
        android:layout_height="0dip" android:layout_weight="1"/>

If you want to modify the image at all, subclass WebcamPreview and override the run() method to make any modifications to the iamge before rendering it to the canvas. The WebcamManager service has a getFrame() method which returns a Bitmap of the latest frame from the camera.

USB Webcam Support

To use a USB webcam in Android, the kernel must be compiled with V4L2. Many late-model Android versions (4.2 and possibly 4.1/4.0) already have this enabled.

If the file /dev/video0 appears on the device when you plug in a video camera, then you've got V4L2 support.

If you have /dev/video0, check the permissions in adb:

$ adb shell
shell@android:/ $ ls -l /dev/video0
crw-rw---- media    camera    81,   0 2013-02-25 10:31 video0

If the file is at least 0660, owned by the media user with the group camera, you're good to go.

Add the CAMERA permissions to your app's manifest:

<uses-permission android:name="android.permission.CAMERA" />

Tested and Working

  • Toshiba Thrive 10.1"
  • Google Nexus 7

Tested and Not Working

  • Galaxy Nexus (might not have enough power to start webcam)

Custom Kernel

If your Android version and device doesn't have include V4L2 support, you'll need to load a custom Android ROM and configure the kernel with these options:

CONFIG_VIDEO_DEV=y
CONFIG_VIDEO_V4L2_COMMON=y
CONFIG_VIDEO_MEDIA=y
CONFIG_USB_VIDEO_CLASS=y
CONFIG_V4L_USB_DRIVERS=y
CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y

Contributors

This project was originally based on a JNI implementation for UVC webcams by neuralassembly.

See the CONTRIBUTORS file for other contributors.

License

Copyright (c) 2011-2013 Ford Motor Company Licensed under the BSD license.

More Repositories

1

uds-c

Unified Diagnostics Service (UDS) and OBD-II (On Board Diagnostics for Vehicles) C Library
C
617
star
2

isotp-c

An implementation of the ISO-TP (ISO15765-2) CAN protocol in C
C
289
star
3

openxc-android

Android library for accessing vehicle data from an OpenXC vehicle interface
Java
230
star
4

vi-firmware

OpenXC-compatible firmware for PIC32 and LPC1768
C++
194
star
5

openxc-python

OpenXC Python library
Python
109
star
6

openxc-message-format

Specification for the OpenXC JSON message format
C
97
star
7

bitfield-c

Bit array parsing and encoding utility library in C
C
85
star
8

AT-commander

A C library to control a device via UART that responds to an AT command set (like an RN-42)
C
75
star
9

openxc-vehicle-simulator

Python
62
star
10

openxcplatform.com

Static website for openxcplatform.com
HTML
40
star
11

reference-vi

Open Source Hardware Schematics for OpenXC Vehicle Interface
HTML
38
star
12

bluetooth-audio-passthrough

Open source schematics for Bluetooth audio passthrough
21
star
13

nxpUSBlib

Fork of NXP's USB library for all LPC microcontrollers, with bug fixes
C
20
star
14

emhashmap

This library is an implementation of a hash map in C that maps integers to void pointers
C
20
star
15

web-logging-example

Example OpenXC web application in Python for vehicle data logging
Python
17
star
16

diagnostic-tool

OpenXC Android Tool for Sending OBD-II Requests to a Vehicle Interface
Java
16
star
17

rearview-camera

Rearview camera implemented as an Android app with OpenXC
Java
16
star
18

openxc-starter

OpenXC "hello world."
Java
15
star
19

openxc-ios-framework

OpenXC iOS framework for use with the C5 BLE device. Also see the openxc-ios-app-demo.
Swift
14
star
20

trace-analyzer

JavaScript visualization of OpenXC vehicle data traces
JavaScript
12
star
21

nxp-cdl

Fork with slight modifications to NXP's Common Driver Library, for LPCxxxx Microcontrollers
C
12
star
22

nightvision

Video-based object detection for forward collision warnings with OpenXC
Java
9
star
23

emqueue

An implementation of a queue in C that can support arbirtary element types.
C
9
star
24

arduino-transfer-benchmarking

Benchmarking USB and FTDI transfer rates on Arduino-compatible microcontrollers
C
8
star
25

openxc-ios-library

OpenXC iOS framework for use with the C5 BLE device. Example contains the OpenXC demonstration app that use all of the features of the OpenXC Framework.
Swift
8
star
26

nonstandard-android-measurements

Non-standard OpenXC Measurement and Unit types for Android
Java
7
star
27

emlist

A simple linked list in C for embedded applications
C
7
star
28

openxc-ios-app-demo

OpenXC demonstration app that use all of the features of the openxc-ios-framework. This can be a starting app for any OpenXC iOS application that wishes to use the C5 BLE device.
HTML
6
star
29

OpenXCAccessory

Contents of OpenXCAccessory directory on V2X and Modem devices
Python
6
star
30

shiftknob-android

Android application to control the OpenXC-enabled Haptic Shift Knob
Java
6
star
31

mpg

Java
5
star
32

openxc-c

C library to access data from an OpenXC vehicle interface
C
5
star
33

shiftknob-3Ddesign

3D design sources for the OpenXC-enabled Haptic Shift Knob
Perl
5
star
34

simple-hud

Firmware and Java connector for a Bluetooth-connected OpenXC module
Java
4
star
35

chipkit-vehicle-interface

Assembly instructions for a chipKIT-based OpenXC Vehicle Interface
CSS
3
star
36

smart-wiper

Java
3
star
37

openxc-data-tools

Python tools for OpenXC data analysis and visualization
Python
3
star
38

vi-windows-driver

Windows driver for USB OpenXC Vehicle Interface
3
star
39

rain

Android application to provide rain detection information to Weather Underground
Java
3
star
40

shiftknob-firmware

Embedded (Arduino) firmware for OpenXC-enabled Haptic Shift Knob
Arduino
2
star
41

MLA

Microchip Library Access for use on OpenXC vi-firmware
C
2
star
42

SimCrashDetection

Crash detection library for app testing purposes, triggers an event when crash is detected (currently crude algorithm)
Java
2
star
43

validation-android

Validation app used to verify signals from VI
Java
2
star
44

pixel-openxc-android

A smart brake light prototype using the pixelart board(http://ledpixelart.com/) utilizing the OpenXC platform (http://openxcplatform.com)
Java
2
star
45

shiftknob-hardware

Electrical schematics for the OpenXC-enabled Haptic Shift Knob
Ruby
1
star
46

EV_Coach_public

Continuation of the Ford EV Coach Efficiency Application Trainer
Java
1
star
47

SignalMonitor

Application to send all OpenXC signals only when a monitored signal crosses a designated threshold
1
star
48

nxp-bsp

Fork with slight modifications to NXP's Board Support Package, for LPCxxxx Microcontrollers
C
1
star
49

io-accessory

Open source schematics for a generic I/O extension for the OpenXC platform
1
star