Setting up the Eclipse Workspace

Note

For a refresher on installing Eclipse and OpenCV as part of TADP, refer to the section Tegra Android Development Pack in Chapter 1, Preparing for the Mission. The same section also contains instructions for building and running OpenCV's Android demos.

To keep things organized, we should create a new Eclipse Workspace for our Android project. Start Eclipse. Eclipse might automatically open a Workspace Launcher window, where you can select a directory for a new workspace. Alternatively, you can open a Workspace Launcher window, as shown in the following screenshot, by going to File | Switch Workspace | Other…:

Setting up the Eclipse Workspace

Click on the Browse… button and select a root folder for our projects, as shown in the preceding screenshot. We will use Eclipse to create individual project folders under this root folder.

Setting up the Eclipse Workspace

Since our apps will depend on OpenCV, we need to import the OpenCV library project that we obtained with TADP in Chapter 1, Preparing for the Mission. Go to File | Import…. From the Import window shown in the preceding screenshot, select General | Existing Projects into Workspace and click on the Next > button.

Setting up the Eclipse Workspace

Next to the Select root directory field, click on the Browse… button and select the root folder of the OpenCV library project. Remember TADP's installation path, which we refer to as <tadp>. By default, <tadp> is C:\NVPACK (in Windows) or ~/NVPACK (in Mac and Linux). The path to the OpenCV library project is <tadp>/OpenCV-2.4.8.2-Tegra-sdk/sdk/java, assuming the version is 2.4.8.2 (the latest at the time of writing). After selecting the path, ensure that the checkbox next to the OpenCV Library – 2.8.4.2 project is checked and click on the Finish button, as shown in the preceding screenshot.

Setting up the Eclipse Workspace

Right-click on the OpenCV Library – 2.4.8.2 folder in the Package Explorer pane and select Properties from the context menu. Select the Android section and ensure that the Is Library checkbox is checked, as shown in the preceding screenshot. For the build target, ensure that a recent Android version is checkmarked. Generally, the latest stable Android version should be a safe choice, and particularly for OpenCV 2.4.x, Android 4.0+ should work. Regardless of the selected build target, OpenCV 2.4.x is built for backward compatibility with Android 2.2+. After reviewing the settings and making changes if needed, click on the OK button.

Now, we are ready to create the Eclipse project for Goldgesture. Go to File | New | Android Application Project. This opens the New Android Application window as shown in the following screenshot:

Setting up the Eclipse Workspace

Our app name is Goldgesture, its package name is com.nummist.goldgesture, and its minimum Android SDK version is API level 8, which is Android 2.2 (as required by OpenCV 2.4.x). The app should target and be compiled with the latest stable Android SDK version. Configure the first form in the New Android Application window as shown in the preceding screenshot. Click the first form's Next > button. A new form appears, as shown in the following screenshot:

Setting up the Eclipse Workspace

Uncheck the Create custom launcher item checkbox and click on the Next > button, as shown in the preceding screenshot. Now, select Blank Activity and click on the Next > button, as shown in the following screenshot:

Setting up the Eclipse Workspace

For the final form, enter CameraActivity in the Activity Name field. Click on the Finish button as shown in the following screenshot:

Setting up the Eclipse Workspace

The Goldgesture project is created, but we still need to specify its dependency on the OpenCV library project. Right-click on the Goldgesture folder in the Package Explorer pane and select Properties from the context menu. Now, select the Android section and click on the Add… button next to the Library list, as shown in the following screenshot:

Setting up the Eclipse Workspace

Then, select OpenCV Library – 2.4.5. Click on the OK buttons. The OpenCV library is now linked with Goldgesture.