Post date: Mar 07, 2012 9:58:33 PM
Part 1 of several. Overview here.
This portion of the tutorial might not be as fully fledged out as others because I found the OpenCV tutorial on this subject to be adequate. I will attempt to clarify any points that I found rough or any previous knowledge that the OpenCV tutorial implies except basic Java.
The main page of OpenCV for Android is here. And the installation tutorial is here.
If you have no intention of doing other development in Eclipse there is a link to an Android developer package provided by NVIDIA which includes everything you need for Android development except the OpenCV libraries. It is a slightly older version of Eclipse but any samples or tutorials you find should still make sense. They were also likely built on that version of Eclipse.
The basic process described in more detail above is to download Java, Eclipse, The SDK and ADT from Google and the OpenCV library and samples. Then stuff them all together and go to town.
In the tutorial, forum and all over the OpenCV website you will see references to 'The Native Camera' or 'OpenCV Native Camera' which differs from the 'Java Camera' or 'Androiid Java Camera.' Native Camera refers to OpenCV's own camera access methods which are compiled for the device in Native C++. Java Camera refers to Andoid's built in camera methods which are the default mechanism for accessing the camera on Android phones. This can be confusing since the 'Java Camera' is native to android but in this case means that the C++ code is compiled into a binary that is native to the device (the opposite of portable) Rather than Java code which runs in the JVM. More confusing still because neither one is named the way they are referenced.
Android's Camera class. 'Java Camera' in OpenCV parlance.
OpenCV's VideoCapture class. 'Native Camera' in OpenCV parlance.
Some times after importing or copying some of the sample code instead of a reference to the OpenCV library eclipse creates a broken reference to it's own libraries or none at all. Rather than updating the libraries under properties -> Java Build Path do the following.
Right click on your project in Package Explorer.
Choose Properties (Should be at the bottom. Shortcut is ALT + Enter)
Select Android from the list on the left hand side.
Below "Project Build Target' Is the 'Library' section. If there is a link but it is broken (Red X) Select it and choose delete. After or if it is simply missing choose Add. You should see any library projects in your workspace. Select OpenCV and add it to your project.
Once you have the OpenCV samples and library loaded you should be able to run at minimum Tutorial 1 Basic - 0. Android Camera and Tutorial 1 Basic - 1. Add OpenCV in your emulator. Depending on your model of phone those may be the only ones you are able to run. Also some models of phone, Most Motorolas for example, might not run any of the sample projects. I was unable to run them on my Droid 3. Someone out there can because you can download the OpenCV face detection sample from the Android Market.
Important: Even if you are prompted to select a webcam when the emulator runs there is a solid chance that it won't connect to your actual web cam. Mine doesn't. In this case you will see a moving checkerboard background and a floating green square with a red shadow. This is working. I beat my head against this for a couple of days before I figured that out.
Return to part one or continue to part three