Skip to content

Commit

Permalink
Merge pull request #5 from michaeltroger/feature/update_dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
michaeltroger committed Feb 8, 2024
2 parents a1cbb7f + ac5c5d7 commit 46d7653
Show file tree
Hide file tree
Showing 921 changed files with 62 additions and 719,688 deletions.
1 change: 0 additions & 1 deletion .gitattributes

This file was deleted.

15 changes: 7 additions & 8 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: set up JDK 11
uses: actions/setup-java@v2
- uses: actions/checkout@v4
- name: set up JDK
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'
java-version: '21'
distribution: 'temurin'
cache: gradle

- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew assembleDebug
- uses: actions/upload-artifact@v2

- uses: actions/upload-artifact@v4
with:
name: APK
path: app/build/outputs/apk/debug/
13 changes: 5 additions & 8 deletions .github/workflows/release_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: set up JDK 11
uses: actions/setup-java@v2
- name: set up JDK
uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'adopt'
java-version: '21'
distribution: 'temurin'
cache: gradle

- name: grant execute permission for gradlew
run: chmod +x gradlew

- name: Build APK with Gradle
run: ./gradlew assembleDebug

Expand Down
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Augmented Reality simple shape detector using OpenCV for >= Android 4.0 #
# Augmented Reality simple shape detector using OpenCV
[![Android CI](https://github.com/michaeltroger/shape-detection-android/actions/workflows/android.yml/badge.svg)](https://github.com/michaeltroger/shape-detection-android/actions/workflows/android.yml)

Attention: This app was created in 2016. I was a beginner to Android development and Computer Vision back then.
So don't expect a perfect code please. In 2021 I updated the project to build with the latest Android Studio (2020.3.1), updated most dependencies and converted it to Kotlin, while the business logic remained unchanged.
So don't expect a perfect code please. Over the years I updated the dependencies and converted it to Kotlin, while the business logic remained unchanged.

<img src="/screenshots/demo.gif" alt="Augmented Reality shape detection" width="800px"/>

Expand All @@ -13,9 +13,8 @@ So don't expect a perfect code please. In 2021 I updated the project to build wi

### How do I get set up? ###

* IDE: Android Studio (tested with 2020.3.1)
* IDE: Android Studio (tested with 2023.3.1)
* Android SDK
* Dependencies: OpenCV 3 library (included) [License](/opencv-3-4-15/LICENSE)
* Images location: res/drawable | Sounds location: res/raw
* Mode (label/image): Flag in MainActivity (default labels)
* Mode (all colors / red only): Flag in MainActivity (default all colors)
Expand All @@ -29,5 +28,5 @@ So don't expect a perfect code please. In 2021 I updated the project to build wi
[Michael Troger](https://michaeltroger.com)

### Credits ###
* The shape detection is based on Nash's shape detection https://github.com/bsdnoobz/opencv-code/blob/master/shape-detect.cpp His version is based on OpenCV 2 for the PC and usable for static images files.
* The shape detection is based on Nash's shape detection https://github.com/bsdnoobz/opencv-code/blob/master/shape-detect.cpp His version is based on OpenCV 2 for the PC and usable for static images files. He extracted the code from the OpenCV tutorials http://opencv-code.com back then - that website is no longer available though.
* The red color detection is based on Sol's OpenCV red circle detection. See https://github.com/sol-prog/OpenCV-red-circle-detection and https://solarianprogrammer.com/2015/05/08/detect-red-circles-image-using-opencv/
35 changes: 15 additions & 20 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,41 @@ plugins {
}

android {
compileSdkVersion 30
buildToolsVersion "30.0.3"
namespace "com.michaeltroger.shapedetection"
compileSdk 34

defaultConfig {
applicationId "com.michaeltroger.shapedetection"
minSdkVersion 15
targetSdkVersion 30
versionCode 3
versionName "1.2"
minSdkVersion 21
targetSdkVersion 34
versionCode 4
versionName "1.3"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
kotlinOptions {
jvmTarget = "11"
}
splits {
abi {
enable true
reset()
include "x86", "x86_64", "mips", "mips64", "armeabi", "armeabi-v7a", "arm64-v8a"
include "x86", "x86_64", "armeabi-v7a", "arm64-v8a"
universalApk true
}
}
}

kotlin.jvmToolchain(java_version)

dependencies {
implementation 'androidx.core:core-ktx:1.6.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.activity:activity-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation project(':opencv-3-4-15')
implementation 'androidx.core:core-ktx:1.12.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.activity:activity-ktx:1.8.2'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.11.0'
implementation 'org.opencv:opencv:4.9.0'

testImplementation 'junit:junit:4.13.2'
}
15 changes: 5 additions & 10 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.michaeltroger.shapedetection">
<manifest xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android">
<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"/>
Expand All @@ -9,20 +9,15 @@
<application
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
android:theme="@style/AppTheme.NoActionBar" >
<activity android:name="com.michaeltroger.shapedetection.MainActivity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:configChanges="keyboardHidden|orientation">
android:exported="true"
tools:ignore="DiscouragedApi">
<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" />
</manifest>
47 changes: 15 additions & 32 deletions app/src/main/java/com/michaeltroger/shapedetection/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import android.widget.Toast
import com.michaeltroger.shapedetection.views.OverlayView
import android.app.ActivityManager
import android.content.pm.PackageManager
import org.opencv.android.BaseLoaderCallback
import org.opencv.android.LoaderCallbackInterface
import android.os.Bundle
import android.os.Handler
import android.view.WindowManager
Expand Down Expand Up @@ -100,28 +98,6 @@ class MainActivity : ComponentActivity(), CvCameraViewListener2 {
* approximated polygonal curve with specified precision
*/
private var approxCurve: MatOfPoint2f? = null
private val mLoaderCallback: BaseLoaderCallback = object : BaseLoaderCallback(this) {
override fun onManagerConnected(status: Int) {
when (status) {
SUCCESS -> {
Log.i(TAG, "OpenCV loaded successfully")
bw = Mat()
hsv = Mat()
lowerRedRange = Mat()
upperRedRange = Mat()
downscaled = Mat()
upscaled = Mat()
contourImage = Mat()
hierarchyOutputVector = Mat()
approxCurve = MatOfPoint2f()
mOpenCvCameraView!!.enableView()
}
else -> {
super.onManagerConnected(status)
}
}
}
}

private val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()
Expand Down Expand Up @@ -161,6 +137,7 @@ class MainActivity : ComponentActivity(), CvCameraViewListener2 {
}
mOpenCvCameraView!!.visibility = SurfaceView.VISIBLE
mOpenCvCameraView!!.setCvCameraViewListener(this)
mOpenCvCameraView!!.setCameraPermissionGranted()
mi = ActivityManager.MemoryInfo()
activityManager = getSystemService(ACTIVITY_SERVICE) as ActivityManager
}
Expand All @@ -174,13 +151,19 @@ class MainActivity : ComponentActivity(), CvCameraViewListener2 {
public override fun onResume() {
super.onResume()

if (!OpenCVLoader.initDebug()) {
Log.d(TAG, "Internal OpenCV library not found. Using OpenCV Manager for initialization")
OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_3_0_0, this, mLoaderCallback)
} else {
Log.d(TAG, "OpenCV library found inside package. Using it!")
mLoaderCallback.onManagerConnected(LoaderCallbackInterface.SUCCESS)
}
OpenCVLoader.initLocal()

Log.i(TAG, "OpenCV loaded successfully")
bw = Mat()
hsv = Mat()
lowerRedRange = Mat()
upperRedRange = Mat()
downscaled = Mat()
upscaled = Mat()
contourImage = Mat()
hierarchyOutputVector = Mat()
approxCurve = MatOfPoint2f()
mOpenCvCameraView!!.enableView()
}

public override fun onDestroy() {
Expand Down Expand Up @@ -338,7 +321,7 @@ class MainActivity : ComponentActivity(), CvCameraViewListener2 {
* @param contour the contour to which the label should apply
*/
private fun setLabel(im: Mat, label: String, contour: MatOfPoint) {
val fontface = Core.FONT_HERSHEY_SIMPLEX
val fontface = Imgproc.FONT_HERSHEY_SIMPLEX
val scale = 3.0 //0.4;
val thickness = 3 //1;
val baseline = IntArray(1)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_my.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:opencv="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
Expand Down
10 changes: 0 additions & 10 deletions app/src/main/res/menu/menu_my.xml

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/res/values-v21/styles.xml

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/res/values-w820dp/dimens.xml

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/res/values/dimens.xml

This file was deleted.

1 change: 0 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<resources>
<string name="app_name">Shape detection</string>
<string name="action_settings">Settings</string>
</resources>
18 changes: 2 additions & 16 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,10 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="AppTheme.NoActionBar.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.NoActionBar.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

</resources>
7 changes: 4 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.5.21'
ext.kotlin_version = '1.9.22'
ext.java_version = 21
repositories {
mavenCentral()
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.0.0'
classpath 'com.android.tools.build:gradle:8.2.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

task clean(type: Delete) {
tasks.register('clean', Delete) {
delete rootProject.buildDir
}
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8

# 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
android.enableJetifier=true
android.enableJetifier=false
android.useAndroidX=true
kotlin.code.style=official
org.gradle.configuration-cache=true
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
1 change: 0 additions & 1 deletion opencv-3-4-15/.gitignore

This file was deleted.

Loading

0 comments on commit 46d7653

Please sign in to comment.