Ask Your Question

garyp's profile - activity

2014-07-07 03:50:16 -0500 received badge  Good Answer (source)
2013-10-14 03:18:05 -0500 received badge  Supporter (source)
2013-08-12 03:15:09 -0500 received badge  Nice Answer (source)
2013-08-08 05:40:13 -0500 received badge  Teacher (source)
2013-08-08 02:35:57 -0500 received badge  Necromancer (source)
2013-08-07 19:55:09 -0500 received badge  Editor (source)
2013-08-07 19:52:37 -0500 answered a question How to work with OPENCV4ANDROID- in android studio

Android Studio uses gradle as the build system for Android projects. Until the OpenCV Android SDK ships with support for gradle out-of-the-box, I find it easiest to first convert the SDK to a gradle project from Eclipse before using it from Android Studio. To do this:

  1. If you don't have it installed already, install the Eclipse Android Developer Tools bundle from

  2. Make sure you have the latest version of the Eclipse ADT plugin installed.

  3. Download and extract the OpenCV Android SDK (e.g.

  4. Open Eclipse and import the OpenCV Android SDK using the instructions on the OpenCV website. Note: When selecting the root directory to import, use the OpenCV-2.4.6-android-sdk/sdk/java sub-directory and not the top-level OpenCV-2.4.6-android-sdk directory as the instructions on that site suggest.

  5. Select File > Export. In the window that appears, open Android and select Generate Gradle build files.

Your copy of the OpenCV Android SDK should now be properly configured to be built by gradle. To use it from a new project in Android Studio:

  1. Create the Android app project using the New Project wizard in Android Studio. Make sure you set the minimum Android SDK to at least version 8 (this is what the OpenCV Android SDK declares as its minimum). For the following instructions, I'll assume the project is using the default name of "MyApplicationProject".

  2. Copy/move your copy of the OpenCV Android SDK into the new project directory (e.g. copy the OpenCV-2.4.6-android-sdk/sdk/java directory to MyApplicationProject/opencv-android).

  3. Open MyApplicationProject/settings.gradle and add ':opencv-android' to the include line. The new line should look similar to this:

    include ':MyApplication', ':opencv-android'
  4. Open MyApplicationProject/MyApplication/build.gradle and add "compile project(':opencv-android')" to the dependencies section. Make sure this is the top-level dependencies section and not the one inside of the buildscript section at the top of the file. The new dependencies section should look similar to this:

    dependencies {
        compile ''
        compile project(':opencv-android')
  5. In Android Studio, select Tools > Android > Sync Project with Gradle Files.

Your new project can now use the OpenCV Android SDK from Android Studio. For example, you should be able to implement the "Hello World" example from the OpenCV Android tutorial (skip all of the Eclipse setup instructions and just make the layout, Android manifest, and main activity changes inside MyApplication).

2013-08-07 18:03:17 -0500 answered a question Opencv java build error in Ubuntu 13.04

You shouldn't need to install a local copy of libv4l. The libv4l-dev package in Ubuntu should be sufficient. Here is the full list of steps I had to perform to compile OpenCV from source under Ubuntu 13.04 with Java support:

# install basic development environment
sudo apt-get install build-essential cmake pkg-config

# install opencv dependencies. ubuntu 13.04 ships with opencv
# 2.4.2, which is close enough to 2.4.6 to pull in most of the
# needed dependencies.
sudo apt-get build-dep libopencv-dev
# additional dependencies for java support
sudo apt-get install default-jdk ant

# compile opencv
tar xzvf opencv-
cd opencv-
mkdir build; cd build
sudo make install

If you're still having trouble, can you post the full cmake command you're using?

OpenGL support (optional)

If you need OpenGL support, you'll want to "sudo apt-get install libgtkglext1-dev" and add "-D WITH_OPENGL=ON" to the list of cmake arguments.

OpenCL support (optional)

To compile with OpenCL support, you'll want to "sudo apt-get install ocl-icd-opencl-dev", apply the following patch (if you're on a 64-bit system), and then prefix the above cmake command with "OCLROOT=/usr" (i.e. "OCLROOT=/usr cmake -D ...".

--- opencv-  2013-07-10 11:49:00.000000000 +0000
+++ opencv-       2013-08-02 17:37:11.105800999 +0000
@@ -21,7 +21,7 @@

     if (X86_64)
-      set(OPENCL_POSSIBLE_LIB_SUFFIXES lib/Win64 lib/x86_64 lib/x64)
+      set(OPENCL_POSSIBLE_LIB_SUFFIXES lib/Win64 lib/x86_64 lib/x64 lib/x86_64-linux-gnu)
     elseif (X86)
       set(OPENCL_POSSIBLE_LIB_SUFFIXES lib/Win32 lib/x86)