eclipse debug yellow highlight

When the debugger stops at a breakpoint, you can continue the debugger session by selecting the Step Over option from the Debug view toolbar (see Figure 9). This steps over the highlighted line of code and continues execution at the next line in the same method (or it will continue in the method from which the current method was called). The variables that are changed as a result of the last step are highlighted in a color (default is yellow).


implements Runnable


Extend 类

extends是子继承父的关键字,继承父之后,可以使用父的方法,也可以复写父的方法。 implements是一个实现一个或者多个接口。



android:configChanges Handles Runtime Changes:

Some device configurations can change during runtime (such as screen orientation, keyboard availability, and language). When such a change occurs, Android restarts the running Activity (onDestroy()is called, followed by onCreate()).

To declare that your activity handles a configuration change, edit the appropriate <activity> element in your manifest file to include the android:configChanges attribute with a value that represents the configuration you want to handle.

The most commonly used values are "orientation" to prevent restarts when the screen orientation changes and "keyboardHidden" to prevent restarts when the keyboard availability changes.


The multiple configuration values can be declared in the attribute by separating them with a pipe | character.



尽管 C/C++ 的执行效率很高,却不拥有 scripting language 里面那些最让人觉得好用的东西,比如不严格的类型检查、garbage collection 等等;

可是很多脚本语言还是需要有 C/C++ 模块的支持的,所谓的模块无非就是对某些 C/C++ 类或者函数的 wrapper,使得原来的一些函数能与脚本语言的解释器进行交互,因此本质上所谓的模块就是一个解释器能够动态载入动态链接库。类似 Matlab 的 mex(每个 mex 的入口函数都是 mexFunction)

  • C++ Dynamic Link Libraries(.dll)
  • linux based libraries(.so)

SWIG(Simplified Wrapper and Interface Generator)  的设计就是通过 swig 命令进行预处理,用一个模块说明文件(一般是 .i 后缀)产生 wrapper,和对应的 C/C++ 程序一起编译连接成为动态链接库。

运行opencv sample,配置参见以前博文

虽然从2.2开始, OpenCV就号称支持Android平台, 但真正能让OpenCV在Android上运行起来还是在2.3.1版本上. 在这个版本上, 我们可以使用Android的Camera,也可以使用OpenCV自带的VideoCapture. 大部分重要的API已经封装成了JAVA接口,可以在Android中直接调用. 比如imread, VideoCapture, Mat等.

OCV T0-Android Camera和 OCV T2 – OpenCV Camera:

人觉得还是Android Camera比较好, 使用起来比较灵活, 用户可以方便的设置各种属性, 比如视频格式, 分辨率, 帧率, 白平衡, 曝光等等. Android的Camera类允许用户设置PreviewCallback, 可以在这里面调OpenCV的api对每帧图像进行处理, 把结果实时显示到屏幕上.





Get Bitmap from an Uri

targetUri = Intentdata.getData();
try { bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri)); targetImage.setImageBitmap(bitmap); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } 
Uri getData()

Retrieve data this intent is operating on.
final static Bitmap getBitmap(ContentResolver cr, Uri url)

Retrieves an image for the given url as a Bitmap.

Bundle extras = Intentdata.getExtras();

Bitmap bmp = (Bitmap) extras.get(“data”); //

Object get(String key)

Returns the entry with the given key as an object.

Google – Loading Large Bitmaps Efficiently

Photo Location:

1.  the uri returned from build-in Gallery app is in the format of “content://media/external/images/…”.

Uri targetUri = data.getData();
static Uri getContentUri(String volumeName)

Get the content:// style URI for the image media table on the given volume.
2. convert it to the real path format (eg. /mnt/sdcard/dropbox/Eric/....png), the following function can be used.
public String getRealPathFromURI(Uri contentUri) {
       String[] proj = { MediaStore.Images.Media.DATA };
       Cursor cursor = managedQuery(contentUri, proj, null, null, null);
       int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
       return cursor.getString(column_index);
final Cursor managedQuery(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

This method is deprecated. Use CursorLoader instead.

 Bitmap orientation:

Exif orientation

For convenience, here is what the letter F would look like if it were tagged correctly and displayed by a program that ignores the orientation tag (thus showing the stored image):
1        2       3      4         5            6           7          8

888888  888888      88  88      8888888888  88                  88  8888888888
88          88      88  88      88  88      88  88          88  88      88  88
8888      8888    8888  8888    88          8888888888  8888888888          88
88          88      88  88
88          88  888888  888888

ExifInterface exif = new ExifInterface(filename);
orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1);//grab the orientation of the image,the most important values are 3, 6 and 8. If the orientation is 6, for example, you can rotate the image like this:

Matrix matrix = new Matrix();
rotatedBitmap = Bitmap.createBitmap(sourceBitmap, 0, 0, sourceBitmap.getWidth(), sourceBitmap.getHeight(), matrix, true);

【error】Failed to load properties file for project

Android plug-in for Eclipse is out of date with respect to your Android SDK. Whenever a new SDK comes out, you should upgrade the Eclipse plug-in and vice-versa.

So after updating, problems still exist:

  1. “heriachical parent:Activity name must be specified”
  2. “The MainActivity in the new Android project seem to be missing the file”
  3. “AndroidManifest.xml: The markup in the document preceding the root element must be well-formed.”

help -> check for update:


  • 问:eclipse_juno + ADT20 新建android application project 的Hierarchical Parent 填什么?
  • 答:正常情况下什么都不用填。

【Error】Opencv Package was not found

1. Download the suitable OCV package:

2. install the OCV apk

CMD ->Go to directory android-sdk/platform-tools ->adb install org.opencv.lib_v24_armv7a_22.apk  //here I copied the apk file into the $Android/android-sdk/platform-tools/, and my AVD emulator uses android 4.1 OS.

3.Fatal error. can’t open camera:

  • OpenCV Tutorial 0 – Android Camera
  • OpenCV Tutorial 1 – Add OpenCV


OpenCV Manager provides the best version of the OpenCV for your hardware. It also receives the latest stability and performance updates for the library.

【zz】Using C++ OpenCV code with Android binary package


The Android way is writing all your code in Java. But somethimes it is not enough and you need to go to a native level and write part of your application in C/C++. This is important when you already have some computer vision functionality which is written in C++ and uses OpenCV, and you want to use it in your Android application, but do not want to rewrite the C++ code to Java. In this case the only way is to use JNI mechanism. It means, that you should add a class with native methods wrapping your C++ functionality into the Java part of your Android application.

This tutorial describes a fast way how to create and build Android applications containing OpenCV code written in C++. It shows how to build an application which uses OpenCV inside its JNI calls.

Please note that before starting this tutorial you should fulfill all the steps, described in the tutorial Using Android binary package with Eclipse.

This tutorial was tested using Ubuntu 10.04 and Windows 7 SP1 operating systems. Nevertheless, it should also work on Mac OS X. If you encounter errors after following the steps described here, feel free to contact us via android-opencv discussion group and we will try to help you.

Prerequisites: Setup NDK

To compile C++ code for Android platform you need Android Native Development Kit (NDK).

You can get the latest version of NDK from the page .

To install Android NDK just extract the archive to some folder on your computer. (Here is installation instructions on the NDK home page:


Before start you can read official Android NDK documentation which is in the Android NDK archive, in the folder docs/.

The main article about using Android NDK build system you can read in the fileANDROID-MK.html.

Also some additional useful information you can read in the files APPLICATION-MK.htmlNDK-BUILD.html, and in the files CPU-ARM-NEON.htmlCPLUSPLUS-SUPPORT.htmlPREBUILTS.html.

Theory: Android application structure

Usually code of an Android application has the following structure:

  • root folder of the project/
    • jni/
    • libs/
    • res/
    • src/
    • AndroidManifest.xml
    • ... other files ...


  • the src folder contains Java code of the application,
  • the res folder contains resources of the application (images, xml files describing UI layout , etc),
  • the libs folder will contain native libraries after successful build,
  • and the jni folder contains C/C++ application source code and NDK’s build and scripts control the C++ build process (they are written in Makefile language).

Also the root folder should contain the following files

  • AndroidManifest.xml file presents essential information about application to the Android system (name of the Application, name of main application’s package, components of the application, required permissions, etc)It can be created using Eclipse wizard or android tool from Android SDK
  • is a text file containing information about target Android platform and other build details.This file is generated by Eclipse or can be created with android tool from Android SDK


Both files (AndroidManifest.xml and are required to compile the C++ part of the application (NDK build system uses information from these files). If any of these files does not exist, compile the Java part of the project before the C++ part.

Theory: How to build Android application having C++ native part (from command line)

Here is the standard way to compile C++ part of an Android application:

  1. Open console and go to the root folder of Android application
    cd <root folder of the project>/


    Alternatively you can go to the folder jni of Android project but samples from OpenCV binary package are configured for building from project root level (because of relative path to the OpenCV library).

  2. Run the following command


    If you are working in cygwin shell and encounter an error saying that NDK does not find some cygwin‘s path then you might need to define the following environment variable:

    export NDK_USE_CYGPATH=1
  3. After executing this command the C++ part of the source code is compiled.

After that the Java part of the application can be (re)compiled (using either Eclipse or antbuild tool).


Some parameters can be set for the ndk-build:

Example 1: Verbose compilation

<path_where_NDK_is_placed>/ndk-build V=1

Example 2: Rebuild all

<path_where_NDK_is_placed>/ndk-build -B

Theory: How to build Android application having C++ native part (from Eclipse)

There are several possible ways to integrate compilation of C++ code by Android NDK into Eclipse compilation process. We recommend the approach taken from this site:


This instructions should be applied for each Android project in Eclipseworkspace. So if you have 3 projects having C++ part then you need to configure 3 builders.

Below is an adapted version of this guide:

  1. Navigate to Package Explorer window and expand your project having JNI resources.

    If you can not see libs folder under this project then you need to create it manually. (It will be required on step 7, but you need to create it before you open project properties.)

  2. Right click on your project in Package Explorer window and select Properties.
  3. In the Properties dialog select Builders menu and press the New… button:

    Configure builders

  4. In the resulting dialog select the Program type and press OK button:

    Choose builder type

  5. In the Main tab fill the following fields:
    • Name – any name for your builder. (“Tutorial 2.1 Builder” in my case.)


      This name has to be unique for each project in your workspace.

    • Location – full path to ndk-build tool.
      • UNIX

        Just put full path to ndk-build into this filed. Also you can add some options to the Arguments:guilabel: fied, for example -B option.

      • Cygwin
        • Instead of path to the ndk-build tool you need to put full path to cygwin‘s bash.exe location. E.g:C:\cygwin\bin\bash.exe.
        • Put full path to ndk-build into the Arguments field E.g.C:\Android\android-ndk-r6\ndk-build.
        • Go to the Environment tab and define an environment variable:
          • PATH – full path to the cygwin tools. E.g. C:\cygwin\bin

    Define environment variables

    • Working Directory – put path to your project into this field. Instead of hardcoding full path you can click Browse Workspace… button and select your project.

    Define environment variables

  6. Go to the Refresh tab and select both Refresh resources upon completion andRecursively include sub-folders.

    Next set the Specific resources option and click Specify resources… button:

    Define environment variables

  7. Select libs folder under your project and click Finish:

    Select resources folder to refresh automatically

  8. Go to the last tab Build options. Make sure that all checkboxes are set as shown on the next screen:

    Configure build options

  9. Next, click the Specify resources… button.
  10. Select jni folder of your project and click the Finish button:

    Select resources to build

  11. Finally press OK in the builder configuration and project properties dialogs. If you have automatic build turned on then console showing build log should appear:

    Select resources to build

Theory: The structure of scripts

The script usually have the following structure:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE    := <module_name>
LOCAL_SRC_FILES := <list of .c and .cpp project files>
<some variable name> := <some variable value>
<some variable name> := <some variable value>


This is the minimal file, which builds a C++ source code of an Android application. Note that the first two lines and the last line are mandatory for

Usually the file is optional, but in case of project using OpenCV, when STL and exceptions are used in C++, it also should be written. Example of the

APP_STL := gnustl_static
APP_CPPFLAGS := -frtti -fexceptions
APP_ABI := armeabi-v7a

Practice: Build samples from OpenCV binary package

OpenCV binary package includes two samples having JNI resources:

  • Tutorial 2 Advanced – 1. Add Native OpenCVThis sample illustrate how you can use OpenCV in C++ but without OpenCV Java API.
  • Tutorial 2 Advanced – 2. Mix Java+Native OpenCVThis sample shows how you can mix OpenCV Java API and native C++ code.

To build these samples you need to:

  1. Fulfill all the steps, described in the tutorial Using Android binary package with Eclipse.
  2. Setup one builder for “Tutorial 2 Advanced – 1. Add Native OpenCV” project (as described in Theory: How to build Android application having C++ native part (from Eclipse))
  3. Setup second builder for “Tutorial 2 Advanced – 2. Mix Java+Native OpenCV”project (repeat the steps from Theory: How to build Android application having C++ native part (from Eclipse))
  4. Clean these projects (in the main Eclipse menu: Project ‣ Clean…)
  5. Run Eclipse build command (if option Build Automatically is not set)

Practice: Create an Android application, which uses OpenCV

To build your own Android application, which uses OpenCV from native part, the following steps should be done:

  1. The archive with OpenCV binary package should be downloaded and extracted to some folder (as example, into the home folder)
  2. We recommend to use an environment variable to specify the location of OpenCV package. Full or relative path hardcoded in jni/ will also work.So, the environment variable OPENCV_PACKAGE_DIR should be defined. The value of the variable should points to the folder, where the OpenCV package has been extracted.

    As an example, on UNIX you can add add the following line into the hidden file.bashrc placed in your home folder:

    export OPENCV_PACKAGE_DIR = <path to the extracted OpenCV package>

    Then relogin (or better reboot your computer).


    without rebooting (or logout) this change might not work.

    If you are a Windows user, then navigate to:

    • Windows 7 / Windows VistaMy Computer (Right Click on Icon) ‣ Properties (Link) ‣ Advanced System Settings (Link) ‣ Advanced (Tab) ‣ Environment Variables (Button) ‣ System variables (Section)
    • Windows XPMy Computer (Right Click on Icon) ‣ Properties (Link) ‣ Advanced (Tab) ‣ Environment Variables (Button) ‣ System variables (Section)

    Create new variable OPENCV_PACKAGE_DIR and similarly to UNIX relogin or reboot.

    If you are setting NDK builder as described above in Theory: How to build Android application having C++ native part (from Eclipse), then you can define this variable in builder settings. It can be done on third Environment tab of the builder configuration window (we have already added some variables to this tab onWindows but skipped it for other platforms).

  3. The file jni/ should be written for the current application using the common rules for the file.For detailed information see the Android NDK documentation from the Android NDK archive, in the file <path_where_NDK_is_placed>/docs/ANDROID-MK.html
  4. The line
    include $(OPENCV_PACKAGE_DIR)/share/OpenCV/

    should be inserted into the jni/ file right after the line

    include $(CLEAR_VARS)


    If your application utilize both native (C++) OpenCV and its Java API you need to put the following line before including to avoid conflict between C++ and Java builders:

  5. The file should exist and should contain lines
    APP_STL := gnustl_static
    APP_CPPFLAGS := -frtti -fexceptions

    Also the line

    APP_ABI := armeabi-v7a

    is recommended for the applications targeting modern ARMs

  6. To build the C++ code the Android NDK script ndk-build should be run in the root directory of application. Then the C++ source code using OpenCV will be built by Android NDK build system. After that the Java part of the application can be rebuild and the application can be installed on an Android device.Note that this step requires calling the ndk-build script from the console. Instead of this step you can use integration of Android NDK into Eclipse as stated above in the section Theory: How to build Android application having C++ native part (from Eclipse) .

Additional C++ support in Eclipse

Note that you can install additional C++ plugins in Eclipse:

  1. Open Help / Install New Software. This shows the Install dialog.
  2. In the Work with drop-down list choose Helios – (or Indigo – depending on your Eclipse version) and wait while the list of available software is loaded.
  3. From the list of available software select Programming Languages ‣ C/C++ Development Tools.
  4. Click Next, click Next again, accept the agreement, and click the Finish button.
  5. When installation is finished, click Reload

set the button background

source from /wyf.jc.Sample_4_2
public void onCreate(Bundle savedInstanceState) { //重写onCreate方法
setContentView(R.layout.main); //设置当前屏幕
Button btn = (Button)findViewById(; //获取Button控件对象
btn.setOnClickListener(new OnClickListener(){ //添加OnClickListener监听器
public void onClick(View v) { //重写onClick方法
Button btn = (Button)findViewById(; //获取Button对象
btn.setBackgroundDrawable(getResources().getDrawable(R.color.btn)); //设置按钮背景
//or btn.setBackgroundColor(getResources().getColor(;
btn.setText(R.string.btn2); //设置按钮显示文字

Just another site

Jing's Blog

Just another site

Start from here......







Just another site

Where On Earth Is Waldo?

A Project By Melanie Coles

the Serious Computer Vision Blog

A blog about computer vision and serious stuff

Cauthy's Blog

paper review...

Cornell Computer Vision Seminar Blog

Blog for CS 7670 - Special Topics in Computer Vision


Life through nerd-colored glasses

Luciana Haill

Brainwaves Augmenting Consciousness



Dr Paul Tennent

and the university of nottingham

turn off the lights, please

A bunch of random, thinned and stateless thoughts around the Web

John's Weblog

Just another weblog

I Am That I Am

Chasing tomorrow's sunrise.