camera-samples | Multiple samples showing the best practices

 by   android Kotlin Version: Current License: Apache-2.0

kandi X-RAY | camera-samples Summary

kandi X-RAY | camera-samples Summary

camera-samples is a Kotlin library. camera-samples has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

This repository contains a set of individual Android Studio projects to help you get started with the CameraX and Camera2 APIs in Android.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              camera-samples has a medium active ecosystem.
              It has 4343 star(s) with 2189 fork(s). There are 185 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 114 open issues and 300 have been closed. On average issues are closed in 70 days. There are 8 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of camera-samples is current.

            kandi-Quality Quality

              camera-samples has 0 bugs and 0 code smells.

            kandi-Security Security

              camera-samples has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              camera-samples code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              camera-samples is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              camera-samples releases are not available. You will need to build from source code and install.
              It has 10816 lines of code, 403 functions and 234 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of camera-samples
            Get all kandi verified functions for this library.

            camera-samples Key Features

            No Key Features are available at this moment for camera-samples.

            camera-samples Examples and Code Snippets

            No Code Snippets are available at this moment for camera-samples.

            Community Discussions

            QUESTION

            Android DataBinding new button setOnClickListener
            Asked 2022-Mar-25 at 05:33

            I need to use the Android Camera. Therefore I am using following Template: https://github.com/android/camera-samples/tree/main/Camera2SlowMotion

            I added a Butten to the fragment_camera.xml https://github.com/android/camera-samples/blob/main/Camera2SlowMotion/app/src/main/res/layout/fragment_camera.xml

            ...

            ANSWER

            Answered 2022-Mar-25 at 05:33

            I had to download the sample because I couldn't see what the issue was from the snippets in your post.

            The issue is that CameraFragment has two layout files, one in the default folder layout, and one in layout-land for landscape orientation. So you need to add your change_focus_button XML to both layout files to make it not nullable when you access it via fragmentCameraBinding in CameraFragment.

            Source https://stackoverflow.com/questions/71610319

            QUESTION

            How to ensure focused before taking picture in Android CameraX? (Should be a very commonly used feature!)
            Asked 2021-Sep-19 at 07:35

            I am using CameraX and want to take a photo. Of course, no one wants a blurred picture, so we should ensure focused before taking picture.

            First attempt: Simply call takePicture like what is done in the official sample.

            Problem: I can change the scene and quickly press the take photo button. Then, the camera has not finished auto focus when the takePicture happens. Therefore, I get a blurred photo :/

            Second attempt: Before actually taking photo, firstly trigger focusing and wait for it to finish.

            Code like:

            ...

            ANSWER

            Answered 2021-Sep-19 at 07:35

            I found the answer! Simply call setCaptureMode(ImageCapture.CAPTURE_MODE_MAXIMIZE_QUALITY).

            Reason: look at ImageCapture's constructor:

            Source https://stackoverflow.com/questions/69029799

            QUESTION

            How to save captured image from camera in android
            Asked 2021-Apr-10 at 07:00

            The official sample of Camera2Basic for capturing images from camera.
            It only shows the captured image in an activity but does not save the image to external storage

            How to save that image to external storage?

            I searched a lot over the internet for this, but there are all of the deprecated as of Android 11 (API 30).
            Thanks!

            ...

            ANSWER

            Answered 2021-Apr-10 at 07:00

            use camerax lib from google which is part android jetpack

            Source https://stackoverflow.com/questions/67031021

            QUESTION

            Clarification on Handlers, Threads and Executors when using a camera in Android Development
            Asked 2021-Apr-09 at 23:33

            I'm trying to implement the Camera2 API in my application. Having never done this before, I'm starting with the Camera2Basic example code provided by android.

            However, within the createCaptureSession() method there is a deprecated initialization method CameraDevice.createCaptureSession(), so I changed it to the following:

            ...

            ANSWER

            Answered 2021-Apr-09 at 12:45

            The documentation might resolve your problem:

            As per this link:

            To dispatch events through the main thread of your application, you can use Context.getMainExecutor(). To dispatch events through a shared thread pool, you can use AsyncTask#THREAD_POOL_EXECUTOR.

            You might get rid of the variable cameraHandler by using equivalent methods: CameraCaptureSession#capture -> CameraCaptureSession#captureSingleRequest CameraCaptureSession#setRepeatingRequest -> CameraCaptureSession#setSingleRepeatingRequest

            and so on. But be aware, that the method you mentioned (CameraDevice#createCaptureSession(java.util.List, android.hardware.camera2.CameraCaptureSession.StateCallback, android.os.Handler)) was introduced in API 24 and deprecated in API 30, but the CameraDevice#createCaptureSession(SessionConfiguration) was introduced only in API 28. So very probably You would need to handle API differences.

            Source https://stackoverflow.com/questions/67020602

            QUESTION

            What is difference between RS_KERNEL and __attribute__((kernel)) in RenderScript?
            Asked 2021-Feb-26 at 12:14

            ANSWER

            Answered 2021-Feb-26 at 12:14

            Ok, after detailed reading I can see that RS_KERNEL is a macro to __attribute__((kernel))

            Source https://stackoverflow.com/questions/66385632

            QUESTION

            How do you take a picture with camerax?
            Asked 2021-Feb-23 at 01:10

            I'm still practicing with Kotlin and Android Developing. As far as I understood, Camera class has been deprecated, and Android invites to use Camerax instead, because this high-level class is device-indipendent, and they've made simpler the process of implementing cameras on apps.

            I've tried to read the documentation (https://developer.android.com/training/camerax) but it's written so bad I barely understood what they are trying to explain. So I went to read the entire sample code given in the documentation itself (https://github.com/android/camera-samples/tree/main/CameraXBasic). The CameraFragment code is about 500 lines long (ignoring imports and various comments).

            Do I really need to write 500 lines of code to simply take a picture? How is this supposed to be considered "simpler than before"?

            I mean, Android programming is at the point where I just need to write only 4 lines of code to ask the user to select an Image from his storage and retreive it and show it in an ImageView. Is there a TRUE simple way to take a picture, or do I really need to stop and lose a whole day of work to write all those lines of code?

            EDIT: Take this page of the documentation: https://developer.android.com/training/camerax/architecture#kotlin It starts with this piece of code.

            ...

            ANSWER

            Answered 2021-Feb-23 at 01:10

            Before you can interact with the device's cameras using CameraX, you need to initialize the library. The initialization process is asynchronous, and involves things like loading information about the device's cameras.

            You interact with the device's cameras using a ProcessCameraProvider. It's a Singleton, so the first time you get an instance of if, CameraX performs its initialization.

            Source https://stackoverflow.com/questions/66318595

            QUESTION

            Memory Leak detected by LeakCanary on Activity with Fragments
            Asked 2021-Feb-14 at 06:51

            We have 2 distinct memory leaks(which look the same) in $ git clone https://source.codeaurora.org/quic/la/camera-samples -b iot-concam-apk.lnx.1.1 in version 2.0 and they go away on app close.

            They occurs as soon as the app is launched. Switching tabs, again and again, does not increase the number of leaks which is a good thing I think.

            I caught it using https://square.github.io/leakcanary/getting_started/ I noticed if we change all 'replace' to add in onCreate, the 2 leaks happen on Tab switch and not on the app launch.

            ...

            ANSWER

            Answered 2021-Feb-13 at 08:57

            I have fixed the memory leak.

            Not using androidx.fragment.app.FragmentContainerView in my XML was the solution.

            Instead, I have used a ConstraintLayout.

            I think you should not use it if you do not control your fragment using app:navGraph="@navigation/nav_graph" in XML and instead use replace(R.id.fragment_container, null, null) in your activity

            Source https://stackoverflow.com/questions/66176103

            QUESTION

            How to mirror the PreviewView in CameraX?
            Asked 2021-Jan-05 at 21:08

            Disclaimer: I'm aware of the existence of this question, but it currently stands unresolved and I'm trying to provide extra information without polluting that one with useless answers that won't solve the problem anyway.

            I have a custom device with a front camera that is mirrored by default, so I want to display the preview normally and I need to horizontally flip the content of PreviewView, but I'm stuck. Other people in the past have suggested using PreviewView#setScaleX(-1) but it either doesn't work at all or it needs to be called at a very specific point in the code, which I haven't found yet.

            The code below is a simplified version of CameraFragment.kt in the official CameraXBasic example; I've added comments where I've already tired calling viewFinder.scaleX = -1f with no success. Honestly I don't really think that the place makes a difference because if I call it with any value other than 1 it works fine with both scaleX and scaleY, but it always ignores the negative sign so it never flips.

            ...

            ANSWER

            Answered 2021-Jan-05 at 21:08

            Depending on the implementation type (COMPATIBLE vs PERFORMANCE) and the device, PreviewView can either use a TextureView or a SurfaceView, in your case I'm assuming PreviewView is using a SurfaceView, you can confirm this by getting access to PreviewView's first child view (View.getChildAt(0)).

            TextureView is just like any other View, which is why when PreviewView uses it, setting its scaleX to -1 should mirror the displayed preview. You can call PreviewView.setScaleX(-1F) once the layout is created (e.g. In onViewCreated()).

            With SurfaceView, it's a bit tricky, as the Surface and the View are independent in some aspects: The Surface is placed behind the window that holds the View, and the View hierarchy handles correctly composing the entire layout by punching a hole in the window in order to display SurfaceView's Surface. This might explain why mirroring the content SurfaceView displays isn't possible, though I'm not sure why zooming in (scaleX set to values > 1) and out (scaleX set to values between 0 and 1) work nonetheless.

            Source https://stackoverflow.com/questions/65577507

            QUESTION

            Getting relative rotation from the camera sensor to the current device orientation
            Asked 2020-Jul-31 at 07:19

            There are a couple of samples to get the relative rotation from the camera sensor to the current device orientation, e.g. for using it for correcting camera preview or for MediaRecorder.setOrientationHint(int)

            But the newest method from the latest official github camera samples works different than older methods (for deprecated camera2 API and method from archived camera2 sample)

            Here's my sample code that uses all methods and logs all results, we can see that function computeRelativeRotationCamera2New returns different result for Surface.ROTATION_90 and Surface.ROTATION_270 display rotation

            So what is the correct method to do it?

            ...

            ANSWER

            Answered 2020-Jul-31 at 07:19

            Tested recorded videos with different methods and found out that the newest method from the latest sample is incorrect for landscape video recording, it plays videos upside down

            I decided to update old method that uses deprecated camera api to use camera2 api (works for 21+ API) and use it in my project

            Source https://stackoverflow.com/questions/63174125

            QUESTION

            Is bindToLifecycle() is necessary to switch ON/OFF/AUTO flash every time after creating preview in CameraX library
            Asked 2020-Jun-05 at 17:59

            As I understand from many implementations such as :

            https://github.com/android/camera-samples/tree/master/CameraXBasic

            https://proandroiddev.com/android-camerax-preview-analyze-capture-1b3f403a9395

            After every use case in CameraX implementation cameraProvide.bindToLifecycle() method needs to be called.

            For example, if I need to switch ON the FLASH_MODE of the camera from the default OFF mode, then again bindToLifecycle() method needs to be called.

            The disadvantage with this approach is that for a second or two the preview is removed and re-attached which doesn't feel like a smooth transition for an app.

            Is there any better practice available or it is the limitation?

            I Have attached a sample code below:

            ...

            ANSWER

            Answered 2020-Jun-05 at 17:59

            To enable or disable the flash during an image capture after you've created an ImageCapture instance and bound it to a lifecycle, you can use ImageCapture.setFlashMode(boolean).

            Regarding your question about the difference between setting the flash mode before vs after binding the ImageCapture use case, AFAIK there isn't much of a difference really. When you take a picture by calling ImageCapture.takePicture(), a capture request is built using different configuration parameters, one of them is the flash mode. So as long as the flash mode is set before this call (ImageCapture.takePicture()), the output of the capture request should be the same.

            CameraX currently uses Camera2 under the hood, to better understand how the flash mode is set when taking a picture, you can take a look at CaptureRequest.FLASH_MODE.

            Source https://stackoverflow.com/questions/62204461

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install camera-samples

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/android/camera-samples.git

          • CLI

            gh repo clone android/camera-samples

          • sshUrl

            git@github.com:android/camera-samples.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link