Android Application Programming With Open CV Part-2
Building the
OpenCV samples with Eclipse
Building and running a few
sample applications is a good way to test that OpenCV is correctly set up. At
the same time, we can practice using Eclipse.
We should see a window called Workspace Launcher, which
asks us to select a workspace. A workspace is the root directory for a
set of related Eclipse projects. If we are using TADP, enter <tadp>/nvsample_workspace,
which is a workspace where the OpenCV4Android library, samples, and tutorials
are already set up as projects. Otherwise, enter any location you choose.
We can return to Workspace Launcher anytime via the menu:
File | Switch Workspace | Other….
Now, we should see a window with several panels,
including Package Explorer. If we are not using TAPD, we need to import
the OpenCV sample projects into our new workspace. Right-click on Package
Explorer and select Import… from the context menu
.
The Import window should appear. Select General
| Existing Projects into Workspace, and then click on Next>.
On the second page of the Import window,
enter <opencv>
in the Select root directory: field. Under
the Projects: label, a list of detected projects should appear (If not,
click on Refresh). The list should include OpenCV library, samples, and
tutorials. Ensure that all projects are selected and click on Finish to
import them.
Once the projects are imported, we may need to fix
some configuration issues. Our development environment may have different
paths, and different versions of the Android SDK, than the ones in the samples'
default configuration.
Any resulting errors will be reported in the Problems tab.
The following are some of the
common configuration problems, and their symptoms and solutions:
The target Android version
might not be properly specified. The symptoms are that imports from the java
and android packages fail, and there are error messages such as The project was not built since its build path is
incomplete. The solution is to
right-click on the project in Package Explorer, select Properties from
the context menu, select the Android section, and checkmark one of the
available Android versions. These steps should be repeated for all projects. At
compile time, OpenCV and its samples must target Android 3.0 (API level 11) or
greater, though at runtime they also support Android 2.2 (API level 8) or
greater.
If we are working on Mac or Linux, the C++ samples might be
misconfigured to use the Windows build executable. The symptom is an error
message such as Program
"{ndk}/ndk-build.cmd" not found in PATH. The solution is to right-click on the project in Package
Explorer, select Properties from the context menu, select the C/C++
Build section, and edit the Build command: field to remove the .cmd extension. These steps should be repeated for all the native (C++)
projects, which include OpenCV Sample - face-detection and OpenCV Tutorial 2
- Mixed Processing.
If we are using the projects
in TADP's <tadp>/nvsample_
workspace, we only need to troubleshoot
the projects that have names starting with OpenCV. For this book's purposes,
the other TADP samples are not relevant.
Once the OpenCV projects no
longer show any errors, we can prepare to test them on an Android device.
Recall that the device must have Android 2.2 (Froyo) or a greater version, and
a camera. To enable Eclipse to communicate with the device, we must enable the
device's USB debugging option with the help of the following steps:
1.
Open the Settings app.
2.
On Android 4.2 or greater, go
to the About phone or About tablet section and tap Build
number seven times. This step enables the Developer options section.
3.Go to the Developer options section (on Android 4.0 or
greater) or the Applications | Development section (on Android
3.2 or less). Enable the USB debugging option.
Now, open the Play Store app, and find and install
the OpenCV Manager app. (The app's page in the Play Store should look
similar to the previous screenshot.) OpenCV Manager takes care of checking for
any OpenCV library updates when we run any OpenCV applications.
If you do not have the Play
Store app on your device, then you need to install OpenCV Manager and certain
OpenCV libraries via USB as per the instructions at http://docs.opencv.org/android/service/
doc/UseCases.html.
Now, we must prepare our main
computer for communication with the Android device. The required steps vary,
depending on our operating system.
On Windows, we need to install
the proper USB drivers for the Android device. Different vendors and devices
have different drivers. The official Android documentation provides links to
the various vendors' driver download sites at http://developer.android.com/tools/extras/oem-usb.html#Drivers.
On Linux, before connecting an
Android device via USB, we must specify the device's vendor in a permissions
file. Each vendor has a unique ID number, as listed in the official Android
documentation at http://developer.android.com/tools/
device.html#VendorIds. We will refer to this ID
number as <vendor_id>. To create the permissions file, open a command
prompt application (such as Terminal) and run the following commands:
$ cd /etc/udev/rules.d/
$ sudo touch 51-android.rules
$ sudo chmod a+r
51-android-rules
Note that the permissions file
needs to have root ownership, so we use sudo when creating or modifying it.
Now, open the file in an editor such as gedit:
$ sudo gedit 51-android-rules
For each vendor, append a new
line to the file. Each of these lines should have the following format:
SUBSYSTEM=="usb",
ATTR{idVendor}=="<vendor_id>", MODE="0666",
GROUP="plugdev"
Save the permissions file and
quit the editor.
On Mac,
no special drivers or permissions are required.
Plug the Android device into your computer's USB
port. In Eclipse, select one of the OpenCV sample projects in Package
Explorer. Then, from the menu system, select Run | Run as… | Android
Application.
An Android Device Chooser window
should appear. Your Android device should be listed under Choose a running
Android device. (If the device is not listed, try unplugging it and
plugging it back in. If that does not work, also try disabling and re-enabling
the device's USB debugging option, as described earlier.)
Select
the device and click on OK.
Thank You,See You Next Post.
Visit Our Bangla Web: theit-mela.blogspot.com
|
No comments:
Post a Comment