Android Tutorial: Augmented Reality With Digital Cameras and QR Code

With the fast movement of mobile technology, it does not matter which operative system you are using. What matters is to be connected with the technology, the novelty and to keep up with regular updates.  Oftentimes, we talk about things that are unknown to us.  For example,  we can focus on programming experiences where the applications we develop use the digital camera.  Today we will use Android Mobile App Development as an example use case.

Augmented reality 2

As good practice for development, it is recommended to focus not only on the hardware functionality in a device, but in the functionally of the whole device. Keep in mind that the rule should fail in the third device that is not being tested. Why?

1. Android is built on the Linux kernel, but Android is not Linux

2. No native windowing system

3. No glibc support

4. Does not include the full set of standard Linux utilities

Another negative is that manufacturers create their own drivers based on Linux whereas Android offers the platform and the environment.  Problems can occur when developing mobile app code by phone range, resolutions and functions.

If you work with cameras, keep in mind that lately the current phones have integrated Camera Front and Camera Back. From developer's side, the code is developed with more functionality and expertise.  However from the user's  side, video chat is adaptable for a front photo. But what happens with devices that only have one camera? Well, you will have to be careful because you will need to recognize the number of cameras in the device. The front camera is labeled by 0 and the back camera with 1 and maybe there could be a third camera with sequential numbering.

After the hardware is recognized, we need to show the focus. One important point to remember when working with native cameras,  is to save steps and call a simple Intent.

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//Save File
fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);

When working with custom cameras, use SurfaceView with SurfaceHolder. Callback is implemented taking into account the following overridden methods in a separate class or nested:

     ¬ surfaceCreated
     ¬ surfaceDestroyed
     ¬ surfaceChanged(advisable method for orientation in landscape, portrait, reverse landscape and reverse portrait)
     ¬ Aspect Ratio
     ¬ Size Area
     ¬ Autofocus
     ¬ Flash

 Adding Attributes to a Photograph as Geotag

Some key software and mobile app developer archictecture questions to ask are:

  1. Do you need to have the location information in the metadata of each photo in with GPS use.
  2. Do you need to record tags with picture information as date, location of the photo taken, time, orientation, white balance, picture size.

And how does it work?

There are attributes for setting using ExifInterface class. For example if we want to record the location point, we make use of Location class: get latitude and longitude:

String exifLatitude = exif2.getAttribute(ExifInterface.<em>TAG_GPS_LATITUDE</em>);
String exifLongitude = exif2.getAttribute(ExifInterface.<em>TAG_GPS_LONGITUDE</em>);
exifs.setExifLatitude(exifLatitude);
exifs.setExifLongitude(exifLongitude);

Picture2

Using QR Codes 

From time to time I used to ask myself, if the current products will stop using the typical barcode. Then the QR appears (Quick Response barcode) and maybe it’s not being used 100% of the time as the barcode, but it has much more to offer for marketing purposes.

The Optical Encryption represents an attractive and powerful tool for the safe handling of information. QR,  is used by thousands of people around the world on their smartphones.

How can I read a QR code?

QR codes require a camera to capture the image code. The encrypted code encrypts 4000 alphanumeric characters.

There are several types of codes and not all are the same:

     ¬ Encrypted messages
     ¬ URL
     ¬ Code user-password access
     ¬ Code Wi-Fi access
     ¬ Code to download a program
     ¬ App store download 

describe the image

Read Hidden Text

Represent an URL QR

Direct URL

App Sotre Download

App Store

We can identify the kind of code with the separation of bits. Text code is much simpler than "download the app" link. Also, we can see that the QR codes can have differnt colors, sizes and strokes.  So there are a lot of combinations to use.

How they are generated?

There are online pages that do it as Kaywa, MSkyNet or INVX. You select which type of QR code you want and write your text, select a picture or provide the URL.  It is easy for any user.

How to Generate the Encryption if I'm a Developer?

The QR code process is 

  • Obtain an image, text or original URL.
  • The image is converted in QR code.
  • The QR code encrypts the optical method and converted into in new image.
  • The receiver decrypts and obtains the original message.

There are 2 libraries in Java for manipulating the code:

ZXing Library:  has a QR code generator for java, is actively developed, and is liberally licensed.

QRCode Library: can include support for encoding and decoding codes, correction of errors, and sample applications.

The following Java code illustrates how to create a QR-Code barcode, and output to various formats.

QRCode barcode = new QRCode();
     barcode.setData("123456789");
      // add more QRCode property settings here
     barcode.renderBarcode("c:/barcode.gif");
     BufferedImage bufferedImage = barcode.renderBarcode();
     byte[] barcodeBytes = barcode.renderBarcodeToBytes();
     Graphics2D g = ...
     Rectangle2D rectangle = ...
     barcode.renderBarcode(g, rectangle);
    OutputStream outputStream = ...
    barcode.renderBarcode(outputStream);

Explanation

     ¬ Create a QRCode barcode object (line 1)
     ¬ Set QRCode object barcode properties (line 2)
     ¬ Generate QR-Code barcode and encode into gif image format (line 3)
     ¬ Generate QR-Code and output to BufferedImage object (line 4)
     ¬ Generate QR-Code in bitmap and output to byte[] (line 5)
     ¬ Generate QR-Code and draw to defined area (Rectangle2D) on Graphics2D (line 6-8)
     ¬ Generate QR-Code and output to OutputStream (line 9-10)

And there you go! Check out my example for a direct link.

Direct URL QR (webinar)

That's all for now. I hope you can stop thinking that the digital camera is only good for taking photos or video, do not be a typical user... explore!

About the Author

Ariana Yadira Lugo is a Computer Systems Engineer and is working on her Masters degree in Internet Technologies. She is currently an Android Developer with nearly 2 years of professional mobile app development experience. She also has experience in Web Development in PHP, CSS, management and design of databases with MySQL and as a network administrator using Fortigate tool. She is a JAVA Sun Certified Programmer with Sun MicroSystems, JAVA Web Component Development with Servlets and JSP Sun MicroSystems and Titanium Certified App Developer (TCAD)

Oscar Salas

Written by Oscar Salas

Oscar Salas is a B2B Digital Marketing Specialist with 5 years of experience, who has helped organizations to grow and expand through strategic brand development and marketing programs. Analytical thinker, cat lover, he enjoys to play the piano and listening to Led Zeppelin He's currently leading the iTexico Demand Gen strategies.

Explore iTexico, The Nearshore + Company 

Learn More

Read More

Mobile Competency Center

Recent Posts