New sample for CUDA on Android added.
This commit is contained in:
		@@ -15,6 +15,10 @@ add_subdirectory(tutorial-1-camerapreview)
 | 
			
		||||
add_subdirectory(tutorial-2-mixedprocessing)
 | 
			
		||||
add_subdirectory(tutorial-3-cameracontrol)
 | 
			
		||||
 | 
			
		||||
if (HAVE_opencv_gpu)
 | 
			
		||||
  add_subdirectory(tutorial-4-cuda)
 | 
			
		||||
endif()
 | 
			
		||||
 | 
			
		||||
add_subdirectory(native-activity)
 | 
			
		||||
 | 
			
		||||
# hello-android sample
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										8
									
								
								samples/android/tutorial-4-cuda/.classpath
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										8
									
								
								samples/android/tutorial-4-cuda/.classpath
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,8 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<classpath>
 | 
			
		||||
	<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
 | 
			
		||||
	<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
 | 
			
		||||
	<classpathentry kind="src" path="src"/>
 | 
			
		||||
	<classpathentry kind="src" path="gen"/>
 | 
			
		||||
	<classpathentry kind="output" path="bin/classes"/>
 | 
			
		||||
</classpath>
 | 
			
		||||
							
								
								
									
										76
									
								
								samples/android/tutorial-4-cuda/.cproject
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										76
									
								
								samples/android/tutorial-4-cuda/.cproject
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,76 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 | 
			
		||||
<?fileVersion 4.0.0?>
 | 
			
		||||
 | 
			
		||||
<cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
 | 
			
		||||
	<storageModule moduleId="org.eclipse.cdt.core.settings">
 | 
			
		||||
		<cconfiguration id="0.1227367918">
 | 
			
		||||
			<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="0.1227367918" moduleId="org.eclipse.cdt.core.settings" name="Default">
 | 
			
		||||
				<externalSettings/>
 | 
			
		||||
				<extensions>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.VCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GmakeErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.CWDLocator" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
					<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
 | 
			
		||||
				</extensions>
 | 
			
		||||
			</storageModule>
 | 
			
		||||
			<storageModule moduleId="cdtBuildSystem" version="4.0.0">
 | 
			
		||||
				<configuration artifactName="${ProjName}" buildProperties="" description="" id="0.1227367918" name="Default" parent="org.eclipse.cdt.build.core.prefbase.cfg">
 | 
			
		||||
					<folderInfo id="0.1227367918." name="/" resourcePath="">
 | 
			
		||||
						<toolChain id="org.eclipse.cdt.build.core.prefbase.toolchain.1817556292" name="No ToolChain" resourceTypeBasedDiscovery="false" superClass="org.eclipse.cdt.build.core.prefbase.toolchain">
 | 
			
		||||
							<targetPlatform id="org.eclipse.cdt.build.core.prefbase.toolchain.1817556292.437475188" name=""/>
 | 
			
		||||
							<builder autoBuildTarget="" command="${NDKROOT}/ndk-build.cmd" enableAutoBuild="true" enableCleanBuild="false" id="org.eclipse.cdt.build.core.settings.default.builder.141883337" incrementalBuildTarget="" keepEnvironmentInBuildfile="false" managedBuildOn="false" name="Gnu Make Builder" superClass="org.eclipse.cdt.build.core.settings.default.builder"/>
 | 
			
		||||
							<tool id="org.eclipse.cdt.build.core.settings.holder.libs.914869649" name="holder for library settings" superClass="org.eclipse.cdt.build.core.settings.holder.libs"/>
 | 
			
		||||
							<tool id="org.eclipse.cdt.build.core.settings.holder.1504728878" name="Assembly" superClass="org.eclipse.cdt.build.core.settings.holder">
 | 
			
		||||
								<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.1470189286" languageId="org.eclipse.cdt.core.assembly" languageName="Assembly" sourceContentType="org.eclipse.cdt.core.asmSource" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
							<tool id="org.eclipse.cdt.build.core.settings.holder.260316541" name="GNU C++" superClass="org.eclipse.cdt.build.core.settings.holder">
 | 
			
		||||
								<option id="org.eclipse.cdt.build.core.settings.holder.symbols.892620793" superClass="org.eclipse.cdt.build.core.settings.holder.symbols" valueType="definedSymbols">
 | 
			
		||||
									<listOptionValue builtIn="false" value="ANDROID=1"/>
 | 
			
		||||
								</option>
 | 
			
		||||
								<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1772035264" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${NDKROOT}/platforms/android-9/arch-arm/usr/include""/>
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/include""/>
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include""/>
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${CUDA_TOOLKIT_ROOT}/include""/>
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${ProjDirPath}/../../sdk/native/jni/include""/>
 | 
			
		||||
								</option>
 | 
			
		||||
								<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.159439464" languageId="org.eclipse.cdt.core.g++" languageName="GNU C++" sourceContentType="org.eclipse.cdt.core.cxxSource,org.eclipse.cdt.core.cxxHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
							<tool id="org.eclipse.cdt.build.core.settings.holder.1147885196" name="GNU C" superClass="org.eclipse.cdt.build.core.settings.holder">
 | 
			
		||||
								<option id="org.eclipse.cdt.build.core.settings.holder.symbols.1153621931" superClass="org.eclipse.cdt.build.core.settings.holder.symbols" valueType="definedSymbols">
 | 
			
		||||
									<listOptionValue builtIn="false" value="ANDROID=1"/>
 | 
			
		||||
								</option>
 | 
			
		||||
								<option id="org.eclipse.cdt.build.core.settings.holder.incpaths.1841493632" superClass="org.eclipse.cdt.build.core.settings.holder.incpaths" valueType="includePath">
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${NDKROOT}/platforms/android-9/arch-arm/usr/include""/>
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/include""/>
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${NDKROOT}/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include""/>
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${CUDA_TOOLKIT_ROOT}/include""/>
 | 
			
		||||
									<listOptionValue builtIn="false" value=""${ProjDirPath}/../../sdk/native/jni/include""/>
 | 
			
		||||
								</option>
 | 
			
		||||
								<inputType id="org.eclipse.cdt.build.core.settings.holder.inType.608739504" languageId="org.eclipse.cdt.core.gcc" languageName="GNU C" sourceContentType="org.eclipse.cdt.core.cSource,org.eclipse.cdt.core.cHeader" superClass="org.eclipse.cdt.build.core.settings.holder.inType"/>
 | 
			
		||||
							</tool>
 | 
			
		||||
						</toolChain>
 | 
			
		||||
					</folderInfo>
 | 
			
		||||
					<sourceEntries>
 | 
			
		||||
						<entry flags="VALUE_WORKSPACE_PATH" kind="sourcePath" name="jni"/>
 | 
			
		||||
					</sourceEntries>
 | 
			
		||||
				</configuration>
 | 
			
		||||
			</storageModule>
 | 
			
		||||
			<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
 | 
			
		||||
		</cconfiguration>
 | 
			
		||||
	</storageModule>
 | 
			
		||||
	<storageModule moduleId="cdtBuildSystem" version="4.0.0">
 | 
			
		||||
		<project id="OpenCV Tutorial 4 - CUDA OpenCV.null.1819504790" name="OpenCV Tutorial 4 - CUDA"/>
 | 
			
		||||
	</storageModule>
 | 
			
		||||
	<storageModule moduleId="scannerConfiguration">
 | 
			
		||||
		<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
 | 
			
		||||
		<scannerConfigBuildInfo instanceId="0.1227367918">
 | 
			
		||||
			<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
 | 
			
		||||
		</scannerConfigBuildInfo>
 | 
			
		||||
	</storageModule>
 | 
			
		||||
	<storageModule moduleId="refreshScope" versionNumber="1">
 | 
			
		||||
		<resource resourceType="PROJECT" workspacePath="/OpenCV Tutorial 4 - CUDA"/>
 | 
			
		||||
	</storageModule>
 | 
			
		||||
</cproject>
 | 
			
		||||
							
								
								
									
										101
									
								
								samples/android/tutorial-4-cuda/.project
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										101
									
								
								samples/android/tutorial-4-cuda/.project
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,101 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<projectDescription>
 | 
			
		||||
	<name>OpenCV Tutorial 4 - CUDA</name>
 | 
			
		||||
	<comment></comment>
 | 
			
		||||
	<projects>
 | 
			
		||||
	</projects>
 | 
			
		||||
	<buildSpec>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
 | 
			
		||||
			<triggers>auto,full,incremental,</triggers>
 | 
			
		||||
			<arguments>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>?name?</key>
 | 
			
		||||
					<value></value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.append_environment</key>
 | 
			
		||||
					<value>true</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.autoBuildTarget</key>
 | 
			
		||||
					<value></value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.buildArguments</key>
 | 
			
		||||
					<value></value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.buildCommand</key>
 | 
			
		||||
					<value>${NDKROOT}/ndk-build.cmd</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.cleanBuildTarget</key>
 | 
			
		||||
					<value>clean</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.contents</key>
 | 
			
		||||
					<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
 | 
			
		||||
					<value>true</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
 | 
			
		||||
					<value>false</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.enableFullBuild</key>
 | 
			
		||||
					<value>true</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.fullBuildTarget</key>
 | 
			
		||||
					<value></value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.stopOnError</key>
 | 
			
		||||
					<value>true</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
				<dictionary>
 | 
			
		||||
					<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
 | 
			
		||||
					<value>false</value>
 | 
			
		||||
				</dictionary>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>com.android.ide.eclipse.adt.ResourceManagerBuilder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>com.android.ide.eclipse.adt.PreCompilerBuilder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>org.eclipse.jdt.core.javabuilder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>com.android.ide.eclipse.adt.ApkBuilder</name>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
		<buildCommand>
 | 
			
		||||
			<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
 | 
			
		||||
			<triggers>full,incremental,</triggers>
 | 
			
		||||
			<arguments>
 | 
			
		||||
			</arguments>
 | 
			
		||||
		</buildCommand>
 | 
			
		||||
	</buildSpec>
 | 
			
		||||
	<natures>
 | 
			
		||||
		<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
 | 
			
		||||
		<nature>org.eclipse.jdt.core.javanature</nature>
 | 
			
		||||
		<nature>org.eclipse.cdt.core.cnature</nature>
 | 
			
		||||
		<nature>org.eclipse.cdt.core.ccnature</nature>
 | 
			
		||||
		<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
 | 
			
		||||
		<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
 | 
			
		||||
	</natures>
 | 
			
		||||
</projectDescription>
 | 
			
		||||
@@ -0,0 +1,4 @@
 | 
			
		||||
eclipse.preferences.version=1
 | 
			
		||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
 | 
			
		||||
org.eclipse.jdt.core.compiler.compliance=1.6
 | 
			
		||||
org.eclipse.jdt.core.compiler.source=1.6
 | 
			
		||||
							
								
								
									
										38
									
								
								samples/android/tutorial-4-cuda/AndroidManifest.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								samples/android/tutorial-4-cuda/AndroidManifest.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,38 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
          package="org.opencv.samples.tutorial4"
 | 
			
		||||
          android:versionCode="21"
 | 
			
		||||
          android:versionName="2.1">
 | 
			
		||||
 | 
			
		||||
    <application
 | 
			
		||||
        android:label="@string/app_name"
 | 
			
		||||
        android:icon="@drawable/icon"
 | 
			
		||||
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
 | 
			
		||||
 | 
			
		||||
        <activity android:name="Tutorial4Activity"
 | 
			
		||||
                  android:label="@string/app_name"
 | 
			
		||||
                  android:screenOrientation="landscape"
 | 
			
		||||
                  android:configChanges="keyboardHidden|orientation">
 | 
			
		||||
            <intent-filter>
 | 
			
		||||
                <action android:name="android.intent.action.MAIN" />
 | 
			
		||||
                <category android:name="android.intent.category.LAUNCHER" />
 | 
			
		||||
            </intent-filter>
 | 
			
		||||
        </activity>
 | 
			
		||||
    </application>
 | 
			
		||||
 | 
			
		||||
    <supports-screens android:resizeable="true"
 | 
			
		||||
                      android:smallScreens="true"
 | 
			
		||||
                      android:normalScreens="true"
 | 
			
		||||
                      android:largeScreens="true"
 | 
			
		||||
                      android:anyDensity="true" />
 | 
			
		||||
 | 
			
		||||
    <uses-sdk android:minSdkVersion="8" />
 | 
			
		||||
 | 
			
		||||
    <uses-permission android:name="android.permission.CAMERA"/>
 | 
			
		||||
 | 
			
		||||
    <uses-feature android:name="android.hardware.camera" android:required="false"/>
 | 
			
		||||
    <uses-feature android:name="android.hardware.camera.autofocus" android:required="false"/>
 | 
			
		||||
    <uses-feature android:name="android.hardware.camera.front" android:required="false"/>
 | 
			
		||||
    <uses-feature android:name="android.hardware.camera.front.autofocus" android:required="false"/>
 | 
			
		||||
 | 
			
		||||
</manifest>
 | 
			
		||||
							
								
								
									
										16
									
								
								samples/android/tutorial-4-cuda/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								samples/android/tutorial-4-cuda/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,16 @@
 | 
			
		||||
set(sample example-tutorial-4-cuda)
 | 
			
		||||
 | 
			
		||||
ocv_check_dependencies(opencv_core opencv_java opencv_gpu)
 | 
			
		||||
 | 
			
		||||
if (OCV_DEPENDENCIES_FOUND)
 | 
			
		||||
  if(BUILD_FAT_JAVA_LIB)
 | 
			
		||||
    set(native_deps opencv_java opencv_gpu)
 | 
			
		||||
  else()
 | 
			
		||||
    set(native_deps opencv_gpu)
 | 
			
		||||
  endif()
 | 
			
		||||
 | 
			
		||||
  add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS ${OpenCV_BINARY_DIR} SDK_TARGET 11 ${ANDROID_SDK_TARGET} NATIVE_DEPS ${native_deps})
 | 
			
		||||
  if(TARGET ${sample})
 | 
			
		||||
    add_dependencies(opencv_android_examples ${sample})
 | 
			
		||||
  endif()
 | 
			
		||||
endif()
 | 
			
		||||
							
								
								
									
										13
									
								
								samples/android/tutorial-4-cuda/jni/Android.mk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								samples/android/tutorial-4-cuda/jni/Android.mk
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,13 @@
 | 
			
		||||
LOCAL_PATH := $(call my-dir)
 | 
			
		||||
 | 
			
		||||
include $(CLEAR_VARS)
 | 
			
		||||
 | 
			
		||||
CUDA_TOOLKIT_DIR=$(CUDA_TOOLKIT_ROOT)
 | 
			
		||||
include ../../sdk/native/jni/OpenCV.mk
 | 
			
		||||
 | 
			
		||||
LOCAL_MODULE    := cuda_sample
 | 
			
		||||
LOCAL_SRC_FILES := jni_part.cpp
 | 
			
		||||
LOCAL_LDLIBS +=  -llog -ldl
 | 
			
		||||
LOCAL_LDFLAGS += -Os
 | 
			
		||||
 | 
			
		||||
include $(BUILD_SHARED_LIBRARY)
 | 
			
		||||
							
								
								
									
										4
									
								
								samples/android/tutorial-4-cuda/jni/Application.mk
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								samples/android/tutorial-4-cuda/jni/Application.mk
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
APP_STL := gnustl_static
 | 
			
		||||
APP_CPPFLAGS := -frtti -fexceptions
 | 
			
		||||
APP_ABI := armeabi-v7a
 | 
			
		||||
APP_PLATFORM := android-8
 | 
			
		||||
							
								
								
									
										35
									
								
								samples/android/tutorial-4-cuda/jni/jni_part.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										35
									
								
								samples/android/tutorial-4-cuda/jni/jni_part.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,35 @@
 | 
			
		||||
#include <jni.h>
 | 
			
		||||
#include <opencv2/core/core.hpp>
 | 
			
		||||
#include <opencv2/imgproc/imgproc.hpp>
 | 
			
		||||
#include <opencv2/features2d/features2d.hpp>
 | 
			
		||||
#include <opencv2/gpu/gpu.hpp>
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
using namespace cv;
 | 
			
		||||
using namespace cv::gpu;
 | 
			
		||||
 | 
			
		||||
#include <android/log.h>
 | 
			
		||||
 | 
			
		||||
#define LOG_TAG "Cuda"
 | 
			
		||||
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))
 | 
			
		||||
 | 
			
		||||
extern "C" {
 | 
			
		||||
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial4_Tutorial4Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba);
 | 
			
		||||
 | 
			
		||||
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial4_Tutorial4Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba)
 | 
			
		||||
{
 | 
			
		||||
    Mat& mGr  = *(Mat*)addrGray;
 | 
			
		||||
    Mat& mRgb = *(Mat*)addrRgba;
 | 
			
		||||
    vector<KeyPoint> keypoints;
 | 
			
		||||
    GpuMat grGpu(mGr);
 | 
			
		||||
 | 
			
		||||
    FAST_GPU fast(50);
 | 
			
		||||
    fast(grGpu, GpuMat(), keypoints);
 | 
			
		||||
    for( unsigned int i = 0; i < keypoints.size(); i++ )
 | 
			
		||||
    {
 | 
			
		||||
        const KeyPoint& kp = keypoints[i];
 | 
			
		||||
        circle(mRgb, Point(kp.pt.x, kp.pt.y), 10, Scalar(255,0,0,255));
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								samples/android/tutorial-4-cuda/res/drawable/icon.png
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								samples/android/tutorial-4-cuda/res/drawable/icon.png
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 After Width: | Height: | Size: 2.0 KiB  | 
@@ -0,0 +1,11 @@
 | 
			
		||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 | 
			
		||||
    xmlns:tools="http://schemas.android.com/tools"
 | 
			
		||||
    android:layout_width="match_parent"
 | 
			
		||||
    android:layout_height="match_parent" >
 | 
			
		||||
 | 
			
		||||
    <org.opencv.android.JavaCameraView
 | 
			
		||||
        android:layout_width="fill_parent"
 | 
			
		||||
        android:layout_height="fill_parent"
 | 
			
		||||
        android:id="@+id/tutorial4_activity_surface_view" />
 | 
			
		||||
 | 
			
		||||
</LinearLayout>
 | 
			
		||||
							
								
								
									
										4
									
								
								samples/android/tutorial-4-cuda/res/values/strings.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								samples/android/tutorial-4-cuda/res/values/strings.xml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,4 @@
 | 
			
		||||
<?xml version="1.0" encoding="utf-8"?>
 | 
			
		||||
<resources>
 | 
			
		||||
    <string name="app_name">OCV T4 CUDA</string>
 | 
			
		||||
</resources>
 | 
			
		||||
@@ -0,0 +1,166 @@
 | 
			
		||||
package org.opencv.samples.tutorial4;
 | 
			
		||||
 | 
			
		||||
import org.opencv.android.BaseLoaderCallback;
 | 
			
		||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
 | 
			
		||||
import org.opencv.android.LoaderCallbackInterface;
 | 
			
		||||
import org.opencv.android.OpenCVLoader;
 | 
			
		||||
import org.opencv.core.CvType;
 | 
			
		||||
import org.opencv.core.Mat;
 | 
			
		||||
import org.opencv.android.CameraBridgeViewBase;
 | 
			
		||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewListener2;
 | 
			
		||||
import org.opencv.imgproc.Imgproc;
 | 
			
		||||
 | 
			
		||||
import android.app.Activity;
 | 
			
		||||
import android.os.Bundle;
 | 
			
		||||
import android.util.Log;
 | 
			
		||||
import android.view.Menu;
 | 
			
		||||
import android.view.MenuItem;
 | 
			
		||||
import android.view.WindowManager;
 | 
			
		||||
 | 
			
		||||
public class Tutorial4Activity extends Activity implements CvCameraViewListener2 {
 | 
			
		||||
    private static final String    TAG = "OCVSample::Activity";
 | 
			
		||||
 | 
			
		||||
    private static final int       VIEW_MODE_RGBA     = 0;
 | 
			
		||||
    private static final int       VIEW_MODE_GRAY     = 1;
 | 
			
		||||
    private static final int       VIEW_MODE_CANNY    = 2;
 | 
			
		||||
    private static final int       VIEW_MODE_FEATURES = 5;
 | 
			
		||||
 | 
			
		||||
    private int                    mViewMode;
 | 
			
		||||
    private Mat                    mRgba;
 | 
			
		||||
    private Mat                    mIntermediateMat;
 | 
			
		||||
    private Mat                    mGray;
 | 
			
		||||
 | 
			
		||||
    private MenuItem               mItemPreviewRGBA;
 | 
			
		||||
    private MenuItem               mItemPreviewGray;
 | 
			
		||||
    private MenuItem               mItemPreviewCanny;
 | 
			
		||||
    private MenuItem               mItemPreviewFeatures;
 | 
			
		||||
 | 
			
		||||
    private CameraBridgeViewBase   mOpenCvCameraView;
 | 
			
		||||
 | 
			
		||||
    private BaseLoaderCallback  mLoaderCallback = new BaseLoaderCallback(this) {
 | 
			
		||||
        @Override
 | 
			
		||||
        public void onManagerConnected(int status) {
 | 
			
		||||
            switch (status) {
 | 
			
		||||
                case LoaderCallbackInterface.SUCCESS:
 | 
			
		||||
                {
 | 
			
		||||
                    Log.i(TAG, "OpenCV loaded successfully");
 | 
			
		||||
 | 
			
		||||
                    // Load native library after(!) OpenCV initialization
 | 
			
		||||
                    System.loadLibrary("cuda_sample");
 | 
			
		||||
 | 
			
		||||
                    mOpenCvCameraView.enableView();
 | 
			
		||||
                } break;
 | 
			
		||||
                default:
 | 
			
		||||
                {
 | 
			
		||||
                    super.onManagerConnected(status);
 | 
			
		||||
                } break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    public Tutorial4Activity() {
 | 
			
		||||
        Log.i(TAG, "Instantiated new " + this.getClass());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** Called when the activity is first created. */
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onCreate(Bundle savedInstanceState) {
 | 
			
		||||
        Log.i(TAG, "called onCreate");
 | 
			
		||||
        super.onCreate(savedInstanceState);
 | 
			
		||||
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
 | 
			
		||||
 | 
			
		||||
        setContentView(R.layout.tutorial4_surface_view);
 | 
			
		||||
 | 
			
		||||
        mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial4_activity_surface_view);
 | 
			
		||||
        mOpenCvCameraView.setCvCameraViewListener(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public boolean onCreateOptionsMenu(Menu menu) {
 | 
			
		||||
        Log.i(TAG, "called onCreateOptionsMenu");
 | 
			
		||||
        mItemPreviewRGBA = menu.add("Preview RGBA");
 | 
			
		||||
        mItemPreviewGray = menu.add("Preview GRAY");
 | 
			
		||||
        mItemPreviewCanny = menu.add("Canny");
 | 
			
		||||
        mItemPreviewFeatures = menu.add("Find features");
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onPause()
 | 
			
		||||
    {
 | 
			
		||||
        super.onPause();
 | 
			
		||||
        if (mOpenCvCameraView != null)
 | 
			
		||||
            mOpenCvCameraView.disableView();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    public void onResume()
 | 
			
		||||
    {
 | 
			
		||||
        super.onResume();
 | 
			
		||||
        OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_8, this, mLoaderCallback);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onDestroy() {
 | 
			
		||||
        super.onDestroy();
 | 
			
		||||
        if (mOpenCvCameraView != null)
 | 
			
		||||
            mOpenCvCameraView.disableView();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onCameraViewStarted(int width, int height) {
 | 
			
		||||
        mRgba = new Mat(height, width, CvType.CV_8UC4);
 | 
			
		||||
        mIntermediateMat = new Mat(height, width, CvType.CV_8UC4);
 | 
			
		||||
        mGray = new Mat(height, width, CvType.CV_8UC1);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void onCameraViewStopped() {
 | 
			
		||||
        mRgba.release();
 | 
			
		||||
        mGray.release();
 | 
			
		||||
        mIntermediateMat.release();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
 | 
			
		||||
        final int viewMode = mViewMode;
 | 
			
		||||
        switch (viewMode) {
 | 
			
		||||
        case VIEW_MODE_GRAY:
 | 
			
		||||
            // input frame has gray scale format
 | 
			
		||||
            Imgproc.cvtColor(inputFrame.gray(), mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
 | 
			
		||||
            break;
 | 
			
		||||
        case VIEW_MODE_RGBA:
 | 
			
		||||
            // input frame has RBGA format
 | 
			
		||||
            mRgba = inputFrame.rgba();
 | 
			
		||||
            break;
 | 
			
		||||
        case VIEW_MODE_CANNY:
 | 
			
		||||
            // input frame has gray scale format
 | 
			
		||||
            mRgba = inputFrame.rgba();
 | 
			
		||||
            Imgproc.Canny(inputFrame.gray(), mIntermediateMat, 80, 100);
 | 
			
		||||
            Imgproc.cvtColor(mIntermediateMat, mRgba, Imgproc.COLOR_GRAY2RGBA, 4);
 | 
			
		||||
            break;
 | 
			
		||||
        case VIEW_MODE_FEATURES:
 | 
			
		||||
            // input frame has RGBA format
 | 
			
		||||
            mRgba = inputFrame.rgba();
 | 
			
		||||
            mGray = inputFrame.gray();
 | 
			
		||||
            FindFeatures(mGray.getNativeObjAddr(), mRgba.getNativeObjAddr());
 | 
			
		||||
            break;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return mRgba;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public boolean onOptionsItemSelected(MenuItem item) {
 | 
			
		||||
        Log.i(TAG, "called onOptionsItemSelected; selected item: " + item);
 | 
			
		||||
 | 
			
		||||
        if (item == mItemPreviewRGBA) {
 | 
			
		||||
            mViewMode = VIEW_MODE_RGBA;
 | 
			
		||||
        } else if (item == mItemPreviewGray) {
 | 
			
		||||
            mViewMode = VIEW_MODE_GRAY;
 | 
			
		||||
        } else if (item == mItemPreviewCanny) {
 | 
			
		||||
            mViewMode = VIEW_MODE_CANNY;
 | 
			
		||||
        } else if (item == mItemPreviewFeatures) {
 | 
			
		||||
            mViewMode = VIEW_MODE_FEATURES;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return true;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public native void FindFeatures(long matAddrGr, long matAddrRgba);
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user