Acquisitions Editor: Mariann Barsolo

Development Editor: Gary Schwartz

Technical Editor: John Nyquist

Production Editor: Dassi Zeidel

Copy Editor: Liz Welch

Editorial Manager: Pete Gaughan

Production Manager: Tim Tate

Vice President and Executive Group Publisher: Richard Swadley

Vice President and Publisher: Neil Edde

Book Designer: Caryl Gorska

Compositor: Chris Gillespie, Happenstance Type-O-Rama

Proofreader: Candace English

Indexer: Ted Laux

Project Coordinator, Cover: Katherine Crocker

Cover Designer: Ryan Sneed

Cover Image: Tony Mullen

Copyright © 2011 by John Wiley & Sons, Inc., Indianapolis, Indiana

Published simultaneously in Canada

ISBN: 978-1-118-03663-1

ISBN: 978-1-118-18005-1 (ebk.)

ISBN: 978-1-118-18007-5 (ebk.)

ISBN: 978-1-118-18006-8 (ebk.)

No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permitted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600. Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley & Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://www.wiley.com/go/permissions.

Limit of Liability/Disclaimer of Warranty: The publisher and the author make no representations or warranties with respect to the accuracy or completeness of the contents of this work and specifically disclaim all warranties, including without limitation warranties of fitness for a particular purpose. No warranty may be created or extended by sales or promotional materials. The advice and strategies contained herein may not be suitable for every situation. This work is sold with the understanding that the publisher is not engaged in rendering legal, accounting, or other professional services. If professional assistance is required, the services of a competent professional person should be sought. Neither the publisher nor the author shall be liable for damages arising herefrom. The fact that an organization or Web site is referred to in this work as a citation and/or a potential source of further information does not mean that the author or the publisher endorses the information the organization or Web site may provide or recommendations it may make. Further, readers should be aware that Internet Web sites listed in this work may have changed or disappeared between when this work was written and when it is read.

For general information on our other products and services or to obtain technical support, please contact our Customer Care Department within the U.S. at (877) 762-2974, outside the U.S. at (317) 572-3993 or fax (317) 572-4002.

Wiley also publishes its books in a variety of electronic formats and by print-on-demand. Not all content that is available in standard print versions of this book may appear or be packaged in all book formats. If you have purchased a version of this book that did not include media that is referenced by or accompanies a standard print version, you may request this media by visiting http://booksupport.wiley.com. For more information about Wiley products, visit us at www.wiley.com.

Library of Congress Control Number: 2011937513

TRADEMARKS: Wiley, the Wiley logo, and the Sybex logo are trademarks or registered trademarks of John Wiley & Sons, Inc. and/or its affiliates, in the United States and other countries, and may not be used without written permission. All other trademarks are the property of their respective owners. John Wiley & Sons, Inc. is not associated with any product or vendor mentioned in this book.

10 9 8 7 6 5 4 3 2 1

Dear Reader,

Thank you for choosing Prototyping Augmented Reality. This book is part of a family of premium-quality Sybex books, all of which are written by outstanding authors who combine practical experience with a gift for teaching.

Sybex was founded in 1976. More than 30 years later, we’re still committed to producing consistently exceptional books. With each of our titles, we’re working hard to set a new standard for the industry. From the paper we print on, to the authors we work with, our goal is to bring you the best books available.

I hope you see all that reflected in these pages. I’d be very interested to hear your comments and get your feedback on how we’re doing. Feel free to let me know what you think about this or any other Sybex book by sending me an email at nedde@wiley.com. If you think you’ve found a technical error in this book, please visit http://sybex.custhelp.com. Customer feedback is critical to our efforts at Sybex.

Best regards,

Neil Edde

Vice President and Publisher

Sybex, an Imprint of Wiley

For my family

Acknowledgments

I’d like to thank Acquisitions Editor Mariann Barsolo, Editorial Manager Pete Gaughan, Development Editor Gary Schwartz, Technical Editor John Nyquist, Editorial Assistants Jenni Housh and Connor O’Brien, Production Editor Dassi Zeidel, Copyeditor Liz Welch, and everyone else at Sybex who contributed to putting this book together. I’m also very grateful to the dedicated software developers who contributed their time and effort to create the open source software used in this book, including the ARToolKit, NyARToolkit, Processing, Blender, and JMonkeyEngine developers. I want to single out Adam Clarkson, creator of ARMonkeyKit, in particular for his help with the content of this book.

About the Author

Tony Mullen, PhD, has a broad background in CG and programming. He teaches at Tsuda College in Tokyo, Japan, where his courses include Python programming as well as Blender modeling and animation. He has been a cartoonist and an illustrator; his screen credits include writer, codirector, and lead animator on several short films, including the award-winning live-action/stop-motion film “Gustav Braustache and the Auto-Debilitator” (2007). He is the author of Introducing Character Animation with Blender; 3D for iPhone Apps with Blender and SIO2; Mastering Blender, Bounce, Tumble, and Splash!: Simulating the Physical World with Blender 3D, and Blender Studio Projects: Digital Movie-Making, all from Sybex.

About the Technical Editor

John R. Nyquist is a Blender Foundation Certified Trainer (BFCT) and has created seven Blender and two ActionScript training videos for CartoonSmart.com, as well as 60 episodes of Bits of Blender. He has worked professionally using Blender/Python, Java, ActionScript, C++, C#, and Lingo for interactive multimedia. John has coauthored two books on Director/Lingo and has served as technical editor for books on Java, Director, and Lingo.

Introduction

Augmented Reality (AR) is a term used for a wide range of related technologies aimed at integrating virtual content and data with live, real-time media. The idea of AR is to mingle what is not really there with what is there as seamlessly as possible, and to present users with an enhanced, or augmented, display of the world around them. The nature of the augmentation could be anything from a textual display of data overlaid on real scenes or objects to complete, interactive 3D graphical scenes integrated into real ones.

AR depends crucially on hardware that is able to capture information about the real world, such as video, position data, orientation data, and potentially other forms of data, and also able to play back a display that mixes live media with virtual content in a way that is meaningful and useful to users.

With the recent ubiquity of smartphones, just about everybody now has in their pockets hardware with exciting AR potential. This has contributed to an explosion of interest in AR development, both for mobile platforms and in general. With the widespread use of webcams on laptops and desktop computers, browser-based AR for marketing and creative purposes has begun to boom. Inexpensive cameras and displays also make it possible to set up on-site AR installations cheaply and easily, as LEGO did with their brilliant AR-based marketing campaign in which AR stations were set up at toy stores to enable customers to hold a box up to the camera and see the completed 3D model in the display, fully integrated into the live camera video.

There are several major varieties of AR, and each is a broad topic in itself. Currently available books about mobile AR mainly focus on AR that uses location (GPS) and orientation (accelerometer) data from a mobile device to annotate or integrate content into live scenery. These applications know what your smartphone camera is viewing because they know where you’re standing and which direction your smartphone is pointing. Based on this data, annotations that have been uploaded, either by a centralized service or by other users, can be overlaid on the scene in your camera.

Another, but by no means mutually exclusive, approach to AR is to use the actual image content captured by a camera to determine what is being viewed. This technology is known as computer vision, for obvious reasons. The computer processes each pixel of each video frame, evaluating each pixel’s relationship with neighboring pixels in both time and space, and identifies patterns. Among other things, the current state of the art of computer vision includes accurate algorithms for face recognition, identifying moving objects in videos, and the ability to recognize familiar markers, or specific visual patterns that have been identified in advance to the algorithm, in a very robust way.

Computer vision–based AR can be used in both mobile contexts and non-mobile contexts. It can be used to enhance location- and orientation-based AR methods, and it can also be used to create AR applications that are not tied in any way to a specific location. The computer-vision algorithm can be made to recognize patterns on packaging, products, clothing, artwork, or in any number of other contexts.

This book is concerned with tools and technologies used for computer vision–based AR. Aside from its potential use in marketing campaigns and the like, computer vision–based AR is a lot of fun and, in my opinion, a bit magical. This aspect was what motivated me to begin investigating the subject and ultimately to write this book. I think that the creative potential of this technology has only begun to be explored, and I am eager to see people take it further. This is also why this book is geared less toward professional developers and more toward creative people who want to have fun exploring the possibilities before getting too bogged down in the technical demands of creating stable, ready-to-deploy software.

To these ends, I’ve tried to keep the technologies discussed in this book as accessible as possible. This is why a large portion of the book is devoted to the Processing programming environment. Processing is perhaps the most accessible programming environment around for creating visual, interactive programs. Processing is open source and cross-platform, and was developed specifically with the needs of artists and creative people in mind, people who are not necessarily highly skilled programmers. Processing has a comparatively gentle learning curve, but is remarkably powerful in spite of its simplicity. In addition to learning the basics of programming in Processing, you’ll learn how to create animated 3D content using the open source 3D application Blender. This portion of the book is entirely optional; 3D content files are provided for download if you want to follow the other chapters without making your own.

In the interest of keeping things as accessible as possible, I’ve also stuck with AR technologies that use markers. Markers are printable patterns that provide AR systems with easy-to-recognize reference points. Because of the need for real-world markers, marker-based AR has some definite limitations. The technology exists to do some very impressive things with markerless AR. Markerless AR systems are able to create AR environments that reference other recognizable features of a video stream. For example, a markerless AR system might be made to recognize human faces or other objects, without the need for an explicitly printed marker.

The problem is that, at present, the available markerless AR technologies of which I am aware are not very accessible to nonprogrammers. By contrast, there is a variety of marker-based libraries that I think are comparatively easy to get running. This will certainly change in the future.

The Goals of This Book

This book is intended to give a broad introduction to some of the most accessible and usable tools for computer vision– and marker-based AR content creation. In doing so, a certain amount of programming is unavoidable, but programming is not the primary objective of this book. This book will show you how to get started using a wide variety of tools, each of which has different functions and benefits. Although there are overlaps, each of the tools depends on a different set of programming skills. To get the most out of these tools, you will need to pick up the ball in going further in your study of the programming environments you want to use. Whole shelves exist on the subject of 3D programming in Java or ActionScript, for example, and this book makes no attempt to replace these.

Rather, this book will give you the opportunity to get AR applications up and running on your computer (and potentially on your Android mobile device) and to get the basics of how to go about creating your own content. Depending on the technology, it may be possible to create an interactive AR application yourself quickly. Some of the chapters involve more hands-on programming activities, whereas others provide more cursory glimpses at the technology. You won’t need programming skills to follow the content of the book, but you will need to pick them up if you want to go further with some of the topics.

Ultimately, the goal of this book is to inspire you to do just that. This book should give you a sense of the possibilities already available to you for creating AR applications in a variety of settings. Perhaps you’ll be impressed by the possibilities of physical computing–based AR, and you’ll go further in studying the Arduino and Processing environments. Maybe you’ll get a great idea for a Flash-based AR game to create, and you’ll throw yourself into learning ActionScript. Or maybe this book will inspire you to dive into 3D development in Android. Whatever the case may be, this book is intended to be a first step, not a last step.

Who Should Buy This Book

The title of this book is Prototyping Augmented Reality, and the focus of the book is not on creating polished, deployment-ready software, but rather on experimenting with and demonstrating AR applications, hopefully in as quick and simple a manner as possible. For this reason, the main target readership for this book is people who are creative and eager to explore the possibilities of AR for making fun, interactive applications with a sense of merging the real with the virtual. The book is written deliberately to avoid making assumptions of specific programming experience. Even if you’ve done no programming at all, you should be able to follow along and do some interesting things.

This does not mean that there’s nothing here for professional, experienced developers. The value for more experienced developers will lie mostly in being pointed to interesting technologies and libraries. For people with programming chops in Java or ActionScript, this book should serve as a quick springboard into the world of AR. You won’t learn much programming you don’t already know, but you’ll find out exactly where to start hacking to bring your own AR ideas to life. The breadth of the topics covered here also makes it likely that, even if you’re a fairly experienced developer, there is something new within that might give you some interesting ideas.

Although I try to avoid assuming programming experience in describing this book, the fact is that programming is central to everything this book is about. Any programming experience you have, even in a completely different language, will be useful. Understanding object-oriented programming concepts will make a lot of things in the book more self-evident, and I do take a basic level of programming literacy for granted. If the idea of a “for” loop mystifies you, much of what you’ll find in these pages will be pretty cryptic.

For some of the technologies discussed in this book, programming skills are an absolute must in going further to create your own content. You simply cannot develop AR applications on your own for Android without an understanding of Java, for example. The book’s handling of those topics is intended as a gentle introduction to the AR potential of the environment, not as an in-depth programming course.

In short, this book is intended for anybody with an interest in computer vision– and marker-based AR who isn’t sure where to start exploring the subject. What you get out of the book will depend a lot on what you bring to it.

What’s Inside?

Here is a glance at what’s in each chapter:

Chapter 1: Getting Started with Augmented Reality This chapter provides an overview of augmented reality and broadly introduces the libraries that the rest of the book covers in more depth. The topic of marker creation, which is relevant to all the other chapters, is covered here.

Chapter 2: Introduction to Processing This chapter provides a gentle introduction to the Processing programming environment, suitable for nonprogrammers. The basics of programming in Processing are covered with examples using 2D graphics.

Chapter 3: Blender Modeling and Texturing Basics This chapter gives a brief introduction to modeling and texturing using the open source 3D modeling and animation software called Blender.

Chapter 4: Creating a Low-Poly Animated Character This chapter picks up where Chapter 3 leaves off in creating a textured, low-poly animated character for use in AR applications.

Chapter 5: 3D Programming in Processing This chapter returns to Processing to introduce 3D programming and show what to do with an animated 3D character similar to the one you learned to create in Chapter 4.

Chapter 6: Augmented Reality with Processing This chapter carries what you’ve learned in the previous chapters into the world of AR by introducing special third-party libraries for Processing that enable AR.

Chapter 7: Interacting with the Physical World This chapter introduces the Arduino micro-controller and programming environment for physical computing. You’ll learn to create an AR application that incorporates data from the real world via channels other than video only.

Chapter 8: Browser-Based AR with ActionScript and FLARManager This chapter shows you how to put your AR ideas online by using the FLARManager toolset for creating Flash-based browser AR applications.

Chapter 9: Prototyping AR with jMonkeyEngine This chapter introduces ARMonkeyKit, a powerful tool under development for rapid prototyping of 3D AR applications based on the open source jMonkeyEngine.

Chapter 10: Setting Up NyARToolKit for Android This chapter shows you how to install the NyARToolKit development environment for Android and run AR applications on your Android-based mobile device.

Appendix A: From Blender 2.49 to Blender 2.58 This appendix shows you how to translate the modeling, texturing, and animation concepts you learned in Chapters 3 and 4 from Blender 2.49 into Blender 2.58.

Appendix B: File Formats and Exporting This appendix provides a concise digest of 3D file formats used throughout the book and how you can export your content to the appropriate format for the environment with which you want to work.

Online Companion Files

You’ll find the project files you need to follow the chapters on the book’s companion website, www.sybex.com/go/prototypingar. Where licenses allow, software described in the chapters will also be available as a download from the book’s website in case the corresponding version later becomes unavailable elsewhere.

How to Contact the Author

I welcome feedback from you about this book or about books you’d like to see from me in the future. You can reach me by writing to blender.characters@gmail.com.

Sybex strives to keep you supplied with the latest tools and information you need for your work. Please check the book’s website, www.sybex.com/go/prototypingar, where we’ll post additional content and updates that supplement this book if the need arises.

Chapter 1

Getting Started with Augmented Reality

Augmented reality (AR), in which virtual content is seamlessly integrated with displays of real-world scenes, is an exciting area of interactive design. With the rise of personal mobile devices capable of producing interesting AR environments, the vast potential of AR has begun to be explored. The goal of this chapter is to help you become familiar with the terminology, tools, and technology necessary to begin your own AR explorations and experiments.

In this chapter, you’ll learn about the following topics:

What is augmented reality?

Tools and technologies

AR necessities

What Is Augmented Reality?

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!

Lesen Sie weiter in der vollständigen Ausgabe!