chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
set(sample example-tutorial-2-mixedprocessing)
|
||||
|
||||
if(BUILD_FAT_JAVA_LIB)
|
||||
set(native_deps opencv_java)
|
||||
else()
|
||||
set(native_deps opencv_features2d)
|
||||
endif()
|
||||
|
||||
add_android_project(${sample} "${CMAKE_CURRENT_SOURCE_DIR}" LIBRARY_DEPS "${OPENCV_ANDROID_LIB_DIR}" SDK_TARGET 11 "${ANDROID_SDK_TARGET}" NATIVE_DEPS ${native_deps})
|
||||
if(TARGET ${sample})
|
||||
add_dependencies(opencv_android_examples ${sample})
|
||||
endif()
|
||||
@@ -0,0 +1,62 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
namespace 'org.opencv.samples.tutorial2'
|
||||
compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@
|
||||
defaultConfig {
|
||||
applicationId "org.opencv.samples.tutorial2"
|
||||
minSdkVersion @ANDROID_MIN_SDK_VERSION@
|
||||
targetSdkVersion @ANDROID_TARGET_SDK_VERSION@
|
||||
versionCode 301
|
||||
versionName "3.01"
|
||||
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
if (gradle.opencv_source == "sdk_path") {
|
||||
arguments "-DOpenCV_DIR=" + project(':opencv').projectDir + "/@ANDROID_PROJECT_JNI_PATH@",
|
||||
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
|
||||
"-DOPENCV_FROM_SDK=TRUE"@OPENCV_ANDROID_CMAKE_EXTRA_ARGS@
|
||||
} else {
|
||||
arguments "-DOPENCV_VERSION_MAJOR=@OPENCV_VERSION_MAJOR@",
|
||||
"-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
|
||||
"-DOPENCV_FROM_SDK=FALSE"@OPENCV_ANDROID_CMAKE_EXTRA_ARGS@
|
||||
}
|
||||
targets "mixed_sample"
|
||||
}
|
||||
}
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
main {
|
||||
java.srcDirs = @ANDROID_SAMPLE_JAVA_PATH@
|
||||
res.srcDirs = @ANDROID_SAMPLE_RES_PATH@
|
||||
manifest.srcFile '@ANDROID_SAMPLE_MANIFEST_PATH@'
|
||||
}
|
||||
}
|
||||
externalNativeBuild {
|
||||
cmake {
|
||||
path '@ANDROID_SAMPLE_JNI_PATH@/CMakeLists.txt'
|
||||
}
|
||||
}
|
||||
buildFeatures {
|
||||
if (gradle.opencv_source == "maven_local" || gradle.opencv_source == "maven_central") {
|
||||
prefab true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
//implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
if (gradle.opencv_source == "sdk_path") {
|
||||
println 'Using OpenCV from SDK'
|
||||
implementation project(':opencv')
|
||||
} else if (gradle.opencv_source == "maven_local" || gradle.opencv_source == "maven_central") {
|
||||
println 'Using OpenCV from Maven repo'
|
||||
implementation 'org.opencv:opencv:@OPENCV_VERSION_PLAIN@'
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.opencv.samples.tutorial2"
|
||||
>
|
||||
|
||||
<application
|
||||
android:label="@string/app_name"
|
||||
android:icon="@drawable/icon">
|
||||
|
||||
<activity
|
||||
android:exported="true"
|
||||
android:name="Tutorial2Activity"
|
||||
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-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>
|
||||
@@ -0,0 +1,30 @@
|
||||
cmake_minimum_required(VERSION 3.6)
|
||||
|
||||
set(target mixed_sample)
|
||||
project(${target} CXX)
|
||||
|
||||
if (OPENCV_FROM_SDK)
|
||||
message(STATUS "Using OpenCV from local SDK")
|
||||
set(ANDROID_OPENCV_COMPONENTS "opencv_java" CACHE STRING "")
|
||||
else()
|
||||
message(STATUS "Using OpenCV from AAR (Maven repo)")
|
||||
set(ANDROID_OPENCV_COMPONENTS "OpenCV::opencv_java${OPENCV_VERSION_MAJOR}" CACHE STRING "")
|
||||
endif()
|
||||
|
||||
message(STATUS "ANDROID_ABI=${ANDROID_ABI}")
|
||||
find_package(OpenCV REQUIRED COMPONENTS ${ANDROID_OPENCV_COMPONENTS})
|
||||
|
||||
# For 16k pages support with NDK prior 27
|
||||
# Details: https://developer.android.com/guide/practices/page-sizes?hl=en
|
||||
if(ANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES)
|
||||
if(ANDROID_ABI STREQUAL arm64-v8a OR ANDROID_ABI STREQUAL x86_64)
|
||||
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,max-page-size=16384")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
file(GLOB srcs *.cpp *.c)
|
||||
file(GLOB hdrs *.hpp *.h)
|
||||
|
||||
include_directories("${CMAKE_CURRENT_LIST_DIR}")
|
||||
add_library(${target} SHARED ${srcs} ${hdrs})
|
||||
target_link_libraries(${target} ${ANDROID_OPENCV_COMPONENTS})
|
||||
@@ -0,0 +1,27 @@
|
||||
#include <jni.h>
|
||||
#include <opencv2/core.hpp>
|
||||
#include <opencv2/imgproc.hpp>
|
||||
#include <opencv2/features2d.hpp>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
extern "C" {
|
||||
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_samples_tutorial2_Tutorial2Activity_FindFeatures(JNIEnv*, jobject, jlong addrGray, jlong addrRgba)
|
||||
{
|
||||
Mat& mGr = *(Mat*)addrGray;
|
||||
Mat& mRgb = *(Mat*)addrRgba;
|
||||
vector<KeyPoint> v;
|
||||
|
||||
Ptr<FeatureDetector> detector = FastFeatureDetector::create(50);
|
||||
detector->detect(mGr, v);
|
||||
for( unsigned int i = 0; i < v.size(); i++ )
|
||||
{
|
||||
const KeyPoint& kp = v[i];
|
||||
circle(mRgb, Point(kp.pt.x, kp.pt.y), 10, Scalar(255,0,0,255));
|
||||
}
|
||||
}
|
||||
}
|
||||
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/tutorial2_activity_surface_view" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">OCV T2 Mixed Processing</string>
|
||||
</resources>
|
||||
+166
@@ -0,0 +1,166 @@
|
||||
package org.opencv.samples.tutorial2;
|
||||
|
||||
import org.opencv.android.CameraActivity;
|
||||
import org.opencv.android.CameraBridgeViewBase.CvCameraViewFrame;
|
||||
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.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class Tutorial2Activity extends CameraActivity 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;
|
||||
|
||||
public Tutorial2Activity() {
|
||||
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);
|
||||
|
||||
if (OpenCVLoader.initLocal()) {
|
||||
Log.i(TAG, "OpenCV loaded successfully");
|
||||
} else {
|
||||
Log.e(TAG, "OpenCV initialization failed!");
|
||||
(Toast.makeText(this, "OpenCV initialization failed!", Toast.LENGTH_LONG)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
// Load native library after(!) OpenCV initialization
|
||||
System.loadLibrary("mixed_sample");
|
||||
|
||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
|
||||
|
||||
setContentView(R.layout.tutorial2_surface_view);
|
||||
|
||||
mOpenCvCameraView = (CameraBridgeViewBase) findViewById(R.id.tutorial2_activity_surface_view);
|
||||
mOpenCvCameraView.setVisibility(CameraBridgeViewBase.VISIBLE);
|
||||
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();
|
||||
if (mOpenCvCameraView != null)
|
||||
mOpenCvCameraView.enableView();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<? extends CameraBridgeViewBase> getCameraViewList() {
|
||||
return Collections.singletonList(mOpenCvCameraView);
|
||||
}
|
||||
|
||||
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