We need to create a new Eclipse project for our app. We may do this in the same workspace that we already used for the OpenCV library project and samples. Alternatively, if we use another workspace, we must import the OpenCV library project into this workspace too. (For instructions on setting the workspace and importing the library project, see the Building the OpenCV samples with Eclipse section of Chapter 1, Setting Up OpenCV.)
Open Eclipse to a workspace that contains the library project. Then, from the menu system, navigate to File | New | Android Application Project. The New Android Application window should appear. Enter the options that are shown in the following screenshot:
The Target SDK and Compile With fields should be set to API 11 (Android 3.0) or higher. It is safe to choose the most recent API version, which, at the time of writing, is API 17: Android 4.2 (Jelly Bean). The Minimum Required SDK field should be left at the default, API 8: Android 2.2 (Froyo), because we will write fallbacks to enable our code to run on that version.
Click on the Next button. A checklist should appear. Ensure that the only checked options are Create activity and Create Project in Workspace, as in the following screenshot:
Click on the Next button. A list of activity templates should appear. Select BlankActivity, as in the following screenshot:
Click on the Next button. More options about the activity should appear. Enter CameraActivity
in the Activity Name field, as in the following screenshot:
Click on the Finish button. Our project is created. We should be able to browse its contents in the Package Explorer pane. Let's remove and add some files, according to the following steps:
res/layout/activity_camera.xml
. (Right-click on it, select Delete from the context menu and click on OK.) The layout of our interface will be very simple, so it will be more convenient to create it in Java code instead of this separate XML file. However, if you do want an example of using OpenCV with an XML layout, you may refer to the sample apps that come with the library. See the Building the OpenCV samples with Eclipse section in Chapter 1, Setting Up OpenCV.src/com/nummist/secondsight/LabActivity.java
. (Right-click on com.nummist.secondsight, navigate to New | Class from the context menu, enter LabActivity
in the Name field, and click on Finish.)res/menu/activity_lab.xml
. (Right-click on the parent folder, navigate to New | Android XML File from the context menu, enter activity_lab
in the File field, and click on Finish.)Now, we have the skeleton of our project. Throughout the rest of this chapter, we will edit several files to provide appropriate functionality and content.