Is Camera2 API overly complicated?

Barsik_The_CaTBarsik_The_CaT Member ✭✭
edited May 2018 in Xamarin.Android

I need to get an image from camera for computer vision. For debudding purposes I also need to show the camera output on screen with some overlaying information later, but I'm failing miserably. I can't find a single proper example of using Camera2 in Xamarin and the only example I found (Camera2Basic from this website) does not have a single comment in it so I can't even figure out what's going on in that code. Does anyone know a good example of using Camera2 API in Xamarin.Android?

Tagged:

Answers

  • Barsik_The_CaTBarsik_The_CaT Member ✭✭
    edited May 2018

    Is this place as dead as other Xamarin resources?

  • Barsik_The_CaTBarsik_The_CaT Member ✭✭

    The hell these Callback and Handler in CameraManager.OpenCamera(id, callback, handler)? Where am I supposed to get them? What do they do?

  • HortinzHortinz GBMember ✭✭
    edited May 2018

    There's no links to any resources. It's really hard to be able to help you.

  • Barsik_The_CaTBarsik_The_CaT Member ✭✭

    @Hortinz said:
    There's no links to any resources. It's really hard to be able to help you.

    What links do you need? I am only referring to official documentation.
    Here's the CameraManager.OpenCamera() method:
    developer.xamarin.com/api/member/Android.Hardware.Camera2.CameraManager.OpenCamera/p/System.String/Android.Hardware.Camera2.CameraDevice+StateCallback/Android.OS.Handler/

  • HortinzHortinz GBMember ✭✭
    edited May 2018

    It's pretty clear what the callback handler is. You track certain events there (OnDisconnected, OnError, OnOpened).
    Just create your class that inherits from CameraDevice.StateCallback and implement those methods. So you would actually call the method like this:

            CameraManager cameraManager = (CameraManager)context.GetSystemService(Context.CameraService);
            cameraManager.OpenCamera("cameraId", new CameraCallback(), handler);
    

    You might have to read the documentation or have a look at the Google sample to understand what's the Handler. But you should be able to have it working with that code. Although you need to get the cameraId first. Again the sample contains all that code. It's very easy to just look at the kotlin/java code and write it in C#. But if you have any questions just post them here.

  • Barsik_The_CaTBarsik_The_CaT Member ✭✭

    Apparently I need to create a TextureView to display the camera output. Judging but this android example inducesmile.com/android/android-camera2-api-example-tutorial/ said TextureView needs a SurfaceTextureListener - a member of a class that implements an TextureView.ISurfaceTextureListener - developer.xamarin.com/api/type/Android.Views.TextureView+ISurfaceTextureListener/. Because that example is for Java, it does not implement Dispose() method. Should I just leave it empty?

    On the side note - what is this weird style of hiding certain classes/interfaces within other classes? What's the logic behind it?

  • vasilytserejvasilytserej USMember ✭✭

    Hey
    I created I xamarin forms sample with Camera2. Check it out.
    https://github.com/vtserej/Camera2Forms

  • RePinheiroRePinheiro Member ✭✭

    @vasilytserej

    Thanks for your code !

Sign In or Register to comment.