GithubHelp home page GithubHelp logo

rxcamera's Introduction

RxCamera

RxJava style camera API for android, it based on android.hardware.camera


Add to your project dependence:

repositories {
        jcenter()
}
dependencies {
	compile 'com.ragnarok.rxcamera:lib:0.0.5'
}

Basic Usage:

  1. set the camera parameter by choose a RxCameraConfig, which created by RxCameraConfig.Builder:

    RxCameraConfig config = new RxCameraConfig.Builder()
                .useBackCamera()
                .setAutoFocus(true)
                .setPreferPreviewFrameRate(15, 30)
                .setPreferPreviewSize(new Point(640, 480), false)
                .setHandleSurfaceEvent(true)
                .build();

    for all camera config currently support, please see RxCameraConfig

  2. open camera

    RxCamera.open(context, config)

    it return an RxJava Observable object, the type is Observable<RxCamera>

  3. bind a SurfaceView or TextureView and startPreview

    since RxCamera.open is return an Observable, so you can chain the call like this

    RxCamera.open(this, config).flatMap(new Func1<RxCamera, Observable<RxCamera>>() {
          @Override
          public Observable<RxCamera> call(RxCamera rxCamera) {
              return rxCamera.bindTexture(textureView);
              // or bind a SurfaceView:
              // rxCamera.bindSurface(SurfaceView)
          }
    }).flatMap(new Func1<RxCamera, Observable<RxCamera>>() {
          @Override
          public Observable<RxCamera> call(RxCamera rxCamera) {
              return rxCamera.startPreview();
          }
    });

    both RxCamera.bindTexture and RxCamera.startPreview will return an Observable<RxCamera> object

    PS: if set isHandleSurfaceEventto true(set by setHandleSurfaceEvent(true) in RxCameraConfigChooser), RxCamera will do the actual camera start preview action when the surface is available, otherwise it will start preview immediately, and may failed if surface is not available, in this case, the return Observable will call onError

  4. switch camera

    switch the camera in runtime

     camera.switchCamera();	

    and it will also change the internal camera config, so after switch camera, the camera.getConfig will return with new setting


request camera data

RxCamera support many styles of camera data requests:

  • successiveDataRequest

    camera.request().successiveDataRequest()

    it will return the camera data infinitely

  • periodicDataRequest

     camera.request().periodicDataRequest(1000)

    as the name, it will return camera data periodic, pass the interval in millisecond

  • oneShotRequest

     camera.request().oneShotRequest()

    it will return the camera data only once

  • takePictureRequest

     camera.request().takePictureRequest(boolean isContinuePreview, Func shutterAction, boolean openFlash)

    the encapsulation of takePicture API, if isContinuePreview set to true, the RxCamera will try to restart preview after capture the picture, otherwise will behave as system takePicture call, stop preview after captured successfully

    and the shutterAction will called after picture just captured, like the [ShutterCallback] (http://developer.android.com/intl/es/reference/android/hardware/Camera.ShutterCallback.html) (actually it is called in the system shutterCallback)

    and the openFlash if set to true, it will open the flash when taking picture, and automatically close it after this request

  • FaceDetectionRequest

     camera.request().faceDetectionRequest()

    the encapsulation of Camera.FaceDetectionListener, it will return the faces location in CameraData.faceList


All the data request will return an Observalbe<RxCameraData>

the RxCameraData contained these fields:

  • byte[] cameraData, the raw data of camera, for the takePicture request, it will return the jpeg encode byte, other request just return raw camera preview data, if you don't set preview format, the default is YUV420SP
    • Matrix rotateMatrix, this matrix help you rotate the camera data in portrait
    • Camera.Face[] faceList, the locatoin of faces, only returned in FaceDetectionRequest

camera action request

the camera action request will change the behavior of the camera

  • zoom and somoothZoom action:

     camera.action().zoom(int level)
     camera.action().smoothZoom(int level)

    change the camera zoom level

  • open or close the flash

     camera.action().flashAction(boolean isOn)
  • area focus and area metering

    camera.action().areaFocusAction(List<Camera.Area> focusAreaList)
    camera.action().areaMeterAction(List<Camera.Area> focusAreaList)

    and there is a helper function to convert the coordinate to [-1000, 1000], which is suitable for Camera.Area, in CameraUtil:

    Rect transferCameraAreaFromOuterSize(Point center, Point outerSize, int size)

    check out the example to see how to use this

This project still in very early stage, and welcome the pull request

rxcamera's People

Contributors

elrutas avatar ezequieladrianm avatar gylee2011 avatar keiththompson avatar ragnraok avatar ravidsrk avatar sibelius avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxcamera's Issues

bindTexture doesn't seem to work if the TextureView doesn't have a surface yet

I tried debugging the problem a bit. The RxCameraInternal.surfaceCallback is registered with the TextureView but the RxCameraInternal object is not registered as the SurfaceCallback's listener (I don't see SurfaceCallback.setSurfaceListener being called anywhere).

I'm using verion 0.0.2.

Below is my code (very similar to the example). It is called in my Activity's onResume().

private Observable<RxCamera> initCamera(final TextureView view) {
    RxCameraConfig config = RxCameraConfigChooser.obtain().
            useBackCamera().
            setAutoFocus(true).
            setPreferPreviewFrameRate(15, 30).
            setPreferPreviewSize(new Point(1920, 1080)).
            setHandleSurfaceEvent(true).
            get();
    return RxCamera.open(this, config).flatMap(new Func1<RxCamera, Observable<RxCamera>>() {
        @Override
        public Observable<RxCamera> call(RxCamera rxCamera) {
            currentCamera = rxCamera;
            return rxCamera.bindTexture(view);
        }
    }).flatMap(new Func1<RxCamera, Observable<RxCamera>>() {
        @Override
        public Observable<RxCamera> call(RxCamera rxCamera) {
            return rxCamera.startPreview();
        }
    });
}

Set the size of the saved image

Hello,

I tried to save the image at a high resolution using this method: setPictureSize with RxCamera.getNativeCamera but it doesn't seam to work.

cameraParameters = rxCameraResult.getNativeCamera().getParameters();
cameraParameters.setPictureFormat(ImageFormat.JPEG);
cameraParameters.setPictureSize(2592, 1944);
rxCameraResult.getNativeCamera().setParameters(cameraParameters);

takePicturesObservable = rxCamera
                                .request().oneShotRequest()
                                .observeOn(Schedulers.newThread());

Please could you give me an idea about what I'm doing wrong?

Thank you!

successiveDataRequest stop after switch camera

Hello,

How i can continue receive the RxCameraData or onPreviewFrame(byte[] data, Camera camera) even user switch the camera? I want to implement continues streaming on server even user switch the camera? Can you please help me?

Thanks in advance.

Capture image with Aspect Ratio 4:3

Hi,
I want to take a photo with aspect ratio 4:3. Currently, some device it capture with 4:3 and some with 16:9, so i have problem while scale image which were captured.

Sorry for my bad English. Hope i can get some advice soon.

periodicDataRequest where is the data?

camera.request().periodicDataRequest(500).subscribe(new Action1<RxCameraData>() {
    @Override
    public void call(RxCameraData rxCameraData) {
        showLog("periodic request, cameradata.length: " + rxCameraData.cameraData.length);
            Bitmap bitmap = BitmapFactory.decodeByteArray(rxCameraData.cameraData, 0, rxCameraData.cameraData.length);

Gives this warning and then App Crashes:

periodic request, cameradata.length: 460800
--- SkImageDecoder::Factory returned null

Because rxCameraData.cameraData is NULL...

Flash availability

This is a question. Is flash available to turn on/off while taking photos?

Camera Preview Size and taken camera size issue

Hi, i'm not using toolbar in my application and, preview streched showing. By the way after taking picture, photo cropped left and right side. I'm testing 3 device and result is same. here is example pictures :

before
after

and here is my configs :

 RxCameraConfig config = new RxCameraConfig.Builder()
                .useBackCamera()
                .setAutoFocus(true)
                .setPreferPreviewFrameRate(15, 30)
                .setPreferPreviewSize(new Point(640, 480), false)
                .setHandleSurfaceEvent(true)
                .build();

How can i solve this? And i'm already look Config Page But i dont know how to scale preview for all devices.

Save image locally

Using this method "periodicDataRequest" I tried to save locally the image but the bitmap is null and I don't understand why?!

camera.request().periodicDataRequest(1000).subscribe(new Action1<RxCameraData>() {
           @Override
           public void call(RxCameraData rxCameraData) {

               showLog("periodic request, cameraData.length: " + rxCameraData.cameraData.length);
               try {
                   String path = Environment.getExternalStorageDirectory() + "/test" + "_" + (title++) + ".jpg";
                   File file = new File(path);
                   BitmapFactory.Options options = new BitmapFactory.Options();
                   options.outWidth = 1440;
                   options.outHeight = 1920;
                   byte[] theArray = rxCameraData.cameraData;
                   Bitmap bitmap = BitmapFactory.decodeByteArray(theArray, 0, theArray.length, options);
                   //Bitmap bitmap = BitmapFactory.decodeByteArray(rxCameraData.cameraData, 0, rxCameraData.cameraData.length);
                   bitmap = Bitmap.createBitmap(bitmap, 0, 0, 1440, 1920,
                           rxCameraData.rotateMatrix, false);
                   try {
                       file.createNewFile();
                       FileOutputStream fos = new FileOutputStream(file);
                       bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
                       fos.close();
                   } catch (IOException e) {
                       e.printStackTrace();
                   }
                   showLog("PERIODIC - Save file on " + path);
               } catch (Exception e) {
                   e.printStackTrace();
               }
           }
       });

Please could you help me? Thank you!

Captured Image is saved with wrong orientation (After Switching Camera - Moto G4 Plus)

Hai,

By default i'm opening front camera and it is saving properly but when I switch camera to back it is saving with wrong orientation.

Now I changed config to open back camera first and it saves fine but issue starts with front camera.

In short, image is saved properly only for camera specified in config.

Device: Moto G4 Plus

Any idea?
Thanks

Error Please Hep me

Hi

I have the app_name parameter in the manifest file of this project. I'm getting an error

Error:Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute application@label value=(UfeedBackMe) from AndroidManifest.xml:26:9-36
is also present at [com.ragnarok.rxcamera:lib:0.0.5] AndroidManifest.xml:11:18-50 value=(@string/app_name).
Suggestion: add 'tools:replace="android:label"' to element at AndroidManifest.xml:22:5-87:19 to override.

RxJava 2 support

Hi,

Any plan for the development of RxJava 2 ?

I can help and PR.

Lucas.

need new features

Can you please add code for changing rear cam to front cam.
and set auto flash off and on code

Why do you allow backup on AndroidManifest

Hi Dev,

Can you help me out to set the value of allowBackup variable in application tag inside AndroidManifest file set to false. It is causing issue with my app.

Thank you.

Cheers,
Amila Fonseka

Preview too dark on dome devices.

I am using this library on some devices (nexus 5, galaxy s5 and samsung tablet) is causing preview too dark and here is the code I was using...
RxCameraConfig config = new RxCameraConfig.Builder() .useBackCamera() .setAutoFocus(true) .setPreferPreviewFrameRate(15, 30) .setPreferPreviewSize(new Point(640, 480), false) .setHandleSurfaceEvent(true) .build();
here is what causing preview too dark is this line setPreferPreviewFrameRate(15, 30) I commented this line and preview is fine.
OR
By replacing this code
try { List<Integer> frameRates = parameters.getSupportedPreviewFrameRates(); if (frameRates != null) { Integer max = Collections.max(frameRates); Toast.makeText(context, "=======>" + max, 1).show(); parameters.setPreviewFrameRate(max); } } catch (Exception e) { Log.e(TAG, "get parameter failed: " + e.getMessage()); }
With
if (cameraConfig.minPreferPreviewFrameRate != -1 && cameraConfig.maxPreferPreviewFrameRate != -1) { try { int[] range = CameraUtil.findClosestFpsRange(camera, cameraConfig.minPreferPreviewFrameRate, cameraConfig.maxPreferPreviewFrameRate); parameters.setPreviewFpsRange(range[0], range[1]); parameters.setPreviewFrameRate(15); } catch (Exception e) { openCameraFailedReason = OpenCameraFailedReason.SET_FPS_FAILED; openCameraFailedCause = e; Log.e(TAG, "set preview fps range failed: " + e.getMessage()); return false; } }
Inside RxCameraInternal.java file. in the following path: "RxCamera-lib\src\main\java\com\ragnarok\rxcamera\RxCameraInternal.java"

so Question is why setting frame rate not working on some devices?

Tag release

Can you please tag the 0.0.5 release in github?
Contributor and consumer can then know which code is in release, and which is not.

For example, does 0.0.5 have all the code in master branch?

Thanks.

Add support to FaceDetection

This lib is really great, Rx is a really good choice for camera data

RxCamera should support the FaceDetection API

Suggest update RxJava and RxAndroid version.

I see your lib use old version of rxjava and rxandroid.

And currently,I use your lib by this in gradle script:

compile 'io.reactivex:rxjava:1.1.1'
 compile 'io.reactivex:rxandroid:1.1.0'

    compile('com.ragnarok.rxcamera:lib:0.0.2'){
        exclude group: 'io.reactivex',module:'rxjava'
        exclude group: 'io.reactivex',module:'rxandroid'
    }

Front Camera Touch Focus

Hello, great libraries.

I was wondering if there is a reason why you cant use touch focus while using the front facing camera, it doesnt work on the example app.
Im testing it on my nexus 6p.

I keep getting area focus and metering failed..

Thanks in advance

Support record video

Your library is pretty cool. It's very easy to use. But it only supports taking pictures. It's better if you have a plan to support recording video. Waiting for you :)

Square preview

How to get a square preview. I had tried with a square textureview. Does not work well.

Camera Error 100

I have Error 100 in some Samsung devices. It is because of Android Camera Server Died. Please have a look in this issue.

Problem with result orientation

I have problem with front camera on some devices.
On meizu and sony all is ok.
On some chineses devices rotationMatrix is wrong.
screenshot_2016-04-05-21-13-28 Sony
screenshot_2016-04-05-21-12-33 Ulefone Power

Auto White Balance disabled?

Hi, while opening my RxCamera I found that the imagen was very dark. You can think it's normal, so reopened the app. But the problem persisted. So, without leaving the room and lightning... I opened the Android Camera of my phone and... Surprise! The exposure was perfect! The same happened when I opened Snapchat. The exposure was perfect. My question is: Did you disabled auto exposure? How can this be fixed? Thanks in advance

PeriodicDataRequest updates the available data?

Hi, after being able to decode the YUV RxCameraData to JPG, I am facing a new issue.

I have set the periodicDataRequest time to 250 milliseconds. But sometimes the CameraData received is the same! So it is not updated?
How can it be posible if the minimum framerate is 15fps?
Any ideas, help?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.