SlideShare a Scribd company logo
1 of 21
Download to read offline
HUYEN TUE DAO
PROJECT
DATE BY
MAY 30, 2014
SAY CHEESE
BUILDING A CUSTOM CAMERA APPLICATION
360dp
wrap_content
ANDEVCON 2014
BUILDING A CUSTOM CAMERA APPLICATION
• Getting Started
• Setting up the Camera
• Taking pictures
• Camera settings
• “New” features in API 14
2
ABOUT ME
• Mobile developer: native Android and native iOS (personally I use
Android but no I do not have a “favorite”)
• Computer Engineering, University of MD, College Park
• Marylander living in Colorado
• Gamer (video, board, card, anything): currently Dota 2, Don’t
Starve, Kingdom Rush, 7 Wonders
3
TITLE
CUSTOM CAMERA CAPABILITY AND AVAILABILITY
What you want to do
What features
the API supports
Typical for Android development: Build.VERSION etc.
What features
the device camera has
Typical for Android development: use-feature and PackageManager
Specific to camera: querying support level from the Camera class
What you can do
THE CUSTOM CAMERA: THE MANIFEST
• Camera application hardware-driven so vital to
separate critical features from optional ones.
• Highly recommended to use specific <uses-feature>
to specify required features. Why?
• <uses-permission
android:name="android.permission.CAMERA" />!
- “This will automatically enforce the <uses-
feature> manifest element for all camera features.”
5
THE CUSTOM CAMERA: THE MANIFEST
• Just specifying the camera permission (without any
<uses-feature> specifications) means that a device
would require the following:
- a back-facing camera
- a front-facing camera
- auto-focus
- flash
• If you do not need any of the above, specify <uses-
feature> with android:required=false
6
TITLE
CAMERA CLASS AND INNER CLASSES
android.hardware.Camera*
Device camera client: setup + access point
Preview callback
Shutter callback
Picture taking callback
!
!
!
Auto Focus callback
Zoom listener
Face detection listener
Camera.CameraInfo
front or back, orientation,
shutter disable
Camera.Parameters
preview, picture output,
“photography stuff”:
features/settings dependent
on the device camera: flash
modes, color effects,
scene modes, white balance,
etc.
Camera.Area
“photography stuff”: focus and
metering, rectangular bounds + weight
Camera.Face
“face stuff”, bounds and feature (left
eye, right eye, mouth) coordinates for
a face identified with face detection,
confidence score
APK 14+: Data objects
Device camera information + settings
Camera.Size
width and height:
picture size, video size,
preview size
TITLE
THE CUSTOM CAMERA: CAMERA SETUP
Add a SurfaceView to your
layout for the camera preview.
Implement a
SurfaceHolder.Callback to
listen for #surfaceCreated,
#surfaceChanged, and
#surfaceDestroyed
Pass the callback to the
SurfaceHolder instance of
the SurfaceView.
Open a Camera instance:
Camera#open
Get the Camera.Parameters
and perform any initial setup.
After the preview surface has
been created, call
Camera#setPreviewDisplay
with the SurfaceHolder.
Start the preview:
Camera#startPreview.
wait for surface to be created
THE CUSTOM CAMERA: BASIC SETUP
• Things to note about setting up the camera preview:
- The surface is destroyed when the visibility of the
SurfaceView is set to View.INVISIBLE.
- Camera#release will stop the preview
- Camera#stopPreview nulls out callbacks, stops face
detection
- Camera#setPreviewDisplay should be called after the
surface is created. No error, just no preview.
- Any changes to the preview size must be between calls to
Camera#startPreview and Camera#stopPreview
9
THE CUSTOM CAMERA: PICTURE TAKING
• When the camera is set up, call
takePicture(ShutterCallback,
PictureCallback, PictureCallback,
PictureCallback)!
• PictureCallback parameters = 3 picture formats:
raw (uncompressed), postview, and JPEG.
- Raw and postview availability depends on device
- takePicture stops the camera preview so
Camera#startPreview should be called in/after
callbacks
10
THE CUSTOM CAMERA: CAMERA INFO
• CameraInfo: information about a particular device camera
- orientation: angle of rotation when facing the camera for the
camera image to match the natural orientation of the device
- facing: camera direction
- whether the shutter sound can be disabled
• Camera.getCameraInfo: camera IDs are indices 0 to n-1
• Use CameraInfo to swap between front and back
- Use PackageManager to check if a front camera exists unless
you have front camera as a requirement for device
- Close the current camera before swapping
11
TITLE
DEVICE ORIENTATION VS CAMERA ORIENTATION
Natural device orientation
Natural camera orientation
90° difference
THE CUSTOM CAMERA: ROTATION
• Some thoughts on rotation:
- Empirically, trying to work with camera/display
rotation and configuration changes sucks:
- Complicated.
- Orientation changes do not coordinate well
with camera orientation changes.
- Can change the activity orientation change
animation in API 18+).
13
THE CUSTOM CAMERA: CAMERA INFO
• Recommendation:
- Keep a fixed activity orientation.
- Call Camera#setDisplayOrientation to adjust
for CameraInfo.orientation.
- Use the OrientationEventListener to rotate
the UI.
- Does mean that your application thumbnail may
look sideways in the Recent Apps list.
14
THE CUSTOM CAMERA: CAMERA PARAMETERS
• Most of the fun stuff (settings and modes) is set in
Camera.Parameters.
- A couple of features (auto-focus and flash) have <uses-feature>
and PackageManager values.
- Most other features will provide support information via methods
in Camera.Parameters
- Example: getMinExposureCompensation returns 0 if exposure
compensation is unsupported
- Several getters provide lists of valid values for features or
modes that have different value ranges on different devices.
- Note that API level also factors: face detection and metering areas
are API 14+.
15
THE CUSTOM CAMERA: CAMERA PARAMETERS
• For the most part, Camera.Parameters can be changed while
preview started and will take effect immediately.
• For saving/restoring settings state, handy methods:
Camera.Parameters#flatten and
Camera.Parameters#unflatten
• Important:
- Always call Camera#getParameters, do not hold onto
Camera.Parameters instances
- To actually change parameters, set values on a
Camera.Parameters instance and call Camera#setParameters
16
THE CUSTOM CAMERA: CAMERA PARAMETERS
• Random tips and observations on Camera.Parameters:
- Auto-focus may cause the flash to activate depending on the
camera and its drivers.
- Setting a scene mode overrides other parameters so if camera
parameters have UI feedback may want to call
Camera#getParameters and update.
• Other common camera/photo features done through
Camera.Parameters:
- GPS coordinates and timestamps for geotagging photos.
- Image size and quality
- Note that image size and preview size are independent
17
THE CUSTOM CAMERA: WORKING WITH AREAS
• API 14: Camera.Area and metering areas and focus
areas
• Camera.Area: defines bounds within the viewfinder
for the camera to use in metering and focus
• Camera viewfinder/sensor has its own coordinate
system different from a View’s coordinate system.
• Otherwise, just like setting other camera
parameters
18
TITLE
VIEWFINDER COORDINATES VS VIEW COORDINATES
1000-1000
1000
-1000
Camera
(0,0)
H
W
View
THE CUSTOM CAMERA: FACE DETECTION
• API 14+
• Camera.Face, Camera.FaceDetectionListener,
Camera#startFaceDetection,
Camera#stopFaceDetection!
• Camera.Face camera coordinates of bounds of
face in viewfinder; maybe left eye, right eye, mouth
position; also confidence
• camera/sensor coordinates -> view coordinates
20
THANKS SO MUCH
FOR COMING!
!
QUESTIONS?
RANDOMLYTYPING.COM
HUYEN@RANDOMLYTYPING.COM
PRESENTER CONTACT
HUYEN TUE DAO
THINGS TO CHECK OUT
Standford Digital Image Processing Class
http://www.stanford.edu/class/ee368/Android/index.html
!
Android Design in Action
https://www.youtube.com/watch?v=OLSa7fErTAM

More Related Content

What's hot

Canon Camera With Flip Screen
Canon Camera With Flip ScreenCanon Camera With Flip Screen
Canon Camera With Flip ScreenBoomi Reviews
 
F8e30016551f18f4374655f76c414a90
F8e30016551f18f4374655f76c414a90F8e30016551f18f4374655f76c414a90
F8e30016551f18f4374655f76c414a90guestf2822a
 
Best canon camera for youtube
Best canon camera for youtubeBest canon camera for youtube
Best canon camera for youtubezertclub
 
Halloween horror nights photography
Halloween horror nights photographyHalloween horror nights photography
Halloween horror nights photographyDEEPAK S. SAWANT
 

What's hot (9)

CAMERA USE, BASICS
CAMERA USE, BASICSCAMERA USE, BASICS
CAMERA USE, BASICS
 
Digital Filming Equipment
Digital Filming Equipment Digital Filming Equipment
Digital Filming Equipment
 
Canon Camera With Flip Screen
Canon Camera With Flip ScreenCanon Camera With Flip Screen
Canon Camera With Flip Screen
 
Android Camera
Android CameraAndroid Camera
Android Camera
 
F8e30016551f18f4374655f76c414a90
F8e30016551f18f4374655f76c414a90F8e30016551f18f4374655f76c414a90
F8e30016551f18f4374655f76c414a90
 
Photography
PhotographyPhotography
Photography
 
Equipment
EquipmentEquipment
Equipment
 
Best canon camera for youtube
Best canon camera for youtubeBest canon camera for youtube
Best canon camera for youtube
 
Halloween horror nights photography
Halloween horror nights photographyHalloween horror nights photography
Halloween horror nights photography
 

Similar to AnDevCon 2014: Building a Custom Camera Application

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 ApplicationsHuyen Tue Dao
 
Android 5.0 Camera2 APIs
Android 5.0 Camera2 APIsAndroid 5.0 Camera2 APIs
Android 5.0 Camera2 APIsBalwinder Kaur
 
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)Balwinder Kaur
 
SunEyes T Series Quick Installation Guide
SunEyes T Series Quick Installation GuideSunEyes T Series Quick Installation Guide
SunEyes T Series Quick Installation GuideSecurityCameraTalk
 
Multi-Modality Mobile Image Recognition Based on Thermal and Visual Cameras
Multi-Modality Mobile Image Recognition Based on Thermal and Visual CamerasMulti-Modality Mobile Image Recognition Based on Thermal and Visual Cameras
Multi-Modality Mobile Image Recognition Based on Thermal and Visual CamerasJui-Hsin (Larry) Lai
 
06.Programming Media on Windows Phone
06.Programming Media on Windows Phone06.Programming Media on Windows Phone
06.Programming Media on Windows PhoneNguyen Tuan
 
Photovoltaic Systems: System Design Tools
Photovoltaic Systems: System Design ToolsPhotovoltaic Systems: System Design Tools
Photovoltaic Systems: System Design ToolsGavin Harper
 
Camera manual auto
Camera manual autoCamera manual auto
Camera manual autoanzar coowar
 
Longshot Marksman Target Cameras Instruction Manual | Optics Trade
Longshot Marksman Target Cameras Instruction Manual | Optics TradeLongshot Marksman Target Cameras Instruction Manual | Optics Trade
Longshot Marksman Target Cameras Instruction Manual | Optics TradeOptics-Trade
 
Mopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKitMopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKitanistar sung
 
Sheldon Fernandes (Lucid VR): Real-time Calibration for Stereo Cameras Using ...
Sheldon Fernandes (Lucid VR): Real-time Calibration for Stereo Cameras Using ...Sheldon Fernandes (Lucid VR): Real-time Calibration for Stereo Cameras Using ...
Sheldon Fernandes (Lucid VR): Real-time Calibration for Stereo Cameras Using ...AugmentedWorldExpo
 
COSCUP 2017 FACE OFF
COSCUP 2017 FACE OFFCOSCUP 2017 FACE OFF
COSCUP 2017 FACE OFFPRADA Hsiung
 
Digital photography improvers course
Digital photography improvers courseDigital photography improvers course
Digital photography improvers courseMike Sleigh
 
"Computer-vision-based 360-degree Video Systems: Architectures, Algorithms an...
"Computer-vision-based 360-degree Video Systems: Architectures, Algorithms an..."Computer-vision-based 360-degree Video Systems: Architectures, Algorithms an...
"Computer-vision-based 360-degree Video Systems: Architectures, Algorithms an...Edge AI and Vision Alliance
 
Luis cataldi-ue4-vr-best-practices2
Luis cataldi-ue4-vr-best-practices2Luis cataldi-ue4-vr-best-practices2
Luis cataldi-ue4-vr-best-practices2Luis Cataldi
 
Camera2 API: Overview
Camera2 API: OverviewCamera2 API: Overview
Camera2 API: OverviewSuhyun Park
 

Similar to AnDevCon 2014: Building a Custom Camera Application (20)

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
 
Android 5.0 Camera2 APIs
Android 5.0 Camera2 APIsAndroid 5.0 Camera2 APIs
Android 5.0 Camera2 APIs
 
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)
 
SunEyes T Series Quick Installation Guide
SunEyes T Series Quick Installation GuideSunEyes T Series Quick Installation Guide
SunEyes T Series Quick Installation Guide
 
Multi-Modality Mobile Image Recognition Based on Thermal and Visual Cameras
Multi-Modality Mobile Image Recognition Based on Thermal and Visual CamerasMulti-Modality Mobile Image Recognition Based on Thermal and Visual Cameras
Multi-Modality Mobile Image Recognition Based on Thermal and Visual Cameras
 
06.Programming Media on Windows Phone
06.Programming Media on Windows Phone06.Programming Media on Windows Phone
06.Programming Media on Windows Phone
 
Photovoltaic Systems: System Design Tools
Photovoltaic Systems: System Design ToolsPhotovoltaic Systems: System Design Tools
Photovoltaic Systems: System Design Tools
 
Camera manual auto
Camera manual autoCamera manual auto
Camera manual auto
 
What is remote focus IP Camera
What is remote focus IP CameraWhat is remote focus IP Camera
What is remote focus IP Camera
 
DSLR Cameras
DSLR Cameras DSLR Cameras
DSLR Cameras
 
Longshot Marksman Target Cameras Instruction Manual | Optics Trade
Longshot Marksman Target Cameras Instruction Manual | Optics TradeLongshot Marksman Target Cameras Instruction Manual | Optics Trade
Longshot Marksman Target Cameras Instruction Manual | Optics Trade
 
Mopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKitMopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKit
 
Sheldon Fernandes (Lucid VR): Real-time Calibration for Stereo Cameras Using ...
Sheldon Fernandes (Lucid VR): Real-time Calibration for Stereo Cameras Using ...Sheldon Fernandes (Lucid VR): Real-time Calibration for Stereo Cameras Using ...
Sheldon Fernandes (Lucid VR): Real-time Calibration for Stereo Cameras Using ...
 
COSCUP 2017 FACE OFF
COSCUP 2017 FACE OFFCOSCUP 2017 FACE OFF
COSCUP 2017 FACE OFF
 
Digital photography improvers course
Digital photography improvers courseDigital photography improvers course
Digital photography improvers course
 
Photography lession 01
Photography  lession  01 Photography  lession  01
Photography lession 01
 
"Computer-vision-based 360-degree Video Systems: Architectures, Algorithms an...
"Computer-vision-based 360-degree Video Systems: Architectures, Algorithms an..."Computer-vision-based 360-degree Video Systems: Architectures, Algorithms an...
"Computer-vision-based 360-degree Video Systems: Architectures, Algorithms an...
 
Luis cataldi-ue4-vr-best-practices2
Luis cataldi-ue4-vr-best-practices2Luis cataldi-ue4-vr-best-practices2
Luis cataldi-ue4-vr-best-practices2
 
Camera2 API: Overview
Camera2 API: OverviewCamera2 API: Overview
Camera2 API: Overview
 
Szdalos
SzdalosSzdalos
Szdalos
 

Recently uploaded

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)jennyeacort
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsChristian Birchler
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf31events.com
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Angel Borroy López
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesŁukasz Chruściel
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsSafe Software
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
Call Us🔝>༒+91-9711147426⇛Call In girls karol bagh (Delhi)
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving CarsSensoDat: Simulation-based Sensor Dataset of Self-driving Cars
SensoDat: Simulation-based Sensor Dataset of Self-driving Cars
 
Sending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdfSending Calendar Invites on SES and Calendarsnack.pdf
Sending Calendar Invites on SES and Calendarsnack.pdf
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
Alfresco TTL#157 - Troubleshooting Made Easy: Deciphering Alfresco mTLS Confi...
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Unveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New FeaturesUnveiling the Future: Sylius 2.0 New Features
Unveiling the Future: Sylius 2.0 New Features
 
Powering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data StreamsPowering Real-Time Decisions with Continuous Data Streams
Powering Real-Time Decisions with Continuous Data Streams
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 

AnDevCon 2014: Building a Custom Camera Application

  • 1. HUYEN TUE DAO PROJECT DATE BY MAY 30, 2014 SAY CHEESE BUILDING A CUSTOM CAMERA APPLICATION 360dp wrap_content ANDEVCON 2014
  • 2. BUILDING A CUSTOM CAMERA APPLICATION • Getting Started • Setting up the Camera • Taking pictures • Camera settings • “New” features in API 14 2
  • 3. ABOUT ME • Mobile developer: native Android and native iOS (personally I use Android but no I do not have a “favorite”) • Computer Engineering, University of MD, College Park • Marylander living in Colorado • Gamer (video, board, card, anything): currently Dota 2, Don’t Starve, Kingdom Rush, 7 Wonders 3
  • 4. TITLE CUSTOM CAMERA CAPABILITY AND AVAILABILITY What you want to do What features the API supports Typical for Android development: Build.VERSION etc. What features the device camera has Typical for Android development: use-feature and PackageManager Specific to camera: querying support level from the Camera class What you can do
  • 5. THE CUSTOM CAMERA: THE MANIFEST • Camera application hardware-driven so vital to separate critical features from optional ones. • Highly recommended to use specific <uses-feature> to specify required features. Why? • <uses-permission android:name="android.permission.CAMERA" />! - “This will automatically enforce the <uses- feature> manifest element for all camera features.” 5
  • 6. THE CUSTOM CAMERA: THE MANIFEST • Just specifying the camera permission (without any <uses-feature> specifications) means that a device would require the following: - a back-facing camera - a front-facing camera - auto-focus - flash • If you do not need any of the above, specify <uses- feature> with android:required=false 6
  • 7. TITLE CAMERA CLASS AND INNER CLASSES android.hardware.Camera* Device camera client: setup + access point Preview callback Shutter callback Picture taking callback ! ! ! Auto Focus callback Zoom listener Face detection listener Camera.CameraInfo front or back, orientation, shutter disable Camera.Parameters preview, picture output, “photography stuff”: features/settings dependent on the device camera: flash modes, color effects, scene modes, white balance, etc. Camera.Area “photography stuff”: focus and metering, rectangular bounds + weight Camera.Face “face stuff”, bounds and feature (left eye, right eye, mouth) coordinates for a face identified with face detection, confidence score APK 14+: Data objects Device camera information + settings Camera.Size width and height: picture size, video size, preview size
  • 8. TITLE THE CUSTOM CAMERA: CAMERA SETUP Add a SurfaceView to your layout for the camera preview. Implement a SurfaceHolder.Callback to listen for #surfaceCreated, #surfaceChanged, and #surfaceDestroyed Pass the callback to the SurfaceHolder instance of the SurfaceView. Open a Camera instance: Camera#open Get the Camera.Parameters and perform any initial setup. After the preview surface has been created, call Camera#setPreviewDisplay with the SurfaceHolder. Start the preview: Camera#startPreview. wait for surface to be created
  • 9. THE CUSTOM CAMERA: BASIC SETUP • Things to note about setting up the camera preview: - The surface is destroyed when the visibility of the SurfaceView is set to View.INVISIBLE. - Camera#release will stop the preview - Camera#stopPreview nulls out callbacks, stops face detection - Camera#setPreviewDisplay should be called after the surface is created. No error, just no preview. - Any changes to the preview size must be between calls to Camera#startPreview and Camera#stopPreview 9
  • 10. THE CUSTOM CAMERA: PICTURE TAKING • When the camera is set up, call takePicture(ShutterCallback, PictureCallback, PictureCallback, PictureCallback)! • PictureCallback parameters = 3 picture formats: raw (uncompressed), postview, and JPEG. - Raw and postview availability depends on device - takePicture stops the camera preview so Camera#startPreview should be called in/after callbacks 10
  • 11. THE CUSTOM CAMERA: CAMERA INFO • CameraInfo: information about a particular device camera - orientation: angle of rotation when facing the camera for the camera image to match the natural orientation of the device - facing: camera direction - whether the shutter sound can be disabled • Camera.getCameraInfo: camera IDs are indices 0 to n-1 • Use CameraInfo to swap between front and back - Use PackageManager to check if a front camera exists unless you have front camera as a requirement for device - Close the current camera before swapping 11
  • 12. TITLE DEVICE ORIENTATION VS CAMERA ORIENTATION Natural device orientation Natural camera orientation 90° difference
  • 13. THE CUSTOM CAMERA: ROTATION • Some thoughts on rotation: - Empirically, trying to work with camera/display rotation and configuration changes sucks: - Complicated. - Orientation changes do not coordinate well with camera orientation changes. - Can change the activity orientation change animation in API 18+). 13
  • 14. THE CUSTOM CAMERA: CAMERA INFO • Recommendation: - Keep a fixed activity orientation. - Call Camera#setDisplayOrientation to adjust for CameraInfo.orientation. - Use the OrientationEventListener to rotate the UI. - Does mean that your application thumbnail may look sideways in the Recent Apps list. 14
  • 15. THE CUSTOM CAMERA: CAMERA PARAMETERS • Most of the fun stuff (settings and modes) is set in Camera.Parameters. - A couple of features (auto-focus and flash) have <uses-feature> and PackageManager values. - Most other features will provide support information via methods in Camera.Parameters - Example: getMinExposureCompensation returns 0 if exposure compensation is unsupported - Several getters provide lists of valid values for features or modes that have different value ranges on different devices. - Note that API level also factors: face detection and metering areas are API 14+. 15
  • 16. THE CUSTOM CAMERA: CAMERA PARAMETERS • For the most part, Camera.Parameters can be changed while preview started and will take effect immediately. • For saving/restoring settings state, handy methods: Camera.Parameters#flatten and Camera.Parameters#unflatten • Important: - Always call Camera#getParameters, do not hold onto Camera.Parameters instances - To actually change parameters, set values on a Camera.Parameters instance and call Camera#setParameters 16
  • 17. THE CUSTOM CAMERA: CAMERA PARAMETERS • Random tips and observations on Camera.Parameters: - Auto-focus may cause the flash to activate depending on the camera and its drivers. - Setting a scene mode overrides other parameters so if camera parameters have UI feedback may want to call Camera#getParameters and update. • Other common camera/photo features done through Camera.Parameters: - GPS coordinates and timestamps for geotagging photos. - Image size and quality - Note that image size and preview size are independent 17
  • 18. THE CUSTOM CAMERA: WORKING WITH AREAS • API 14: Camera.Area and metering areas and focus areas • Camera.Area: defines bounds within the viewfinder for the camera to use in metering and focus • Camera viewfinder/sensor has its own coordinate system different from a View’s coordinate system. • Otherwise, just like setting other camera parameters 18
  • 19. TITLE VIEWFINDER COORDINATES VS VIEW COORDINATES 1000-1000 1000 -1000 Camera (0,0) H W View
  • 20. THE CUSTOM CAMERA: FACE DETECTION • API 14+ • Camera.Face, Camera.FaceDetectionListener, Camera#startFaceDetection, Camera#stopFaceDetection! • Camera.Face camera coordinates of bounds of face in viewfinder; maybe left eye, right eye, mouth position; also confidence • camera/sensor coordinates -> view coordinates 20
  • 21. THANKS SO MUCH FOR COMING! ! QUESTIONS? RANDOMLYTYPING.COM HUYEN@RANDOMLYTYPING.COM PRESENTER CONTACT HUYEN TUE DAO THINGS TO CHECK OUT Standford Digital Image Processing Class http://www.stanford.edu/class/ee368/Android/index.html ! Android Design in Action https://www.youtube.com/watch?v=OLSa7fErTAM