SlideShare a Scribd company logo
4
Most read
10
Most read
12
Most read
Why camera?
●   Kind of light sensor :)
●   Take pictures, record video
●   Background image for AR
    ●   Layar
●   Input for computer vision/image processing
    ●   Pose estimation
    ●   Heartbeat
    ●   Spectrometer
Outline
●   Why is camera important
●   Camera API
●   Basic usage
●   Camera in emulator
●   Image formats
Camera API
●   Permissions

●   import android.hardware.Camera;
●   Open/release
    ●   Constructor is private => Camera.open()
●   Where is display?
    ●   Create your own extending SurfaceView
    ●   Add to activity using setContentView
Image pipeline
Typical usage



                     get instance of SurfaceHolder



                         register for callback
                     on surface create and destroy




         set buffer type to
  SURFACE_TYPE_PUSH_BUFFERS
Typical usage (contd.)
    called once the surface was fully initialized




                                    get instance of camera




                                      set fully initialized surface
                                                to camera
Typical usage (contd.)
          called when surface size changes




                              stop preview just to be sure




                                             set width&height
                                          for the camera picture

    tell camera to start
 sending frames to surface
Typical usage (contd.)
      called when surface is destroyed




                                         stop preview


                                     important!
                              camera is shared resource
Demo
Webcam in emulator
●   Don't do that
●   Emulator
    ●   Infinite sample loop (box over checkers)
    ●   Custom SocketCamera
        –   Video input from webcam is sent to server on emulator
        –   Really slow
    ●   Only for quick prototype
●   Real phone is much better
Processing camera input
●   Before Froyo (Android 1.0-2.1)
    ●
        setPreviewCallback → onPreviewFrame




●   Froyo and beyond (Android 2.2)
    ●   Create&reuse your own buffer - addCallbackBuffer
    ●
        setPreviewCallbackWithBuffer → onPreviewFrame
    ●   After processing data from buffer add it back to
        queue using addCallbackBuffer
What is in byte[] data?
●   Image byte by byte
●   PixelFormat – YUV/NV21, RGB565
    ●   Luckily many algorithms work in grayscale
●   YUV (YCbCr_420_SP/NV21)
What is in byte[] data? (contd.)
●   YUV (YCbCr_420_SP/NV21)
    ●   Default format (on older versions the only available)
    ●   Full greyscale (people are more sensitive)
        –   First width*height bytes
    ●   Subsampled blue and red (chroma)
    ●   Use greyscale - first width*height bytes – and don't
        bother with the rest
What is in byte[] data? (contd.)
●   RGB565 – 16 bits – 2 bytes per pixel
          5         6         5
    ●   RRRRRGGG|GGGBBBBB
         data[2n]       data[2n+1]
What is camera actually?
Issues
●   Slow – 15 ps
●   Blurred at low light
●   Narrower angle of view
●   Rolling shutter (no global shutter) – skewed
    image
Issues (contd.)
●   Getting image from sensor takes time – smaller
    time slot for calculations
    ●   Caution - onPreviewFrame called too many times
        when you do much processing =>
        setOneShotPreviewCallback
●   Distortion
More fun with camera
●   Do something with computer vision
    ●   We worked with OpenCV on android
        –   Works but be careful about performance
    ●   Edge detection
    ●   Feature tracking
    ●   Face detection
●   Motion detection
●   Daylight sensor
●   Whatever you can think of :)
Use the source, Luke!
●   http://android.git.kernel.org
    is your friend

●   Camera:
    ●   [platform/frameworks/base.git]
        /core/java/android/hardware
        /Camera.java
    ●   [platform/frameworks/base.git]
        /jni/android_hardware_Camera.cpp

More Related Content

PDF
Broadcast Receivers in Android
PDF
Mobile Application Design & Development
PPT
Learning AOSP - Android Booting Process
PPTX
Android UI
PDF
A deep dive into Android OpenSource Project(AOSP)
PDF
Embedded Android : System Development - Part I
PPTX
Broadcast Receiver
PPTX
Android internals By Rajesh Khetan
Broadcast Receivers in Android
Mobile Application Design & Development
Learning AOSP - Android Booting Process
Android UI
A deep dive into Android OpenSource Project(AOSP)
Embedded Android : System Development - Part I
Broadcast Receiver
Android internals By Rajesh Khetan

What's hot (20)

ODP
Q4.11: Porting Android to new Platforms
PPTX
Flutter workshop
PDF
Cypress Automation Testing Tutorial (Part 1).pdf
PPTX
Android+init+process
PPT
Introduction to Skia by Ryan Chou @20141008
PPTX
Flutter Intro
PDF
Introduction to Flutter - truly crossplatform, amazingly fast
PPTX
Android audio system(audio_hardwareinterace)
PPTX
Android audio system(audioflinger)
PDF
JavaScript - Chapter 13 - Browser Object Model(BOM)
PDF
Basics and different xml files used in android
PDF
Embedded Android : System Development - Part II (HAL)
PDF
Building beautiful apps with Google flutter
PPTX
Android Thread
PPTX
Presentation on Android application life cycle and saved instancestate
PDF
Embedded Android : System Development - Part II (Linux device drivers)
ODP
Android Camera Architecture
PDF
Init of Android
PDF
Embedded Android Workshop with Pie
PPTX
Camera 2.0 in Android 4.2
Q4.11: Porting Android to new Platforms
Flutter workshop
Cypress Automation Testing Tutorial (Part 1).pdf
Android+init+process
Introduction to Skia by Ryan Chou @20141008
Flutter Intro
Introduction to Flutter - truly crossplatform, amazingly fast
Android audio system(audio_hardwareinterace)
Android audio system(audioflinger)
JavaScript - Chapter 13 - Browser Object Model(BOM)
Basics and different xml files used in android
Embedded Android : System Development - Part II (HAL)
Building beautiful apps with Google flutter
Android Thread
Presentation on Android application life cycle and saved instancestate
Embedded Android : System Development - Part II (Linux device drivers)
Android Camera Architecture
Init of Android
Embedded Android Workshop with Pie
Camera 2.0 in Android 4.2
Ad

Viewers also liked (10)

PDF
Building a Custom Camera Application in Android
PDF
Droidcon NYC 2014: Building Custom Camera Applications
PDF
Wifi api android
PDF
Android Wi-Fi Manager and Bluetooth Connection
PPT
Android Audio & OpenSL
PDF
Camera obscura pinhole
PPTX
The history of the pinhole camera
PDF
Android media framework overview
PDF
Design and Concepts of Android Graphics
PDF
Booting Android: bootloaders, fastboot and boot images
Building a Custom Camera Application in Android
Droidcon NYC 2014: Building Custom Camera Applications
Wifi api android
Android Wi-Fi Manager and Bluetooth Connection
Android Audio & OpenSL
Camera obscura pinhole
The history of the pinhole camera
Android media framework overview
Design and Concepts of Android Graphics
Booting Android: bootloaders, fastboot and boot images
Ad

Similar to Android Camera (20)

PPTX
Hidden Camera 3 APIs in Android 4.4 (KitKat)
PPTX
qtdd11_qtmultimediakitonmobile
PDF
Flowframes
PDF
Inside Android's UI
PDF
Inside Android's UI / ABS 2013
PDF
Inside Android's UI at AnDevCon VI
PDF
Inside Android's UI at AnDevCon V
PPTX
Android 5.0 Camera2 APIs
PDF
Alex_Vlachos_Advanced_VR_Rendering_GDC2015
PPTX
How to deal with Fragmentation on Android
PDF
Sony HXR-NX70E Operation Manual
PDF
Practical SPU Programming in God of War III
PDF
Smedberg niklas bringing_aaa_graphics
PDF
Virtual projector
PPTX
AGDK tutorial step by step
PDF
Android Platform Debugging and Development
KEY
Gtug
PDF
Cloud Spin - building a photo booth with the Google Cloud Platform
PDF
Camera2 API: Overview
PPTX
VR Optimization Techniques
Hidden Camera 3 APIs in Android 4.4 (KitKat)
qtdd11_qtmultimediakitonmobile
Flowframes
Inside Android's UI
Inside Android's UI / ABS 2013
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon V
Android 5.0 Camera2 APIs
Alex_Vlachos_Advanced_VR_Rendering_GDC2015
How to deal with Fragmentation on Android
Sony HXR-NX70E Operation Manual
Practical SPU Programming in God of War III
Smedberg niklas bringing_aaa_graphics
Virtual projector
AGDK tutorial step by step
Android Platform Debugging and Development
Gtug
Cloud Spin - building a photo booth with the Google Cloud Platform
Camera2 API: Overview
VR Optimization Techniques

Recently uploaded (20)

PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Hybrid model detection and classification of lung cancer
PPTX
A Presentation on Artificial Intelligence
PDF
project resource management chapter-09.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
A Presentation on Touch Screen Technology
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Encapsulation theory and applications.pdf
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
1 - Historical Antecedents, Social Consideration.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Enhancing emotion recognition model for a student engagement use case through...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hybrid model detection and classification of lung cancer
A Presentation on Artificial Intelligence
project resource management chapter-09.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Heart disease approach using modified random forest and particle swarm optimi...
Building Integrated photovoltaic BIPV_UPV.pdf
A Presentation on Touch Screen Technology
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
A comparative study of natural language inference in Swahili using monolingua...
Encapsulation theory and applications.pdf
SOPHOS-XG Firewall Administrator PPT.pptx
A comparative analysis of optical character recognition models for extracting...
1 - Historical Antecedents, Social Consideration.pdf

Android Camera

  • 1. Why camera? ● Kind of light sensor :) ● Take pictures, record video ● Background image for AR ● Layar ● Input for computer vision/image processing ● Pose estimation ● Heartbeat ● Spectrometer
  • 2. Outline ● Why is camera important ● Camera API ● Basic usage ● Camera in emulator ● Image formats
  • 3. Camera API ● Permissions ● import android.hardware.Camera; ● Open/release ● Constructor is private => Camera.open() ● Where is display? ● Create your own extending SurfaceView ● Add to activity using setContentView
  • 5. Typical usage get instance of SurfaceHolder register for callback on surface create and destroy set buffer type to SURFACE_TYPE_PUSH_BUFFERS
  • 6. Typical usage (contd.) called once the surface was fully initialized get instance of camera set fully initialized surface to camera
  • 7. Typical usage (contd.) called when surface size changes stop preview just to be sure set width&height for the camera picture tell camera to start sending frames to surface
  • 8. Typical usage (contd.) called when surface is destroyed stop preview important! camera is shared resource
  • 10. Webcam in emulator ● Don't do that ● Emulator ● Infinite sample loop (box over checkers) ● Custom SocketCamera – Video input from webcam is sent to server on emulator – Really slow ● Only for quick prototype ● Real phone is much better
  • 11. Processing camera input ● Before Froyo (Android 1.0-2.1) ● setPreviewCallback → onPreviewFrame ● Froyo and beyond (Android 2.2) ● Create&reuse your own buffer - addCallbackBuffer ● setPreviewCallbackWithBuffer → onPreviewFrame ● After processing data from buffer add it back to queue using addCallbackBuffer
  • 12. What is in byte[] data? ● Image byte by byte ● PixelFormat – YUV/NV21, RGB565 ● Luckily many algorithms work in grayscale ● YUV (YCbCr_420_SP/NV21)
  • 13. What is in byte[] data? (contd.) ● YUV (YCbCr_420_SP/NV21) ● Default format (on older versions the only available) ● Full greyscale (people are more sensitive) – First width*height bytes ● Subsampled blue and red (chroma) ● Use greyscale - first width*height bytes – and don't bother with the rest
  • 14. What is in byte[] data? (contd.) ● RGB565 – 16 bits – 2 bytes per pixel 5 6 5 ● RRRRRGGG|GGGBBBBB data[2n] data[2n+1]
  • 15. What is camera actually?
  • 16. Issues ● Slow – 15 ps ● Blurred at low light ● Narrower angle of view ● Rolling shutter (no global shutter) – skewed image
  • 17. Issues (contd.) ● Getting image from sensor takes time – smaller time slot for calculations ● Caution - onPreviewFrame called too many times when you do much processing => setOneShotPreviewCallback ● Distortion
  • 18. More fun with camera ● Do something with computer vision ● We worked with OpenCV on android – Works but be careful about performance ● Edge detection ● Feature tracking ● Face detection ● Motion detection ● Daylight sensor ● Whatever you can think of :)
  • 19. Use the source, Luke! ● http://android.git.kernel.org is your friend ● Camera: ● [platform/frameworks/base.git] /core/java/android/hardware /Camera.java ● [platform/frameworks/base.git] /jni/android_hardware_Camera.cpp