AndroidUSBCamera
============
AndroidUSBCamera is developed based on the [saki4510t/UVCCamera](https://github.com/saki4510t/UVCCamera), the project of USB Camera (UVC equipment) and the use of video data acquisition are highly packaged, and it can help developers using USB Camera devices easily by a few simple APIs. By using AndroidUSBCamera,you can detect and connect to a USB Camera simply.And you also can use it to realize taking picture,recording mp4,switching resolutions ,getting h.264/aac/yuv(nv21) stream and setting camera's contrast or brightness,supporting 480P、720P、1080P and higher,etc.
[中文文档: AndroidUSBCamera,UVCCamera开发通用库](http://blog.csdn.net/andrexpert/article/details/78324181)
Usage
-------
### 1.Add to your Android Studio project
Step 1. Add the JitPack repository to your build file.Add it in your root build.gradle at the end of repositories:
```java
allprojects {
repositories {
...
maven { url 'http://raw.github.com/saki4510t/libcommon/master/repository/' }
maven { url 'https://jitpack.io' }
}
}
```
Step 2. Add the dependency
```java
dependencies {
implementation 'com.github.jiangdongguo:AndroidUSBCamera:2.2.8'
}
```
### 2. APIs Introduction
(1) In order to using it correctly,the following four steps must be achieved:
```java
mUVCCameraView = (CameraViewInterface) mTextureView;
mUVCCameraView.setCallback(mCallback);
mCameraHelper = UVCCameraHelper.getInstance();
// set default preview size
mCameraHelper.setDefaultPreviewSize(1280,720);
// set default frame format,defalut is UVCCameraHelper.Frame_FORMAT_MPEG
// if using mpeg can not record mp4,please try yuv
// mCameraHelper.setDefaultFrameFormat(UVCCameraHelper.FRAME_FORMAT_YUYV);
mCameraHelper.initUSBMonitor(this, mUVCCameraView, mDevConnectListener);
```
To be attention,mCallback is a object of interface CameraViewInterface.Callback,and it's used to be listenering surfaceView
created or detoryed.mDevConnectListener is a object of interface UVCCameraHelper.OnMyDevConnectListener,and it's used to be listenering to detect and conntect USB device.Here is the coding order:
```java
private CameraViewInterface.Callback mCallback = new CameraViewInterface.Callback mCallback(){
@Override
public void onSurfaceCreated(CameraViewInterface view, Surface surface) {
// must have
if (!isPreview && mCameraHelper.isCameraOpened()) {
mCameraHelper.startPreview(mUVCCameraView);
isPreview = true;
}
}
@Override
public void onSurfaceChanged(CameraViewInterface view, Surface surface, int width, int height) {
}
@Override
public void onSurfaceDestroy(CameraViewInterface view, Surface surface) {
// must have
if (isPreview && mCameraHelper.isCameraOpened()) {
mCameraHelper.stopPreview();
isPreview = false;
}
}
}
private UVCCameraHelper.OnMyDevConnectListener listener = new UVCCameraHelper.OnMyDevConnectListener() {
@Override
public void onAttachDev(UsbDevice device) {
// request open permission(must have)
if (!isRequest) {
isRequest = true;
if (mCameraHelper != null) {
mCameraHelper.requestPermission(0);
}
}
}
@Override
public void onDettachDev(UsbDevice device) {
// close camera(must have)
if (isRequest) {
isRequest = false;
mCameraHelper.closeCamera();
}
}
@Override
public void onConnectDev(UsbDevice device, boolean isConnected) {
}
@Override
public void onDisConnectDev(UsbDevice device) {
}
};
```
![Connecting gif](https://github.com/jiangdongguo/AndroidUSBCamera/blob/master/gifs/detecting.gif)
(2) Capturing JPG Images
```java
mCameraHelper.capturePicture(picPath, new AbstractUVCCameraHandler.OnCaptureListener() {
@Override
public void onCaptureResult(String path) {
Log.i(TAG,"save path:" + path);
}
});
```
(3) Recording Mp4,supporting close voice and save file automatic.
```java
RecordParams params = new RecordParams();
params.setRecordPath(videoPath);
params.setRecordDuration(0); // 0,do not cut save
params.setVoiceClose(mSwitchVoice.isChecked()); // is close voice
mCameraHelper.startPusher(params, new AbstractUVCCameraHandler.OnEncodeResultListener() {
@Override
public void onEncodeResult(byte[] data, int offset, int length, long timestamp, int type) {
// type = 1,h264 video stream
if (type == 1) {
// FileUtils.putFileStream(data, offset, length);
}
// type = 0,aac audio stream
if(type == 0) {
}
}
@Override
public void onRecordResult(String videoPath) {
Log.i(TAG,"videoPath = "+videoPath);
}
});
// of course,if you only want to getting h.264 and aac stream
// you can do like this
mCameraHelper.startPusher(listener);
```
(4) setting camera's brightness and contrast.
```java
mCameraHelper.setModelValue(UVCCameraHelper.MODE_BRIGHTNESS,progress);
mCameraHelper.setModelValue(UVCCameraHelper.MODE_CONTRAST,progress);
mCameraHelper.getModelValue(UVCCameraHelper.MODE_BRIGHTNESS);
mCameraHelper.getModelValue(UVCCameraHelper.MODE_CONTRAST);
...
```
![Connecting gif](https://github.com/jiangdongguo/AndroidUSBCamera/blob/master/gifs/brightness.gif)
(5) switch resolutions and camera.
```java
mCameraHelper.updateResolution(widht, height);
```
![Connecting gif](https://github.com/jiangdongguo/AndroidUSBCamera/blob/master/gifs/2.1.0.gif)
At last,remember adding permissions:
```
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
```
Other Library about Android Camera
-------
[OkCamera](https://github.com/jiangdongguo/OkCamera) Android Camera univsersally operation.
[AndroidRecordMp4](https://github.com/jiangdongguo/AndroidRecordMp4) Using MediaCodec realize record mp4.
[AndroidYuvOsd](https://github.com/jiangdongguo/AndroidYuvOsd) YUV data operation.
[Lame4Mp3](https://github.com/jiangdongguo/Lame4Mp3) pcm to mp3 and pcm to aac.
License
-------
Copyright 2018 Jiangdongguo
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
没有合适的资源?快使用搜索试试~ 我知道了~
AndroidUSBCamera.zip
共2032个文件
flat:597个
class:552个
xml:206个
需积分: 50 35 下载量 15 浏览量
2019-06-03
17:57:13
上传
评论
收藏 34.77MB ZIP 举报
温馨提示
这个demo不是调用系统本身的摄像头,而是调用USB外接摄像头的,请根据需要下载.该demo能够拍照,录制视频以及调整分辨率
资源推荐
资源详情
资源评论
收起资源包目录
AndroidUSBCamera.zip (2032个子文件)
3szETZEyyahlz5OFDn_w90+VKhQ= 316KB
3szETZEyyahlz5OFDn_w90+VKhQ= 316KB
652vxKjcWyHix6wRrVeLonmLu7g= 680KB
652vxKjcWyHix6wRrVeLonmLu7g= 680KB
aCzriYCBfuY202nQP0REDKntV1g= 17KB
aCzriYCBfuY202nQP0REDKntV1g= 17KB
aJJLTi5IRzfGblju2RTGUuQtVI4= 22B
aJJLTi5IRzfGblju2RTGUuQtVI4= 22B
resources-debug.ap_ 652KB
resources-debug.ir.ap_ 651KB
testUSBCamera.apk 3.24MB
app-debug.apk 1.77MB
dependencies.apk 1.23MB
slice_8.apk 98KB
slice_3.apk 85KB
slice_4.apk 48KB
slice_0.apk 46KB
slice_7.apk 30KB
slice_2.apk 7KB
slice_6.apk 7KB
slice_1.apk 7KB
slice_9.apk 7KB
slice_5.apk 6KB
gradlew.bat 2KB
executionHistory.bin 1.86MB
classAnalysis.bin 663KB
fileHashes.bin 225KB
outputFiles.bin 54KB
jarAnalysis.bin 35KB
taskHistory.bin 23KB
resourceHashesCache.bin 18KB
last-build.bin 1B
CJcaRc0Cai2O46SwbRqIQ0vTbcM= 102KB
CJcaRc0Cai2O46SwbRqIQ0vTbcM= 102KB
USBCameraActivity.class 44KB
UVCCameraTextureView.class 42KB
USBVendorId.class 41KB
USBVendorId.class 39KB
USBVendorId.class 39KB
USBVendorId.class 39KB
AspectRatioTextureView.class 38KB
UVCCamera.class 37KB
USBMonitor.class 30KB
AbstractUVCCameraHandler$CameraThread.class 29KB
UVCCamera.class 29KB
UVCCamera.class 29KB
UVCCamera.class 29KB
MainActivity.class 29KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$styleable.class 25KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
R$color.class 23KB
USBMonitor.class 23KB
USBMonitor.class 23KB
USBMonitor.class 23KB
R$styleable.class 22KB
R$styleable.class 22KB
R$styleable.class 22KB
R$style.class 22KB
R$style.class 22KB
R$style.class 22KB
R$style.class 22KB
R$style.class 22KB
R$style.class 22KB
R$style.class 22KB
R$style.class 22KB
R$style.class 22KB
AbstractUVCCameraHandler$CameraThread.class 21KB
AbstractUVCCameraHandler$CameraThread.class 21KB
AbstractUVCCameraHandler$CameraThread.class 21KB
R$color.class 19KB
R$color.class 19KB
R$color.class 19KB
H264EncodeConsumer.class 17KB
AbstractUVCCameraHandler.class 17KB
UVCCameraHelper.class 16KB
CameraDialog.class 15KB
USBMonitor$UsbControlBlock.class 15KB
DeviceFilter.class 15KB
MediaEncoder.class 15KB
AACEncodeConsumer.class 15KB
MyApplication.class 13KB
UVCCameraHandlerMultiSurface.class 12KB
MediaEncoder.class 12KB
MediaEncoder.class 12KB
MediaEncoder.class 12KB
H264EncodeConsumer.class 12KB
H264EncodeConsumer.class 12KB
H264EncodeConsumer.class 12KB
USBCameraActivity.class 12KB
USBCameraActivity.class 12KB
UVCCameraTextureView$RenderHandler$RenderThread.class 11KB
共 2032 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论
qq_36628260
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功