Merged android-experimental branch back to trunk.

This commit is contained in:
Andrey Kamaev
2011-04-06 14:31:03 +00:00
parent bbdd0aecbd
commit 68534d70f3
120 changed files with 3483 additions and 1620 deletions

View File

@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 2.8)
project(CVCamera)
add_subdirectory(jni)

View File

@@ -1,86 +0,0 @@
# The path to the NDK, requires crystax version r-4 for now, due to support
# for the standard library
# load environment from local make file
LOCAL_ENV_MK=local.env.mk
ifneq "$(wildcard $(LOCAL_ENV_MK))" ""
include $(LOCAL_ENV_MK)
else
$(shell cp sample.$(LOCAL_ENV_MK) $(LOCAL_ENV_MK))
$(info ERROR local environement not setup! try:)
$(info gedit $(LOCAL_ENV_MK))
$(error Please setup the $(LOCAL_ENV_MK) - the default was just created')
endif
ifndef ARM_TARGETS
ARM_TARGETS="armeabi armeabi-v7a"
endif
ANDROID_NDK_BASE = $(ANDROID_NDK_ROOT)
$(info OPENCV_CONFIG = $(OPENCV_CONFIG))
ifndef PROJECT_PATH
$(info PROJECT_PATH defaulting to this directory)
PROJECT_PATH=.
endif
# The name of the native library
LIBNAME = libcvcamera.so
# Find all the C++ sources in the native folder
SOURCES = $(wildcard jni/*.cpp)
HEADERS = $(wildcard jni/*.h)
ANDROID_MKS = $(wildcard jni/*.mk)
SWIG_IS = $(wildcard jni/*.i)
SWIG_MAIN = jni/cvcamera.i
SWIG_JAVA_DIR = src/com/theveganrobot/cvcamera/jni
SWIG_JAVA_OUT = $(wildcard $(SWIG_JAVA_DIR)/*.java)
SWIG_C_DIR = jni/gen
SWIG_C_OUT = $(SWIG_C_DIR)/cvcamera_swig.cpp
BUILD_DEFS=OPENCV_CONFIG=$(OPENCV_CONFIG) \
PROJECT_PATH=$(PROJECT_PATH) \
V=$(V) \
$(NDK_FLAGS) \
ARM_TARGETS=$(ARM_TARGETS)
# The real native library stripped of symbols
LIB = libs/armeabi-v7a/$(LIBNAME) libs/armeabi/$(LIBNAME)
all: $(LIB)
#calls the ndk-build script, passing it OPENCV_ROOT and OPENCV_LIBS_DIR
$(LIB): $(SWIG_C_OUT) $(SOURCES) $(HEADERS) $(ANDROID_MKS)
$(ANDROID_NDK_BASE)/ndk-build $(BUILD_DEFS)
#this creates the swig wrappers
$(SWIG_C_OUT): $(SWIG_IS)
make clean-swig &&\
mkdir -p $(SWIG_C_DIR) &&\
mkdir -p $(SWIG_JAVA_DIR) &&\
swig -java -c++ -I../../android-jni/jni -package "com.theveganrobot.cvcamera.jni" \
-outdir $(SWIG_JAVA_DIR) \
-o $(SWIG_C_OUT) $(SWIG_MAIN)
#clean targets
.PHONY: clean clean-swig cleanall
#this deletes the generated swig java and the generated c wrapper
clean-swig:
rm -f $(SWIG_JAVA_OUT) $(SWIG_C_OUT)
#does clean-swig and then uses the ndk-build clean
clean: clean-swig
$(ANDROID_NDK_BASE)/ndk-build clean $(BUILD_DEFS)

View File

@@ -1 +0,0 @@
make V=0

View File

@@ -1 +0,0 @@
make OPENCV_ROOT=../../opencv V=0 clean

View File

@@ -7,6 +7,6 @@
# "build.properties", and override values to adapt the script to your
# project structure.
android.library.reference.1=../../android-jni
android.library.reference.1=../../android-opencv
# Project target.
target=android-7

View File

@@ -1,21 +0,0 @@
# date: Summer, 2010
# author: Ethan Rublee
# contact: ethan.rublee@gmail.com
#
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
#define OPENCV_INCLUDES and OPENCV_LIBS
include $(OPENCV_CONFIG)
LOCAL_LDLIBS += $(OPENCV_LIBS) $(ANDROID_OPENCV_LIBS) -llog -lGLESv2
LOCAL_C_INCLUDES += $(OPENCV_INCLUDES) $(ANDROID_OPENCV_INCLUDES)
LOCAL_MODULE := cvcamera
LOCAL_SRC_FILES := Processor.cpp gen/cvcamera_swig.cpp
include $(BUILD_SHARED_LIBRARY)

View File

@@ -1,2 +0,0 @@
# The ARMv7 is significanly faster due to the use of the hardware FPU
APP_ABI := $(ARM_TARGETS)

View File

@@ -0,0 +1,62 @@
#########################################################
# Find opencv and android-opencv
#########################################################
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/../../build
CACHE PATH "The path where you built opencv for android")
set(AndroidOpenCV_DIR ${CMAKE_SOURCE_DIR}/../../android-opencv/build
CACHE PATH "The path where you built android-opencv")
find_package(OpenCV REQUIRED)
FIND_PACKAGE(AndroidOpenCV REQUIRED )
#########################################################
#c flags, included, and lib dependencies
#########################################################
#notice the "recycling" of CMAKE_C_FLAGS
#this is necessary to pick up android flags
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -fPIC" )
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
set( LIBRARY_DEPS ${AndroidOpenCV_LIBS} ${OpenCV_LIBS} )
if(ANDROID)
set( LIBRARY_DEPS ${LIBRARY_DEPS} log dl)
endif(ANDROID)
#########################################################
#SWIG STUFF
#########################################################
#the java package to place swig generated java files in
set(MY_PACKAGE com.theveganrobot.cvcamera.jni)
if(NOT ANDROID)
#non android swig and jni
#jni is available by default on android
find_package(JNI REQUIRED)
include_directories(${JNI_INCLUDE_DIRS})
FIND_PACKAGE(SWIG)
endif()
INCLUDE(${SWIG_USE_FILE}) #on android this is found by the cmake toolchain
if(ANDROID)
#this will set the output path for the java package
#and properly create the package declarations in generated java sources
SET_SWIG_JAVA_PACKAGE( ${MY_PACKAGE} ) #defined in the android toolchain
endif(ANDROID)
#this add's the swig path for the opencv wrappers
SET(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} "-I${AndroidOpenCV_SWIG_DIR}" )
SET_SOURCE_FILES_PROPERTIES(cvcamera.i PROPERTIES CPLUSPLUS ON)
#add the swig module, giving it the name, java, and then all of the source files
SWIG_ADD_MODULE(cvcamera java
cvcamera.i #swig file
Processor.cpp #cpp files can be compiled to
)
#link the module like any other
target_link_libraries(cvcamera ${LIBRARY_DEPS} )

View File

@@ -1,4 +0,0 @@
#location of android-opencv port of OpenCV to android
OPENCV_CONFIG=../../build/android-opencv.mk
ANDROID_NDK_ROOT=$(HOME)/android-ndk-r4-crystax
ARM_TARGETS="armeabi armeabi-v7a"

View File

@@ -7,6 +7,6 @@
# "build.properties", and override values to adapt the script to your
# project structure.
android.library.reference.1=../../android-jni
android.library.reference.1=../../android-opencv/
# Project target.
target=android-7

View File

@@ -204,9 +204,9 @@ public class Calibration extends Activity implements CalibrationCallback {
setFullscreen();
disableScreenTurnOff();
setContentView(R.layout.camera);
setContentView(R.layout.calib_camera);
mPreview = (NativePreviewer) findViewById(R.id.nativepreviewer);
mPreview.setPreviewSize(1000, 500);
mPreview.setPreviewSize(800, 400);
mPreview.setGrayscale(true);
LinearLayout glview_layout = (LinearLayout) findViewById(R.id.glview_layout);
glview = new GL2CameraViewer(getApplication(), false, 0, 0);

View File

@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.OpenCV_SAMPLE" android:versionCode="1"
android:versionName="1.0">
<application android:label="@string/app_name"
android:debuggable="true" android:icon="@drawable/icon">
<activity android:name=".OpenCV_SAMPLE" android:label="@string/app_name"
android:screenOrientation="landscape" android:configChanges="orientation|keyboardHidden|keyboard">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- These activities are defined in the android-opencv library, and just
reused here -->
<activity android:name="com.opencv.camera.CameraConfig"
android:label="@string/app_name" android:screenOrientation="landscape"
android:configChanges="orientation|keyboardHidden|keyboard">
</activity>
</application>
<uses-sdk android:minSdkVersion="7" />
<!-- set the opengl version -->
<uses-feature android:glEsVersion="0x00020000" />
<!-- use the camera -->
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
</manifest>

View File

@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 2.8)
project(OpenCV_SAMPLE)
add_subdirectory(jni)

View File

@@ -0,0 +1,12 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system use,
# "build.properties", and override values to adapt the script to your
# project structure.
# Project target.
target=android-7
android.library.reference.1=../../android-opencv/

View File

@@ -0,0 +1,68 @@
#########################################################
# Find opencv and android-opencv
#########################################################
set(OpenCV_DIR ${CMAKE_SOURCE_DIR}/../../build
CACHE PATH "The path where you built opencv for android")
set(AndroidOpenCV_DIR ${CMAKE_SOURCE_DIR}/../../android-opencv/build
CACHE PATH "The path where you built android-opencv")
find_package(OpenCV REQUIRED)
FIND_PACKAGE(AndroidOpenCV REQUIRED )
#########################################################
#c flags, included, and lib dependencies
#########################################################
#notice the "recycling" of CMAKE_C_FLAGS
#this is necessary to pick up android flags
set( CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -pedantic -fPIC" )
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
set( LIBRARY_DEPS ${AndroidOpenCV_LIBS} ${OpenCV_LIBS} )
if(ANDROID)
set( LIBRARY_DEPS ${LIBRARY_DEPS} log dl)
endif(ANDROID)
#########################################################
#SWIG STUFF
#########################################################
#the java package to place swig generated java files in
set(MY_PACKAGE com.OpenCV_SAMPLE.jni )
set(MY_MODULE OpenCV_SAMPLE )
set(MY_SWIG
OpenCV_SAMPLE.i #swig file
)
set(MY_SRCS
cvsample.cpp #cpp files can be compiled to
)
if(NOT ANDROID)
#non android swig and jni
#jni is available by default on android
find_package(JNI REQUIRED)
include_directories(${JNI_INCLUDE_DIRS})
FIND_PACKAGE(SWIG)
endif()
INCLUDE(${SWIG_USE_FILE}) #on android this is found by the cmake toolchain
if(ANDROID)
#this will set the output path for the java package
#and properly create the package declarations in generated java sources
SET_SWIG_JAVA_PACKAGE( ${MY_PACKAGE} ) #defined in the android toolchain
endif(ANDROID)
#this add's the swig path for the opencv wrappers
SET(CMAKE_SWIG_FLAGS ${CMAKE_SWIG_FLAGS} "-I${AndroidOpenCV_SWIG_DIR}" )
SET_SOURCE_FILES_PROPERTIES(${MY_SWIG} PROPERTIES CPLUSPLUS ON)
#add the swig module, giving it the name, java, and then all of the source files
SWIG_ADD_MODULE(${MY_MODULE} java
${MY_SWIG}
${MY_SRCS}
)
#link the module like any other
target_link_libraries(${MY_MODULE} ${LIBRARY_DEPS} )

View File

@@ -0,0 +1,48 @@
/* File : foobar.i */
%module OpenCV_SAMPLE
/*
* the java import code muse be included for the opencv jni wrappers
* this means that the android project must reference opencv/android as a project
* see the default.properties for how this is done
*/
%pragma(java) jniclassimports=%{
import com.opencv.jni.*; //import the android-opencv jni wrappers
%}
%pragma(java) jniclasscode=%{
static {
try {
//load up our shared libraries
System.loadLibrary("android-opencv");
System.loadLibrary("OpenCV_SAMPLE");
} catch (UnsatisfiedLinkError e) {
//badness
throw e;
}
}
%}
//import the android-cv.i file so that swig is aware of all that has been previous defined
//notice that it is not an include....
%import "android-cv.i"
%{
#include "cvsample.h"
using cv::Mat;
%}
//make sure to import the image_pool as it is
//referenced by the Processor java generated
//class
%typemap(javaimports) CVSample "
import com.opencv.jni.*;// import the opencv java bindings
"
class CVSample
{
public:
void canny(const Mat& input, Mat& output, int edgeThresh);
void invert(Mat& inout);
void blur(Mat& inout, int half_kernel_size);
};

View File

@@ -0,0 +1,27 @@
#include "cvsample.h"
#include <opencv2/imgproc/imgproc.hpp>
void CVSample::canny(const cv::Mat& input, cv::Mat& output, int edgeThresh)
{
if (input.empty())
return;
cv::Mat gray;
if (input.channels() == 3)
{
cv::cvtColor(input, gray, CV_RGB2GRAY);
}
else
gray = input;
cv::Canny(gray, output, edgeThresh, edgeThresh * 3, 3);
}
void CVSample::invert(cv::Mat& inout)
{
cv::bitwise_not(inout, inout);
}
void CVSample::blur(cv::Mat& inout, int half_kernel_size)
{
int ksz = half_kernel_size*2 + 1;
cv::Size kernel(ksz,ksz);
cv::blur(inout,inout,kernel);
}

View File

@@ -0,0 +1,11 @@
#pragma once
#include <opencv2/core/core.hpp>
class CVSample
{
public:
void canny(const cv::Mat& input, cv::Mat& output, int edgeThresh);
void invert(cv::Mat& inout);
void blur(cv::Mat& inout, int half_kernel_size);
};

View File

@@ -0,0 +1,3 @@
#this generates an ant based cli build of the android-jni project
android update project --name OpenCV_SAMPLE \
--path .

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
</LinearLayout>

View File

@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/cv_menu_invert" android:title="Invert"></item>
<item android:id="@+id/cv_menu_canny" android:title="Canny"></item>
<item android:id="@+id/cv_menu_blur" android:title="Blur"></item>
<item android:id="@+id/cv_menu_nothing" android:title="Nothing"></item>
</menu>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World, OpenCV_SAMPLE!</string>
<string name="app_name">OpenCV SAMPLE</string>
</resources>

View File

@@ -0,0 +1,87 @@
package com.OpenCV_SAMPLE;
import java.util.LinkedList;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import com.OpenCV_SAMPLE.jni.CVSample;
import com.opencv.camera.CameraActivity;
import com.opencv.camera.NativeProcessor;
import com.opencv.camera.NativeProcessor.PoolCallback;
import com.opencv.jni.Mat;
import com.opencv.jni.image_pool;
public class OpenCV_SAMPLE extends CameraActivity {
private int do_what = R.id.cv_menu_nothing;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater menu_flater = new MenuInflater(this);
menu_flater.inflate(R.menu.sample_menu, menu);
return true;
}
@Override
public boolean onMenuItemSelected(int featureId, MenuItem item) {
switch (item.getItemId()) {
case R.id.cv_menu_blur:
case R.id.cv_menu_canny:
case R.id.cv_menu_invert:
case R.id.cv_menu_nothing:
do_what = item.getItemId();
break;
default:
return false;
}
return true;
}
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
protected LinkedList<PoolCallback> getCallBackStack() {
LinkedList<PoolCallback> list = new LinkedList<NativeProcessor.PoolCallback>();
list.add(samplePoolCallback);
return list;
}
CVSample cvsample = new CVSample();
Mat canny = new Mat();
PoolCallback samplePoolCallback = new PoolCallback() {
@Override
public void process(int idx, image_pool pool, long timestamp,
NativeProcessor nativeProcessor) {
Mat grey = pool.getGrey(idx);
Mat color = pool.getImage(idx);
Mat draw_img = color;
switch (do_what) {
case R.id.cv_menu_blur:
cvsample.blur(draw_img, 5);
break;
case R.id.cv_menu_canny:
cvsample.canny(grey, canny, 15);
draw_img = canny;
break;
case R.id.cv_menu_invert:
cvsample.invert(draw_img);
break;
case R.id.cv_menu_nothing:
break;
}
pool.addImage(idx + 1, draw_img);
glview.getDrawCallback().process(idx + 1, pool, timestamp,
nativeProcessor);
}
};
}