SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

Android activity
Android activityAndroid activity
Android activity
Krazy Koder
 
Android webservices
Android webservicesAndroid webservices
Android webservices
Krazy Koder
 

Mais procurados (20)

Android's Multimedia Framework
Android's Multimedia FrameworkAndroid's Multimedia Framework
Android's Multimedia Framework
 
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspectiveAndroid graphic system (SurfaceFlinger) : Design Pattern's perspective
Android graphic system (SurfaceFlinger) : Design Pattern's perspective
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Android activity
Android activityAndroid activity
Android activity
 
Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Android Mp3 Player
Android Mp3 PlayerAndroid Mp3 Player
Android Mp3 Player
 
Supporting multiple screens on android
Supporting multiple screens on androidSupporting multiple screens on android
Supporting multiple screens on android
 
Android Storage - Vold
Android Storage - VoldAndroid Storage - Vold
Android Storage - Vold
 
Material Design in Android
Material Design in Android Material Design in Android
Material Design in Android
 
How to install android sdk
How to install android sdkHow to install android sdk
How to install android sdk
 
Jetpack Compose.pptx
Jetpack Compose.pptxJetpack Compose.pptx
Jetpack Compose.pptx
 
Project meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture OverviewProject meeting: Android Graphics Architecture Overview
Project meeting: Android Graphics Architecture Overview
 
Android Multimedia Support
Android Multimedia SupportAndroid Multimedia Support
Android Multimedia Support
 
Android media framework overview
Android media framework overviewAndroid media framework overview
Android media framework overview
 
08 android multimedia_framework_overview
08 android multimedia_framework_overview08 android multimedia_framework_overview
08 android multimedia_framework_overview
 
Flappy Bird Game
Flappy Bird GameFlappy Bird Game
Flappy Bird Game
 
Embedded Android : System Development - Part IV
Embedded Android : System Development - Part IVEmbedded Android : System Development - Part IV
Embedded Android : System Development - Part IV
 
Android Audio System
Android Audio SystemAndroid Audio System
Android Audio System
 
Android webservices
Android webservicesAndroid webservices
Android webservices
 
Data Persistence in Android with Room Library
Data Persistence in Android with Room LibraryData Persistence in Android with Room Library
Data Persistence in Android with Room Library
 

Destaque (8)

Building a Custom Camera Application in Android
Building a Custom Camera Application in AndroidBuilding a Custom Camera Application in Android
Building a Custom Camera Application in Android
 
Droidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera ApplicationsDroidcon NYC 2014: Building Custom Camera Applications
Droidcon NYC 2014: Building Custom Camera Applications
 
Wifi api android
Wifi api androidWifi api android
Wifi api android
 
Android Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth ConnectionAndroid Wi-Fi Manager and Bluetooth Connection
Android Wi-Fi Manager and Bluetooth Connection
 
Android Audio & OpenSL
Android Audio & OpenSLAndroid Audio & OpenSL
Android Audio & OpenSL
 
Camera obscura pinhole
Camera obscura pinholeCamera obscura pinhole
Camera obscura pinhole
 
The history of the pinhole camera
The history of the pinhole cameraThe history of the pinhole camera
The history of the pinhole camera
 
Booting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot imagesBooting Android: bootloaders, fastboot and boot images
Booting Android: bootloaders, fastboot and boot images
 

Semelhante a Android Camera

Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VI
Opersys inc.
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon V
Opersys inc.
 
Alex_Vlachos_Advanced_VR_Rendering_GDC2015
Alex_Vlachos_Advanced_VR_Rendering_GDC2015Alex_Vlachos_Advanced_VR_Rendering_GDC2015
Alex_Vlachos_Advanced_VR_Rendering_GDC2015
Alex Vlachos
 
Sony HXR-NX70E Operation Manual
Sony HXR-NX70E Operation ManualSony HXR-NX70E Operation Manual
Sony HXR-NX70E Operation Manual
AV ProfShop
 
Smedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicsSmedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphics
changehee lee
 

Semelhante a Android Camera (20)

Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)Hidden Camera 3 APIs in Android 4.4 (KitKat)
Hidden Camera 3 APIs in Android 4.4 (KitKat)
 
qtdd11_qtmultimediakitonmobile
qtdd11_qtmultimediakitonmobileqtdd11_qtmultimediakitonmobile
qtdd11_qtmultimediakitonmobile
 
Flowframes
FlowframesFlowframes
Flowframes
 
Inside Android's UI
Inside Android's UIInside Android's UI
Inside Android's UI
 
Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013Inside Android's UI / ABS 2013
Inside Android's UI / ABS 2013
 
Inside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VIInside Android's UI at AnDevCon VI
Inside Android's UI at AnDevCon VI
 
Inside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon VInside Android's UI at AnDevCon V
Inside Android's UI at AnDevCon V
 
Android 5.0 Camera2 APIs
Android 5.0 Camera2 APIsAndroid 5.0 Camera2 APIs
Android 5.0 Camera2 APIs
 
Alex_Vlachos_Advanced_VR_Rendering_GDC2015
Alex_Vlachos_Advanced_VR_Rendering_GDC2015Alex_Vlachos_Advanced_VR_Rendering_GDC2015
Alex_Vlachos_Advanced_VR_Rendering_GDC2015
 
How to deal with Fragmentation on Android
How to deal with Fragmentation on AndroidHow to deal with Fragmentation on Android
How to deal with Fragmentation on Android
 
Sony HXR-NX70E Operation Manual
Sony HXR-NX70E Operation ManualSony HXR-NX70E Operation Manual
Sony HXR-NX70E Operation Manual
 
Practical SPU Programming in God of War III
Practical SPU Programming in God of War IIIPractical SPU Programming in God of War III
Practical SPU Programming in God of War III
 
Smedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphicsSmedberg niklas bringing_aaa_graphics
Smedberg niklas bringing_aaa_graphics
 
Virtual projector
Virtual projectorVirtual projector
Virtual projector
 
AGDK tutorial step by step
AGDK tutorial step by stepAGDK tutorial step by step
AGDK tutorial step by step
 
Android Platform Debugging and Development
Android Platform Debugging and DevelopmentAndroid Platform Debugging and Development
Android Platform Debugging and Development
 
Gtug
GtugGtug
Gtug
 
Cloud Spin - building a photo booth with the Google Cloud Platform
Cloud Spin - building a photo booth with the Google Cloud PlatformCloud Spin - building a photo booth with the Google Cloud Platform
Cloud Spin - building a photo booth with the Google Cloud Platform
 
Camera2 API: Overview
Camera2 API: OverviewCamera2 API: Overview
Camera2 API: Overview
 
VR Optimization Techniques
VR Optimization Techniques VR Optimization Techniques
VR Optimization Techniques
 

Último

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 

Último (20)

Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 

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