mirror of
https://github.com/opencv/opencv.git
synced 2025-06-07 17:44:04 +08:00
Merge pull request #24910 from alexlyulkov:al/android-tests
Modified Java tests to run on Android #24910 To run the tests you need to: 1. Build OpenCV using Android pipeline. For example: `cmake -DBUILD_TEST=ON -DANDROID=ON -DANDROID_ABI=arm64-v8a -DCMAKE_TOOLCHAIN_FILE=/usr/lib/android-sdk/ndk/25.1.8937393/build/cmake/android.toolchain.cmake -DANDROID_NDK=/usr/lib/android-sdk/ndk/25.1.8937393 -DANDROID_SDK=/usr/lib/android-sdk ../opencv` `make` 2. Connect Android Phone 3. Run tests: `cd android_tests` `./gradlew tests_module:connectedAndroidTest` Related CI pipeline: https://github.com/opencv/ci-gha-workflow/pull/138 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
parent
e48b96b926
commit
85450816b4
@ -1884,7 +1884,7 @@ if(BUILD_JAVA)
|
||||
status(" JNI:" JNI_INCLUDE_DIRS THEN "${JNI_INCLUDE_DIRS}" ELSE NO)
|
||||
endif()
|
||||
status(" Java wrappers:" HAVE_opencv_java THEN "YES (${OPENCV_JAVA_SDK_BUILD_TYPE})" ELSE NO)
|
||||
status(" Java tests:" BUILD_TESTS AND opencv_test_java_BINARY_DIR THEN YES ELSE NO)
|
||||
status(" Java tests:" BUILD_TESTS AND (opencv_test_java_BINARY_DIR OR opencv_test_android_BINARY_DIR) THEN YES ELSE NO)
|
||||
endif()
|
||||
|
||||
# ========================== Objective-C =======================
|
||||
|
@ -1,9 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="gen"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
|
||||
<classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
|
||||
<classpathentry kind="output" path="bin/classes"/>
|
||||
</classpath>
|
@ -1,33 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>OpenCV_JavaAPI_Tests</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<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>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,28 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.opencv.test"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
|
||||
<uses-sdk android:minSdkVersion="8" />
|
||||
|
||||
<!-- We add an application tag here just so that we can indicate that
|
||||
this package needs to link against the android.test library,
|
||||
which is needed when building test cases. -->
|
||||
<application>
|
||||
<uses-library android:name="android.test.runner" />
|
||||
</application>
|
||||
<!--
|
||||
This declares that this application uses the instrumentation test runner targeting
|
||||
the package of org.opencv. To run the tests use the command:
|
||||
"adb shell am instrument -w org.opencv.test/android.test.InstrumentationTestRunner"
|
||||
-->
|
||||
<instrumentation android:name="org.opencv.test.OpenCVTestRunner"
|
||||
android:targetPackage="org.opencv.test"
|
||||
android:label="Tests for org.opencv"/>
|
||||
|
||||
<uses-permission android:name="android.permission.CAMERA"/>
|
||||
<uses-feature android:name="android.hardware.camera" />
|
||||
<uses-feature android:name="android.hardware.camera.autofocus" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
</manifest>
|
@ -1,77 +1,24 @@
|
||||
if(NOT ANT_EXECUTABLE OR NOT ANDROID_EXECUTABLE OR NOT ANDROID_TOOLS_Pkg_Revision GREATER 13)
|
||||
return()
|
||||
endif()
|
||||
project(opencv_test_android)
|
||||
|
||||
project(opencv_test_java)
|
||||
set(OPENCV_ANDROID_TEST_DIR "${OpenCV_BINARY_DIR}/android_test" CACHE INTERNAL "")
|
||||
file(REMOVE_RECURSE "${OPENCV_ANDROID_TEST_DIR}")
|
||||
|
||||
set(OPENCV_JAVA_TEST_DIR "${OpenCV_BINARY_DIR}/android_test" CACHE INTERNAL "")
|
||||
file(REMOVE_RECURSE "${OPENCV_JAVA_TEST_DIR}")
|
||||
file(REMOVE "${OPENCV_DEPHELPER}/${the_module}_test_source_copy")
|
||||
set(ANDROID_TESTS_SRC_DIRS
|
||||
"'${CMAKE_CURRENT_SOURCE_DIR}/src', \
|
||||
'${OpenCV_SOURCE_DIR}/modules/java/test/common_test/src', \
|
||||
'${CMAKE_BINARY_DIR}/modules/java_bindings_generator/gen/test'" CACHE INTERNAL "")
|
||||
|
||||
set(test_dir "${CMAKE_CURRENT_SOURCE_DIR}")
|
||||
set(ANDROID_TESTS_RES_DIR "'${OpenCV_SOURCE_DIR}/modules/java/test/common_test/res'" CACHE INTERNAL "")
|
||||
|
||||
set(depends "")
|
||||
|
||||
# 1. gather and copy common test files (resources, utils, etc.)
|
||||
copy_common_tests("${CMAKE_CURRENT_SOURCE_DIR}/../common_test" "${OPENCV_JAVA_TEST_DIR}" depends)
|
||||
|
||||
# 2. gather and copy tests from each module
|
||||
ocv_copyfiles_append_dir(JAVA_TEST_SRC_COPY "${OPENCV_JAVA_BINDINGS_DIR}/gen/test" "${OPENCV_JAVA_TEST_DIR}/src")
|
||||
|
||||
list(APPEND depends gen_opencv_java_source "${OPENCV_DEPHELPER}/gen_opencv_java_source")
|
||||
ocv_copyfiles_add_target(${the_module}_test_source_copy JAVA_TEST_SRC_COPY "Copy Java(Android test) source files" ${depends})
|
||||
set(depends ${the_module}_test_source_copy "${OPENCV_DEPHELPER}/${the_module}_test_source_copy")
|
||||
|
||||
# 3. gather and copy specific files for Android
|
||||
file(GLOB_RECURSE test_files RELATIVE "${test_dir}" "${test_dir}/res/*" "${test_dir}/src/*")
|
||||
foreach(f ${test_files} ${ANDROID_MANIFEST_FILE} ".classpath" ".project")
|
||||
add_custom_command(
|
||||
OUTPUT "${OPENCV_JAVA_TEST_DIR}/${f}"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "${test_dir}/${f}" "${OPENCV_JAVA_TEST_DIR}/${f}"
|
||||
MAIN_DEPENDENCY "${test_dir}/${f}"
|
||||
COMMENT "Copying ${f}")
|
||||
list(APPEND depends "${test_dir}/${f}" "${OPENCV_JAVA_TEST_DIR}/${f}")
|
||||
list(APPEND TEST_PROJECT_FILES "build.gradle" "CMakeLists.txt" "gradle.properties" "settings.gradle")
|
||||
foreach(TEST_PROJECT_FILE ${TEST_PROJECT_FILES})
|
||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/${TEST_PROJECT_FILE}" DESTINATION "${OPENCV_ANDROID_TEST_DIR}")
|
||||
endforeach()
|
||||
file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/tests_module/AndroidManifest.xml" DESTINATION "${OPENCV_ANDROID_TEST_DIR}/tests_module")
|
||||
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tests_module/build.gradle.in" "${OPENCV_ANDROID_TEST_DIR}/tests_module/build.gradle" @ONLY)
|
||||
|
||||
# fix Android project
|
||||
set(android_proj_target_files ${ANDROID_PROJECT_FILES})
|
||||
ocv_list_add_prefix(android_proj_target_files "${OPENCV_JAVA_TEST_DIR}/")
|
||||
file(RELATIVE_PATH __dep "${OPENCV_JAVA_TEST_DIR}" "${OpenCV_BINARY_DIR}/android_sdk")
|
||||
file(COPY "${OpenCV_SOURCE_DIR}/platforms/android/gradle-wrapper/gradlew" DESTINATION "${OPENCV_ANDROID_TEST_DIR}")
|
||||
file(COPY "${OpenCV_SOURCE_DIR}/platforms/android/gradle-wrapper/gradlew.bat" DESTINATION "${OPENCV_ANDROID_TEST_DIR}")
|
||||
file(COPY "${OpenCV_SOURCE_DIR}/platforms/android/gradle-wrapper/gradle/wrapper/gradle-wrapper.jar" DESTINATION "${OPENCV_ANDROID_TEST_DIR}/gradle/wrapper")
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${android_proj_target_files}
|
||||
COMMAND ${CMAKE_COMMAND} -E remove ${android_proj_target_files}
|
||||
COMMAND ${ANDROID_EXECUTABLE} --silent update test-project --path "${OPENCV_JAVA_TEST_DIR}" --main "${OpenCV_BINARY_DIR}/android_sdk"
|
||||
COMMAND ${ANDROID_EXECUTABLE} --silent update project --path "${OPENCV_JAVA_TEST_DIR}" --library "${__dep}"
|
||||
MAIN_DEPENDENCY "${OPENCV_JAVA_TEST_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
COMMENT "Updating Android Java API test project")
|
||||
|
||||
list(APPEND depends ${android_proj_target_files})
|
||||
|
||||
# build java part
|
||||
add_custom_command(
|
||||
OUTPUT "${OPENCV_JAVA_TEST_DIR}/bin/OpenCVTest-debug.apk"
|
||||
COMMAND ${CMAKE_COMMAND} -E copy_if_different "$<TARGET_FILE:opencv_java>" "${OPENCV_JAVA_TEST_DIR}/libs/${ANDROID_NDK_ABI_NAME}/$<TARGET_FILE_NAME:opencv_java>"
|
||||
COMMAND ${ANT_EXECUTABLE} -q -noinput -k debug -Djava.target=1.6 -Djava.source=1.6
|
||||
COMMAND ${CMAKE_COMMAND} -E touch "${OPENCV_JAVA_TEST_DIR}/bin/OpenCVTest-debug.apk" # needed because ant does not update the timestamp of updated apk
|
||||
WORKING_DIRECTORY "${OPENCV_JAVA_TEST_DIR}"
|
||||
MAIN_DEPENDENCY "${OPENCV_JAVA_TEST_DIR}/${ANDROID_MANIFEST_FILE}"
|
||||
DEPENDS opencv_java_android opencv_java
|
||||
DEPENDS ${depends})
|
||||
|
||||
add_custom_target(${PROJECT_NAME} ALL SOURCES "${OPENCV_JAVA_TEST_DIR}/bin/OpenCVTest-debug.apk" "${CMAKE_CURRENT_SOURCE_DIR}/${ANDROID_MANIFEST_FILE}")
|
||||
add_dependencies(${PROJECT_NAME} opencv_java ${__android_project_chain})
|
||||
set(__android_project_chain ${PROJECT_NAME} CACHE INTERNAL "auxiliary variable used for Android progects chaining" FORCE)
|
||||
|
||||
# put the final .apk to the OpenCV's bin folder
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_if_different "${OPENCV_JAVA_TEST_DIR}/bin/OpenCVTest-debug.apk" "${OpenCV_BINARY_DIR}/bin/${PROJECT_NAME}.apk")
|
||||
|
||||
add_dependencies(opencv_tests ${PROJECT_NAME})
|
||||
|
||||
if(PYTHON_DEFAULT_AVAILABLE)
|
||||
set(CHECK_TEST_COVERAGE "${OPENCV_MODULE_opencv_java_LOCATION}/check-tests.py")
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
COMMAND ${PYTHON_DEFAULT_EXECUTABLE} ${CHECK_TEST_COVERAGE} "${OPENCV_JAVA_TEST_DIR}/src" "${OPENCV_ANDROID_LIB_DIR}/src" > "${CMAKE_CURRENT_BINARY_DIR}/tests_coverage.log"
|
||||
)
|
||||
endif()
|
||||
configure_file("${OpenCV_SOURCE_DIR}/platforms/android/gradle-wrapper/gradle/wrapper/gradle-wrapper.properties.in" "${OPENCV_ANDROID_TEST_DIR}/gradle/wrapper/gradle-wrapper.properties" @ONLY)
|
||||
|
27
modules/java/test/android_test/build.gradle
Normal file
27
modules/java/test/android_test/build.gradle
Normal file
@ -0,0 +1,27 @@
|
||||
// Top-level build file where you can add configuration options common to all sub-projects/modules.
|
||||
|
||||
buildscript {
|
||||
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:7.3.1'
|
||||
classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20'
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
repositories {
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
18
modules/java/test/android_test/gradle.properties
Normal file
18
modules/java/test/android_test/gradle.properties
Normal file
@ -0,0 +1,18 @@
|
||||
# Project-wide Gradle settings.
|
||||
|
||||
# IDE (e.g. Android Studio) users:
|
||||
# Gradle settings configured through the IDE *will override*
|
||||
# any settings specified in this file.
|
||||
|
||||
# For more details on how to configure your build environment visit
|
||||
# http://www.gradle.org/docs/current/userguide/build_environment.html
|
||||
|
||||
# Specifies the JVM arguments used for the daemon process.
|
||||
# The setting is particularly useful for tweaking memory settings.
|
||||
org.gradle.jvmargs=-Xmx2g
|
||||
|
||||
android.useAndroidX=true
|
||||
# When configured, Gradle will run in incubating parallel mode.
|
||||
# This option should only be used with decoupled projects. More details, visit
|
||||
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
|
||||
# org.gradle.parallel=true
|
6
modules/java/test/android_test/settings.gradle
Normal file
6
modules/java/test/android_test/settings.gradle
Normal file
@ -0,0 +1,6 @@
|
||||
rootProject.name = 'android_test'
|
||||
|
||||
include ':opencv'
|
||||
project(':opencv').projectDir = new File('../opencv_android/opencv')
|
||||
|
||||
include ':tests_module'
|
@ -294,6 +294,13 @@ public class OpenCVTestCase extends TestCase {
|
||||
//assertTrue(Math.abs(ar1[i].doubleValue() - ar2[i].doubleValue()) <= epsilon);
|
||||
}
|
||||
|
||||
public static void assertArrayEquals(byte[] ar1, byte[] ar2) {
|
||||
assertEquals(ar1.length, ar2.length);
|
||||
|
||||
for (int i = 0; i < ar1.length; i++)
|
||||
assertEquals(ar1[i], ar2[i]);
|
||||
}
|
||||
|
||||
public static void assertArrayEquals(double[] ar1, double[] ar2, double epsilon) {
|
||||
assertEquals(ar1.length, ar2.length);
|
||||
|
||||
|
@ -4,52 +4,29 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.opencv.android.BaseLoaderCallback;
|
||||
import org.opencv.android.LoaderCallbackInterface;
|
||||
import org.opencv.android.OpenCVLoader;
|
||||
import org.opencv.android.Utils;
|
||||
import org.opencv.core.Mat;
|
||||
|
||||
import android.content.Context;
|
||||
import android.test.AndroidTestRunner;
|
||||
import android.test.InstrumentationTestRunner;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.test.runner.AndroidJUnitRunner;
|
||||
|
||||
|
||||
/**
|
||||
* This only class is Android specific.
|
||||
*/
|
||||
|
||||
public class OpenCVTestRunner extends InstrumentationTestRunner {
|
||||
public class OpenCVTestRunner extends AndroidJUnitRunner {
|
||||
|
||||
private static final long MANAGER_TIMEOUT = 3000;
|
||||
public static String LENA_PATH;
|
||||
public static String CHESS_PATH;
|
||||
public static String LBPCASCADE_FRONTALFACE_PATH;
|
||||
public static Context context;
|
||||
|
||||
private AndroidTestRunner androidTestRunner;
|
||||
private static String TAG = "opencv_test_java";
|
||||
|
||||
private BaseLoaderCallback mLoaderCallback = new BaseLoaderCallback(getContext()) {
|
||||
|
||||
@Override
|
||||
public void onManagerConnected(int status) {
|
||||
switch (status) {
|
||||
case LoaderCallbackInterface.SUCCESS:
|
||||
{
|
||||
Log("OpenCV loaded successfully");
|
||||
synchronized (this) {
|
||||
notify();
|
||||
}
|
||||
} break;
|
||||
default:
|
||||
{
|
||||
super.onManagerConnected(status);
|
||||
} break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public static String getTempFileName(String extension)
|
||||
{
|
||||
File cache = context.getCacheDir();
|
||||
@ -76,30 +53,13 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
// try to load internal libs
|
||||
if (!OpenCVLoader.initDebug()) {
|
||||
// There is no internal OpenCV libs
|
||||
// Using OpenCV Manager for initialization;
|
||||
Assert.assertTrue(OpenCVLoader.initLocal());
|
||||
|
||||
Log("Internal OpenCV library not found. Using OpenCV Manager for initialization");
|
||||
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, getContext(), mLoaderCallback);
|
||||
|
||||
synchronized (this) {
|
||||
try {
|
||||
wait(MANAGER_TIMEOUT);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Log("OpenCV library found inside test package. Using it!");
|
||||
}
|
||||
|
||||
context = getContext();
|
||||
context = getTargetContext();
|
||||
Assert.assertNotNull("Context can't be 'null'", context);
|
||||
LENA_PATH = Utils.exportResource(context, R.drawable.lena);
|
||||
CHESS_PATH = Utils.exportResource(context, R.drawable.chessboard);
|
||||
LBPCASCADE_FRONTALFACE_PATH = Utils.exportResource(context, R.raw.lbpcascade_frontalface);
|
||||
LENA_PATH = Utils.exportResource(context, context.getResources().getIdentifier("lena", "drawable", context.getPackageName()));
|
||||
CHESS_PATH = Utils.exportResource(context, context.getResources().getIdentifier("chessboard", "drawable", context.getPackageName()));
|
||||
//LBPCASCADE_FRONTALFACE_PATH = Utils.exportResource(context, R.raw.lbpcascade_frontalface);
|
||||
|
||||
/*
|
||||
* The original idea about test order randomization is from
|
||||
@ -111,12 +71,6 @@ public class OpenCVTestRunner extends InstrumentationTestRunner {
|
||||
super.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AndroidTestRunner getAndroidTestRunner() {
|
||||
androidTestRunner = super.getAndroidTestRunner();
|
||||
return androidTestRunner;
|
||||
}
|
||||
|
||||
public static String getOutputFileName(String name)
|
||||
{
|
||||
return context.getExternalFilesDir(null).getAbsolutePath() + File.separatorChar + name;
|
||||
|
@ -17,6 +17,59 @@ import android.util.Log;
|
||||
|
||||
public class UtilsTest extends OpenCVTestCase {
|
||||
|
||||
private int[] testImgWH = new int[]{64, 48};
|
||||
private byte[] testImgBgColor = new byte[]{1, 2, 3};
|
||||
private int[] testImgRect = new int[] {15, 17, 25, 37};
|
||||
private byte[] testImgRectColor = new byte[]{45, 15, 67};
|
||||
|
||||
private Mat createTestBGRImg() {
|
||||
Mat img = new Mat(testImgWH[1], testImgWH[0], CvType.CV_8UC3,
|
||||
new Scalar(testImgBgColor[2], testImgBgColor[1], testImgBgColor[0]));
|
||||
byte[] color = new byte[]{testImgRectColor[2], testImgRectColor[1], testImgRectColor[0]};
|
||||
|
||||
for (int i = testImgRect[1]; i < testImgRect[3]; i++) {
|
||||
for (int j = testImgRect[0]; j < testImgRect[2]; j++) {
|
||||
img.put(i, j, color);
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
private Bitmap createTestBitmap() {
|
||||
Bitmap img = Bitmap.createBitmap(testImgWH[0], testImgWH[1], Bitmap.Config.ARGB_8888);
|
||||
img.eraseColor(Color.argb(255, testImgBgColor[0], testImgBgColor[1] ,testImgBgColor[2]));
|
||||
|
||||
for (int i = testImgRect[1]; i < testImgRect[3]; i++) {
|
||||
for (int j = testImgRect[0]; j < testImgRect[2]; j++) {
|
||||
img.setPixel(j, i, Color.argb(
|
||||
255, testImgRectColor[0], testImgRectColor[1], testImgRectColor[2]));
|
||||
}
|
||||
}
|
||||
return img;
|
||||
}
|
||||
|
||||
public void testMatBitmapConversion() {
|
||||
Mat mat = new Mat();
|
||||
Imgproc.cvtColor(createTestBGRImg(), mat, Imgproc.COLOR_BGR2RGBA);
|
||||
Bitmap bmp = createTestBitmap();
|
||||
|
||||
Bitmap convertedBmp = Bitmap.createBitmap(
|
||||
Bitmap.createBitmap(testImgWH[0], testImgWH[1], Bitmap.Config.ARGB_8888));
|
||||
Utils.matToBitmap(mat, convertedBmp);
|
||||
assertTrue(bmp.sameAs(convertedBmp));
|
||||
|
||||
Mat convertedMat = new Mat();
|
||||
Utils.bitmapToMat(bmp, convertedMat);
|
||||
Mat diff = new Mat();
|
||||
Core.absdiff(mat, convertedMat, diff);
|
||||
Scalar channelsDiff = Core.sumElems(diff);
|
||||
assertEquals(0.0, channelsDiff.val[0]);
|
||||
assertEquals(0.0, channelsDiff.val[1]);
|
||||
assertEquals(0.0, channelsDiff.val[2]);
|
||||
assertEquals(0.0, channelsDiff.val[3]);
|
||||
}
|
||||
|
||||
|
||||
public void testBitmapToMat() {
|
||||
BitmapFactory.Options opt16 = new BitmapFactory.Options();
|
||||
opt16.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
|
@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="org.opencv.samples.tutorial1"
|
||||
>
|
||||
|
||||
<application
|
||||
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
|
||||
</application>
|
||||
|
||||
</manifest>
|
35
modules/java/test/android_test/tests_module/build.gradle.in
Normal file
35
modules/java/test/android_test/tests_module/build.gradle.in
Normal file
@ -0,0 +1,35 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
namespace 'org.opencv.tests'
|
||||
compileSdkVersion @ANDROID_COMPILE_SDK_VERSION@
|
||||
defaultConfig {
|
||||
applicationId "org.opencv.tests"
|
||||
minSdkVersion @ANDROID_MIN_SDK_VERSION@
|
||||
targetSdkVersion @ANDROID_TARGET_SDK_VERSION@
|
||||
versionCode 301
|
||||
versionName "3.01"
|
||||
|
||||
testInstrumentationRunner "org.opencv.test.OpenCVTestRunner"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
sourceSets {
|
||||
androidTest {
|
||||
java.srcDirs = [@ANDROID_TESTS_SRC_DIRS@]
|
||||
}
|
||||
main {
|
||||
manifest.srcFile 'AndroidManifest.xml'
|
||||
res.srcDirs = [@ANDROID_TESTS_RES_DIR@]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
implementation project(':opencv')
|
||||
}
|
@ -16,10 +16,15 @@ public class BarcodeDetectorTest extends OpenCVTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// relys on https://developer.android.com/reference/java/lang/System
|
||||
isTestCaseEnabled = System.getProperties().getProperty("java.vm.name") != "Dalvik";
|
||||
|
||||
if (isTestCaseEnabled) {
|
||||
testDataPath = System.getenv(ENV_OPENCV_TEST_DATA_PATH);
|
||||
if (testDataPath == null)
|
||||
throw new Exception(ENV_OPENCV_TEST_DATA_PATH + " has to be defined!");
|
||||
}
|
||||
}
|
||||
|
||||
public void testDetectAndDecode() {
|
||||
Mat img = Imgcodecs.imread(testDataPath + "/cv/barcode/multiple/4_barcodes.jpg");
|
||||
|
@ -19,10 +19,15 @@ public class QRCodeDetectorTest extends OpenCVTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
// relys on https://developer.android.com/reference/java/lang/System
|
||||
isTestCaseEnabled = System.getProperties().getProperty("java.vm.name") != "Dalvik";
|
||||
|
||||
if (isTestCaseEnabled) {
|
||||
testDataPath = System.getenv(ENV_OPENCV_TEST_DATA_PATH);
|
||||
if (testDataPath == null)
|
||||
throw new Exception(ENV_OPENCV_TEST_DATA_PATH + " has to be defined!");
|
||||
}
|
||||
}
|
||||
|
||||
public void testDetectAndDecode() {
|
||||
Mat img = Imgcodecs.imread(testDataPath + "/cv/qrcode/link_ocv.jpg");
|
||||
|
0
platforms/android/gradle-wrapper/gradlew
vendored
Normal file → Executable file
0
platforms/android/gradle-wrapper/gradlew
vendored
Normal file → Executable file
Loading…
Reference in New Issue
Block a user