├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_opencv-playstore.png
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_opencv.png
│ │ │ │ └── ic_opencv_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_opencv.png
│ │ │ │ └── ic_opencv_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_opencv.png
│ │ │ │ └── ic_opencv_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_opencv.png
│ │ │ │ └── ic_opencv_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_opencv.png
│ │ │ │ └── ic_opencv_round.png
│ │ │ ├── menu
│ │ │ │ ├── options_menu.xml
│ │ │ │ └── navdrawer_menu.xml
│ │ │ ├── mipmap-anydpi-v26
│ │ │ │ ├── ic_opencv.xml
│ │ │ │ └── ic_opencv_round.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── themes.xml
│ │ │ │ └── strings.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_baseline_vibration.xml
│ │ │ │ ├── ic_license.xml
│ │ │ │ └── ic_opencv_foreground.xml
│ │ │ ├── values-night
│ │ │ │ └── themes.xml
│ │ │ ├── layout
│ │ │ │ ├── fragment_grayscale.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── fragment_licence.xml
│ │ │ │ ├── fragment_erode.xml
│ │ │ │ ├── fragment_dilate.xml
│ │ │ │ ├── fragment_threshold.xml
│ │ │ │ ├── fragment_canny.xml
│ │ │ │ ├── fragment_gaussianblur.xml
│ │ │ │ ├── fragment_title.xml
│ │ │ │ ├── fragment_hsvextraction.xml
│ │ │ │ └── fragment_rgbextraction.xml
│ │ │ ├── navigation
│ │ │ │ └── navigation.xml
│ │ │ └── drawable-night
│ │ │ │ └── ic_opencv_foreground.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── momomomo111
│ │ │ │ └── camerax_opencv
│ │ │ │ ├── data
│ │ │ │ ├── GrayscaleViewModel.kt
│ │ │ │ ├── ErodeViewModel.kt
│ │ │ │ ├── DilateViewModel.kt
│ │ │ │ ├── CannyViewModel.kt
│ │ │ │ ├── ThresholdViewModel.kt
│ │ │ │ ├── SettingsViewModel.kt
│ │ │ │ ├── GaussianblurViewModel.kt
│ │ │ │ ├── Params.kt
│ │ │ │ ├── HsvextractionViewModel.kt
│ │ │ │ └── RgbextractionViewModel.kt
│ │ │ │ ├── ui
│ │ │ │ ├── LicenceFragment.kt
│ │ │ │ ├── GrayScaleFragment.kt
│ │ │ │ ├── ErodeFragment.kt
│ │ │ │ ├── CannyFragment.kt
│ │ │ │ ├── DilateFragment.kt
│ │ │ │ ├── ThresholdFragment.kt
│ │ │ │ ├── GaussianBlurFragment.kt
│ │ │ │ ├── HsvExtractionFragment.kt
│ │ │ │ ├── RgbExtractionFragment.kt
│ │ │ │ └── TitleFragment.kt
│ │ │ │ ├── util
│ │ │ │ ├── VibrationUtil.kt
│ │ │ │ ├── ProcessImageAnalyzer.kt
│ │ │ │ └── CameraUtil.kt
│ │ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
│ └── androidTest
│ │ └── java
│ │ └── com
│ │ └── momomomo111
│ │ └── camerax_opencv
│ │ └── CameraPreviewTest.kt
├── proguard-rules.pro
└── build.gradle.kts
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── .gitignore
├── compiler.xml
├── jarRepositories.xml
└── $CACHE_FILE$
├── settings.gradle
├── LICENSE
├── README.md
├── docs
└── PrivacyPolicy
│ ├── Japanese.md
│ └── English.md
├── gradle.properties
├── .github
└── workflows
│ └── android.yml
├── .gitignore
├── gradlew.bat
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/ic_opencv-playstore.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/ic_opencv-playstore.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_opencv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-hdpi/ic_opencv.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_opencv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-mdpi/ic_opencv.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_opencv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-xhdpi/ic_opencv.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_opencv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-xxhdpi/ic_opencv.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_opencv.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_opencv.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_opencv_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-hdpi/ic_opencv_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_opencv_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-mdpi/ic_opencv_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_opencv_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-xhdpi/ic_opencv_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_opencv_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-xxhdpi/ic_opencv_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_opencv_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/momomomo111/camerax_opencv/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_opencv_round.png
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 | /deploymentTargetSelector.xml
5 | /kotlinc.xml
6 | /other.xml
7 | /androidTestResultsUserPreferences.xml
8 | /migrations.xml
9 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name = "camerax_opencv"
3 |
4 | def opencvsdk='./OpenCV-android-sdk'
5 | //def opencvsdk='/'
6 | include ':opencv'
7 | project(':opencv').projectDir = new File(opencvsdk + '/sdk')
8 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/options_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Apr 04 18:58:53 JST 2021
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_opencv.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_opencv_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #FFBB86FC
4 | #FF6200EE
5 | #FF3700B3
6 | #FF03DAC5
7 | #FF018786
8 | #FF000000
9 | #FFFFFFFF
10 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/GrayscaleViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class GrayscaleViewModel : ViewModel() {
8 | private val _params = MutableStateFlow(Params.GrayScaleParams(null))
9 | val params: StateFlow = _params
10 | }
11 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/navdrawer_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright [2022] [Motoharu Asanuma]
2 |
3 | Licensed under the Apache License, Version 2.0 (the “License”);
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 | http://www.apache.org/licenses/LICENSE-2.0
7 |
8 | Unless required by applicable law or agreed to in writing, software
9 | distributed under the License is distributed on an “AS IS” BASIS,
10 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 |
12 | See the License for the specific language governing permissions and
13 | limitations under the License.
14 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_baseline_vibration.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # About
2 | Check the results of real-time processing of images from a camera using the OpenCV library.
3 |
4 | - OpenCV official website: https://opencv.org/
5 | - OpenCV official GitHub page: https://github.com/opencv/opencv
6 |
7 | # Requirement
8 |
9 | opencv-4.10.0-android-sdk
10 |
11 | # GooglePlayStore
12 |
13 | https://play.google.com/store/apps/details?id=com.momomomo111.camerax_opencv
14 |
15 | # PrivacyPolicy(English)
16 |
17 | https://momomomo111.github.io/camerax_opencv/PrivacyPolicy/English
18 |
19 | # プライバシーポリシー(日本語)
20 |
21 | https://momomomo111.github.io/camerax_opencv/PrivacyPolicy/Japanese
22 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/LicenceFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import com.momomomo111.camerax_opencv.R
9 |
10 | class LicenceFragment : Fragment() {
11 | override fun onCreateView(
12 | inflater: LayoutInflater,
13 | container: ViewGroup?,
14 | savedInstanceState: Bundle?
15 | ): View? {
16 | return inflater.inflate(R.layout.fragment_licence, container, false)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/ErodeViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class ErodeViewModel : ViewModel() {
8 | private val _params = MutableStateFlow(Params.ErodeParams(1, 1))
9 | val params: StateFlow = _params
10 |
11 | fun onKSizeChange(data: Int) {
12 | _params.value = _params.value.copy(kSize = data)
13 | }
14 |
15 | fun onIterationsChange(data: Int) {
16 | _params.value = _params.value.copy(iterations = data)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/DilateViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class DilateViewModel : ViewModel() {
8 | private val _params = MutableStateFlow(Params.DilateParams(1, 1))
9 | val params: StateFlow = _params
10 |
11 | fun onKSizeChange(data: Int) {
12 | _params.value = _params.value.copy(kSize = data)
13 | }
14 |
15 | fun onIterationsChange(data: Int) {
16 | _params.value = _params.value.copy(iterations = data)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/CannyViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class CannyViewModel : ViewModel() {
8 | private val _params = MutableStateFlow(Params.CannyParams(255.0, 255.0))
9 | val params: StateFlow = _params
10 |
11 | fun onThreshold1Change(data: Double) {
12 | _params.value = _params.value.copy(threshold1 = data)
13 | }
14 |
15 | fun onThreshold2Change(data: Double) {
16 | _params.value = _params.value.copy(threshold2 = data)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/ThresholdViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class ThresholdViewModel : ViewModel() {
8 | private val _params = MutableStateFlow(Params.ThresholdParams(128.0, 255.0))
9 | val params: StateFlow = _params
10 |
11 | fun onThreshChange(data: Double) {
12 | _params.value = _params.value.copy(thresh = data)
13 | }
14 |
15 | fun onMaxValChange(data: Double) {
16 | _params.value = _params.value.copy(maxVal = data)
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/SettingsViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class SettingsViewModel : ViewModel() {
8 | private val _settingsUiState = MutableStateFlow(SettingsUiState.None)
9 | val settingsUiState: StateFlow = _settingsUiState
10 |
11 | fun onVibrationChange(value: Boolean) {
12 | _settingsUiState.value = SettingsUiState.Success(vibration = value)
13 | }
14 | }
15 |
16 | sealed class SettingsUiState {
17 | data class Success(val vibration: Boolean) : SettingsUiState()
18 | object None : SettingsUiState()
19 | }
20 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.kts.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/GaussianblurViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class GaussianblurViewModel : ViewModel() {
8 | private val _params = MutableStateFlow(Params.GaussianBlurParams(1.0, 0.0, 0.0))
9 | val params: StateFlow = _params
10 |
11 | fun onKSizeChange(data: Double) {
12 | _params.value = _params.value.copy(kSize = data)
13 | }
14 |
15 | fun onSigmaXChange(data: Double) {
16 | _params.value = _params.value.copy(sigmaX = data)
17 | }
18 |
19 | fun onSigmaYChange(data: Double) {
20 | _params.value = _params.value.copy(sigmaY = data)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/values/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/values-night/themes.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
16 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_grayscale.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
15 |
16 |
22 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/docs/PrivacyPolicy/Japanese.md:
--------------------------------------------------------------------------------
1 | # プライバシーポリシー
2 |
3 | 本プライバシーポリシーは、OpenCV Image Process(以下、「当アプリ」とします。)の各種サービス(当アプリによる情報提供、各種お問合せの受付等)において、当アプリの利用者(以下、「利用者」とします。)の個人情報もしくはそれに準ずる情報を取り扱う際に、当アプリが遵守する方針を示したものです。
4 |
5 | ## 基本方針
6 |
7 | 当アプリは、個人情報の重要性を認識し、個人情報を保護することが社会的責務であると考え、個人情報に関する法令を遵守し、当アプリで取扱う個人情報の取得、利用、管理を適正に行います。当アプリで収集した情報は、利用目的の範囲内で適切に取り扱います。
8 |
9 | ## 適用範囲
10 |
11 | 本プライバシーポリシーは、当アプリにおいてのみ適用されます。
12 |
13 | ## このサイトが収集する個人データと収集の理由
14 |
15 | 当アプリではアクセス情報を除いた個人データについては収集をしておりません。
16 |
17 | ## アクセス解析ツールについて
18 |
19 | 当サイトでは、Google によるアクセス解析ツール「Google アナリティクス」を利用しています。
20 |
21 | この Google アナリティクスはアクセス情報の収集のために使用しています。このアクセス情報は匿名で収集されており、個人を特定するものではありません。
22 |
23 | Google アナリティクスの利用規約に関して確認したい場合は、Google アナリティクス利用規約をご確認ください。
24 |
25 | また、「ユーザーが Google パートナーのサイトやアプリを使用する際の Google によるデータ使用」に関して確認したい場合は、Google ポリシーと規約:広告をご確認ください。
26 |
27 | ## 個人情報の第三者への提供について
28 |
29 | 当サイトは、利用者からご提供いただいた個人情報を、利用者本人の同意を得ることなく第三者に提供することはありません。
30 |
31 | また、今後第三者提供を行うことになった場合には、提供する情報と提供目的などを提示し、利用者から同意を得た場合のみ第三者提供を行います。
32 |
33 | ## プライバシーポリシーの変更について
34 |
35 | 当アプリは、個人情報に関して適用される日本の法令を遵守するとともに、本プライバシーポリシーの内容を適宜見直しその改善に努めます。修正された最新のプライバシーポリシーは常に本ページにて開示されます。
36 |
37 | 2021 年 8 月 9 日 策定
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/util/VibrationUtil.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.util
2 |
3 | import android.annotation.SuppressLint
4 | import android.content.Context
5 | import android.os.Build
6 | import android.os.VibrationEffect
7 | import android.os.Vibrator
8 | import android.os.VibratorManager
9 |
10 | object VibrationUtil {
11 | @SuppressLint("WrongConstant")
12 | fun setVibrator(context: Context?): Vibrator {
13 | val vibrator = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
14 | val vibratorManager =
15 | context?.getSystemService(Context.VIBRATOR_MANAGER_SERVICE) as VibratorManager
16 | vibratorManager.defaultVibrator
17 | } else {
18 | context?.getSystemService(Context.VIBRATOR_SERVICE) as Vibrator
19 | }
20 | return vibrator
21 | }
22 |
23 | fun Vibrator.effectSlider() {
24 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
25 | val effect = VibrationEffect.createOneShot(10, VibrationEffect.DEFAULT_AMPLITUDE)
26 | this.vibrate(effect)
27 | } else {
28 | this.vibrate(10)
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/Params.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.annotation.Nullable
4 |
5 | sealed class Params {
6 | data class GaussianBlurParams(val kSize: Double, val sigmaX: Double, val sigmaY: Double) :
7 | Params()
8 |
9 | data class ThresholdParams(val thresh: Double, val maxVal: Double) : Params()
10 | data class CannyParams(val threshold1: Double, val threshold2: Double) : Params()
11 | data class GrayScaleParams(val param: Nullable?) : Params()
12 | data class RgbExtractionParams(
13 | val upperR: Double,
14 | val upperG: Double,
15 | val upperB: Double,
16 | val lowerR: Double,
17 | val lowerG: Double,
18 | val lowerB: Double
19 | ) : Params()
20 | data class HsvExtractionParams(
21 | val upperH: Double,
22 | val upperS: Double,
23 | val upperV: Double,
24 | val lowerH: Double,
25 | val lowerS: Double,
26 | val lowerV: Double
27 | ) : Params()
28 | data class ErodeParams(val kSize: Int, val iterations: Int) :
29 | Params()
30 | data class DilateParams(val kSize: Int, val iterations: Int) :
31 | Params()
32 | }
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/HsvextractionViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class HsvextractionViewModel : ViewModel() {
8 | private val _params =
9 | MutableStateFlow(Params.HsvExtractionParams(255.0, 255.0, 255.0, 0.0, 0.0, 0.0))
10 | val params: StateFlow = _params
11 |
12 | fun onUpperHChange(data: Double) {
13 | _params.value = _params.value.copy(upperH = data)
14 | }
15 |
16 | fun onUpperSChange(data: Double) {
17 | _params.value = _params.value.copy(upperS = data)
18 | }
19 |
20 | fun onUpperVChange(data: Double) {
21 | _params.value = _params.value.copy(upperV = data)
22 | }
23 |
24 | fun onLowerHChange(data: Double) {
25 | _params.value = _params.value.copy(lowerH = data)
26 | }
27 |
28 | fun onLowerSChange(data: Double) {
29 | _params.value = _params.value.copy(lowerS = data)
30 | }
31 |
32 | fun onLowerVChange(data: Double) {
33 | _params.value = _params.value.copy(lowerV = data)
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/data/RgbextractionViewModel.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.data
2 |
3 | import androidx.lifecycle.ViewModel
4 | import kotlinx.coroutines.flow.MutableStateFlow
5 | import kotlinx.coroutines.flow.StateFlow
6 |
7 | class RgbextractionViewModel : ViewModel() {
8 | private val _params =
9 | MutableStateFlow(Params.RgbExtractionParams(255.0, 255.0, 255.0, 0.0, 0.0, 0.0))
10 | val params: StateFlow = _params
11 |
12 | fun onUpperRChange(data: Double) {
13 | _params.value = _params.value.copy(upperR = data)
14 | }
15 |
16 | fun onUpperGChange(data: Double) {
17 | _params.value = _params.value.copy(upperG = data)
18 | }
19 |
20 | fun onUpperBChange(data: Double) {
21 | _params.value = _params.value.copy(upperB = data)
22 | }
23 |
24 | fun onLowerRChange(data: Double) {
25 | _params.value = _params.value.copy(lowerR = data)
26 | }
27 |
28 | fun onLowerGChange(data: Double) {
29 | _params.value = _params.value.copy(lowerG = data)
30 | }
31 |
32 | fun onLowerBChange(data: Double) {
33 | _params.value = _params.value.copy(lowerB = data)
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/.idea/jarRepositories.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app"s APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
23 | android.buildTypes.release.ndk.debugSymbolLevel = { SYMBOL_TABLE | FULL }
24 | android.defaults.buildfeatures.buildconfig=true
25 | android.nonTransitiveRClass=false
26 | android.nonFinalResIds=false
--------------------------------------------------------------------------------
/.github/workflows/android.yml:
--------------------------------------------------------------------------------
1 | name: Android CI
2 |
3 | on:
4 | push:
5 | branches: [ "main" ]
6 | pull_request:
7 | branches: [ "main" ]
8 |
9 | jobs:
10 | android-test:
11 | runs-on: ubuntu-latest
12 | strategy:
13 | matrix:
14 | api-level: [ 22, 23, 24, 25, 26, 27, 28, 29, 30 ] # Enumerate terminals where emulators are supported.
15 | fail-fast: false
16 | timeout-minutes: 30 # Specify a timeout as testing on emulators is unstable.
17 | steps:
18 | - name: Check out
19 | uses: actions/checkout@v3
20 | - name: Set up JDK
21 | uses: actions/setup-java@v3
22 | with:
23 | distribution: 'zulu'
24 | java-version: 17
25 | - uses: actions/cache@v3.0.8
26 | with:
27 | path: |
28 | ~/.gradle/caches
29 | ~/.gradle/wrapper
30 | key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
31 | restore-keys: |
32 | ${{ runner.os }}-gradle-
33 | - name: Enable KVM group perms
34 | run: |
35 | echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
36 | sudo udevadm control --reload-rules
37 | sudo udevadm trigger --name-match=kvm
38 | - name: Run Android test
39 | uses: reactivecircus/android-emulator-runner@v2
40 | with:
41 | api-level: ${{ matrix.api-level }}
42 | target: 'google_apis'
43 | arch: 'x86'
44 | profile: 'pixel'
45 | disable-animations: true
46 | script: ./gradlew connectedAndroidTest
47 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Built application files
2 | *.apk
3 | *.aar
4 | *.ap_
5 | *.aab
6 |
7 | # Files for the ART/Dalvik VM
8 | *.dex
9 |
10 | # Java class files
11 | *.class
12 |
13 | # Generated files
14 | bin/
15 | gen/
16 | out/
17 | # Uncomment the following line in case you need and you don't have the release build type files in your app
18 | # release/
19 |
20 | # Gradle files
21 | .gradle/
22 | build/
23 |
24 | # Local configuration file (sdk path, etc)
25 | local.properties
26 |
27 | # Proguard folder generated by Eclipse
28 | proguard/
29 |
30 | # Log Files
31 | *.log
32 |
33 | # Android Studio Navigation editor temp files
34 | .navigation/
35 |
36 | # Android Studio captures folder
37 | captures/
38 |
39 | # IntelliJ
40 | *.iml
41 | .idea/workspace.xml
42 | .idea/tasks.xml
43 | .idea/gradle.xml
44 | .idea/assetWizardSettings.xml
45 | .idea/dictionaries
46 | .idea/libraries
47 | .idea/misc.xml
48 | # Android Studio 3 in .gitignore file.
49 | .idea/caches
50 | .idea/modules.xml
51 | # Comment next line if keeping position of elements in Navigation Editor is relevant for you
52 | .idea/navEditor.xml
53 | .idea/misc.xml
54 |
55 | # Keystore files
56 | # Uncomment the following lines if you do not want to check your keystore files in.
57 | #*.jks
58 | #*.keystore
59 |
60 | # External native build folder generated in Android Studio 2.2 and later
61 | .externalNativeBuild
62 | .cxx/
63 |
64 | # Google Services (e.g. APIs or Firebase)
65 | # google-services.json
66 |
67 | # Freeline
68 | freeline.py
69 | freeline/
70 | freeline_project_description.json
71 |
72 | # fastlane
73 | fastlane/report.xml
74 | fastlane/Preview.html
75 | fastlane/screenshots
76 | fastlane/test_output
77 | fastlane/readme.md
78 |
79 | # Version control
80 | vcs.xml
81 |
82 | # lint
83 | lint/intermediates/
84 | lint/generated/
85 | lint/outputs/
86 | lint/tmp/
87 | # lint/reports/
88 |
89 | # OpenCV-SDK
90 | OpenCV-android-sdk/
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_licence.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
30 |
31 |
42 |
43 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/GrayScaleFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import com.momomomo111.camerax_opencv.data.GrayscaleViewModel
10 | import com.momomomo111.camerax_opencv.databinding.FragmentGrayscaleBinding
11 | import com.momomomo111.camerax_opencv.util.CameraUtil
12 | import com.momomomo111.camerax_opencv.util.ProcessImageAnalyzer
13 |
14 | class GrayScaleFragment : Fragment() {
15 | private val viewModel: GrayscaleViewModel by viewModels()
16 |
17 | private var _binding: FragmentGrayscaleBinding? = null
18 | private val binding get() = _binding!!
19 |
20 | override fun onCreateView(
21 | inflater: LayoutInflater,
22 | container: ViewGroup?,
23 | savedInstanceState: Bundle?
24 | ): View {
25 | _binding = FragmentGrayscaleBinding.inflate(inflater, container, false)
26 | return binding.root
27 | }
28 |
29 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
30 | super.onViewCreated(view, savedInstanceState)
31 |
32 | CameraUtil.startCamera(
33 | requireContext(),
34 | ProcessImageAnalyzer(
35 | {
36 | runOnUiThread {
37 | _binding?.imageView?.setImageBitmap(
38 | it
39 | )
40 | }
41 | },
42 | viewModel.params
43 | )
44 | )
45 | }
46 |
47 | override fun onDestroyView() {
48 | super.onDestroyView()
49 | _binding = null
50 | }
51 |
52 | private fun Fragment.runOnUiThread(action: () -> Unit) {
53 | if (!isAdded) return
54 | activity?.runOnUiThread(action)
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_license.xml:
--------------------------------------------------------------------------------
1 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/build.gradle.kts:
--------------------------------------------------------------------------------
1 | plugins {
2 | id("com.android.application")
3 | kotlin("android")
4 | kotlin("kapt")
5 | id("androidx.navigation.safeargs.kotlin")
6 | }
7 |
8 | android {
9 | compileSdk = 34
10 |
11 | defaultConfig {
12 | applicationId = "com.momomomo111.camerax_opencv"
13 | minSdk = 22
14 | targetSdk = 34
15 | versionCode = 10
16 | versionName = "1.3.0"
17 |
18 | testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
19 | }
20 | buildFeatures {
21 | viewBinding = true
22 | }
23 | buildTypes {
24 | getByName("release") {
25 | isMinifyEnabled = false
26 | proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), file("proguard-rules.pro"))
27 | }
28 | }
29 | compileOptions {
30 | sourceCompatibility = JavaVersion.VERSION_17
31 | targetCompatibility = JavaVersion.VERSION_17
32 | }
33 | namespace = "com.momomomo111.camerax_opencv"
34 | tasks.withType {
35 | kotlinOptions {
36 | jvmTarget = "17"
37 | }
38 | }
39 | }
40 |
41 | dependencies {
42 | implementation("androidx.core:core-ktx:1.13.1")
43 | implementation("androidx.appcompat:appcompat:1.7.0")
44 | implementation("com.google.android.material:material:1.12.0")
45 | implementation("androidx.constraintlayout:constraintlayout:2.1.4")
46 | implementation("androidx.activity:activity-ktx:1.9.0")
47 | implementation("androidx.fragment:fragment-ktx:1.8.1")
48 | implementation("androidx.navigation:navigation-fragment-ktx:2.7.7")
49 | implementation("androidx.navigation:navigation-ui-ktx:2.7.7")
50 | implementation("androidx.lifecycle:lifecycle-livedata-ktx:2.8.3")
51 | implementation("org.opencv:opencv:4.10.0")
52 | // CameraX
53 | val cameraxVersion = "1.3.4"
54 | implementation("androidx.camera:camera-camera2:$cameraxVersion")
55 | implementation("androidx.camera:camera-lifecycle:$cameraxVersion")
56 | implementation("androidx.camera:camera-view:$cameraxVersion")
57 | // Unit testing
58 | androidTestImplementation("androidx.test.ext:junit:1.2.1")
59 | androidTestImplementation("androidx.test:core:1.6.1")
60 | androidTestImplementation("androidx.test:rules:1.6.1")
61 | androidTestImplementation("androidx.test:runner:1.6.1")
62 | androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
63 | }
64 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv
2 |
3 | import android.content.Context
4 | import android.os.Bundle
5 | import androidx.activity.viewModels
6 | import androidx.appcompat.app.AppCompatActivity
7 | import androidx.drawerlayout.widget.DrawerLayout
8 | import androidx.navigation.findNavController
9 | import androidx.navigation.fragment.NavHostFragment
10 | import androidx.navigation.ui.NavigationUI
11 | import com.google.android.material.switchmaterial.SwitchMaterial
12 | import com.momomomo111.camerax_opencv.data.SettingsViewModel
13 | import com.momomomo111.camerax_opencv.databinding.ActivityMainBinding
14 |
15 | class MainActivity : AppCompatActivity() {
16 | private lateinit var drawerLayout: DrawerLayout
17 | private lateinit var binding: ActivityMainBinding
18 | override fun onCreate(savedInstanceState: Bundle?) {
19 | super.onCreate(savedInstanceState)
20 | binding = ActivityMainBinding.inflate(layoutInflater)
21 | setContentView(binding.root)
22 | drawerLayout = binding.drawerLayout
23 | val settingsViewModel: SettingsViewModel by viewModels()
24 | val navController = (
25 | supportFragmentManager.findFragmentById(R.id.myNavHostFragment)
26 | as NavHostFragment
27 | ).navController
28 | NavigationUI.setupActionBarWithNavController(this, navController, drawerLayout)
29 | NavigationUI.setupWithNavController(binding.navView, navController)
30 |
31 | val sharedPref = getPreferences(Context.MODE_PRIVATE) ?: return
32 |
33 | val vibSwitch = SwitchMaterial(this)
34 | val vibrationEnable = sharedPref.getBoolean(getString(R.string.vibration_enable), true)
35 | vibSwitch.isChecked = vibrationEnable
36 | settingsViewModel.onVibrationChange(vibrationEnable)
37 | vibSwitch.setOnCheckedChangeListener { _, isChecked ->
38 | with(sharedPref.edit()) {
39 | putBoolean(getString(R.string.vibration_enable), isChecked)
40 | settingsViewModel.onVibrationChange(isChecked)
41 | apply()
42 | }
43 | }
44 | binding.navView.menu.findItem(R.id.vibrationSwitch).actionView = vibSwitch
45 | }
46 |
47 | override fun onSupportNavigateUp(): Boolean {
48 | val navController = this.findNavController(R.id.myNavHostFragment)
49 | return NavigationUI.navigateUp(navController, drawerLayout)
50 | }
51 |
52 | companion object {
53 | init {
54 | System.loadLibrary("opencv_java4")
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/docs/PrivacyPolicy/English.md:
--------------------------------------------------------------------------------
1 | # Privacy Policy
2 |
3 | This Privacy Policy applies to all services of OpenCV Image Process (hereinafter referred to as "this application"). (hereinafter referred to as "the Application") in various services (such as the provision of information by the Application and the acceptance of various inquiries) of the users of the Application (hereinafter referred to as "the Users"). (hereinafter referred to as "the App") in various services (such as providing information through the App and accepting various inquiries).
4 |
5 | ## Basic Policy
6 |
7 | This application recognizes the importance of personal information and considers the protection of personal information to be a social responsibility, and complies with laws and regulations regarding personal information, and appropriately acquires, uses, and manages personal information handled by this application. The information collected by this application will be handled appropriately within the scope of the purpose of use.
8 |
9 | ## Scope of application
10 |
11 | This privacy policy applies only to this application.
12 |
13 | ## Personal data collected by this site and reasons for collection
14 |
15 | This app does not collect any personal data except access information.
16 |
17 | ## About access analysis tools
18 |
19 | This site uses Google Analytics, an access analysis tool by Google.
20 |
21 | This Google Analytics is used to collect access information. This access information is collected anonymously and does not identify any individual.
22 |
23 | If you would like to learn more about the Google Analytics Terms of Service, please see the Google Analytics Terms of Service.
24 |
25 | If you would like to learn more about Google's use of your data when you use Google partners' sites and apps, please see Google Policies and Terms: Advertising.
26 |
27 | ## Sharing of personal information with third parties
28 |
29 | This site will not provide personal information provided by users to third parties without their consent.
30 |
31 | If we decide to provide the information to a third party in the future, we will present the information to be provided and the purpose for which it will be provided, and we will provide the information to the third party only after obtaining the consent of the user.
32 |
33 | ## Changes to the Privacy Policy
34 |
35 | In addition to complying with the Japanese laws and regulations applicable to personal information, this application will review and improve the contents of this privacy policy from time to time. The revised and updated Privacy Policy will always be disclosed on this page.
36 |
37 | Formulated on August 9, 2021
38 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_erode.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
40 |
41 |
51 |
52 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_dilate.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
40 |
41 |
51 |
52 |
62 |
63 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_threshold.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
40 |
41 |
53 |
54 |
65 |
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_canny.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
40 |
41 |
52 |
53 |
64 |
65 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/ErodeFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.navArgs
10 | import com.momomomo111.camerax_opencv.R
11 | import com.momomomo111.camerax_opencv.data.ErodeViewModel
12 | import com.momomomo111.camerax_opencv.databinding.FragmentErodeBinding
13 | import com.momomomo111.camerax_opencv.util.CameraUtil
14 | import com.momomomo111.camerax_opencv.util.ProcessImageAnalyzer
15 | import com.momomomo111.camerax_opencv.util.VibrationUtil
16 | import com.momomomo111.camerax_opencv.util.VibrationUtil.effectSlider
17 |
18 | class ErodeFragment : Fragment() {
19 | private val erodeViewModel: ErodeViewModel by viewModels()
20 | private val args: ErodeFragmentArgs by navArgs()
21 |
22 | private var _binding: FragmentErodeBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | override fun onCreateView(
26 | inflater: LayoutInflater,
27 | container: ViewGroup?,
28 | savedInstanceState: Bundle?
29 | ): View {
30 | _binding = FragmentErodeBinding.inflate(inflater, container, false)
31 | return binding.root
32 | }
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 |
37 | val enableVibration = args.vibrationEnable
38 |
39 | CameraUtil.startCamera(
40 | requireContext(),
41 | ProcessImageAnalyzer(
42 | {
43 | runOnUiThread {
44 | _binding?.imageView?.setImageBitmap(
45 | it
46 | )
47 | }
48 | },
49 | erodeViewModel.params
50 | )
51 | )
52 |
53 | val vibrator = VibrationUtil.setVibrator(this.context)
54 |
55 | _binding?.sliderKSize?.addOnChangeListener { _, value, _ ->
56 | val kSize = value.toInt()
57 | erodeViewModel.onKSizeChange(kSize)
58 | binding.kSizeText.text = getString(R.string.k_size, kSize.toString())
59 | if (enableVibration) {
60 | vibrator.effectSlider()
61 | }
62 | }
63 | _binding?.sliderIterations?.addOnChangeListener { _, value, _ ->
64 | val iterations = value.toInt()
65 | erodeViewModel.onIterationsChange(iterations)
66 | binding.iterationsText.text = getString(R.string.iterations, iterations.toString())
67 | if (enableVibration) {
68 | vibrator.effectSlider()
69 | }
70 | }
71 | }
72 |
73 | override fun onDestroyView() {
74 | super.onDestroyView()
75 | _binding = null
76 | }
77 |
78 | private fun Fragment.runOnUiThread(action: () -> Unit) {
79 | if (!isAdded) return
80 | activity?.runOnUiThread(action)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/CannyFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.navArgs
10 | import com.momomomo111.camerax_opencv.R
11 | import com.momomomo111.camerax_opencv.data.CannyViewModel
12 | import com.momomomo111.camerax_opencv.databinding.FragmentCannyBinding
13 | import com.momomomo111.camerax_opencv.util.CameraUtil
14 | import com.momomomo111.camerax_opencv.util.ProcessImageAnalyzer
15 | import com.momomomo111.camerax_opencv.util.VibrationUtil.effectSlider
16 | import com.momomomo111.camerax_opencv.util.VibrationUtil.setVibrator
17 |
18 | class CannyFragment : Fragment() {
19 | private val cannyViewModel: CannyViewModel by viewModels()
20 | private val args: CannyFragmentArgs by navArgs()
21 |
22 | private var _binding: FragmentCannyBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | override fun onCreateView(
26 | inflater: LayoutInflater,
27 | container: ViewGroup?,
28 | savedInstanceState: Bundle?
29 | ): View {
30 | _binding = FragmentCannyBinding.inflate(inflater, container, false)
31 | return binding.root
32 | }
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 |
37 | val enableVibration = args.vibrationEnable
38 |
39 | CameraUtil.startCamera(
40 | requireContext(),
41 | ProcessImageAnalyzer(
42 | {
43 | runOnUiThread {
44 | _binding?.imageView?.setImageBitmap(
45 | it
46 | )
47 | }
48 | },
49 | cannyViewModel.params
50 | ),
51 | )
52 |
53 | val vibrator = setVibrator(this.context)
54 |
55 | _binding?.sliderThreshold1?.addOnChangeListener { _, value, _ ->
56 | val thresh = value.toDouble()
57 | cannyViewModel.onThreshold1Change(thresh)
58 | binding.threshold1.text = getString(R.string.threshold1, thresh.toString())
59 | if (enableVibration) {
60 | vibrator.effectSlider()
61 | }
62 | }
63 | _binding?.sliderThreshold2?.addOnChangeListener { _, value, _ ->
64 | val maxVal = value.toDouble()
65 | cannyViewModel.onThreshold2Change(maxVal)
66 | binding.threshold2.text = getString(R.string.threshold2, maxVal.toString())
67 | if (enableVibration) {
68 | vibrator.effectSlider()
69 | }
70 | }
71 | }
72 |
73 | override fun onDestroyView() {
74 | super.onDestroyView()
75 | _binding = null
76 | }
77 |
78 | private fun Fragment.runOnUiThread(action: () -> Unit) {
79 | if (!isAdded) return
80 | activity?.runOnUiThread(action)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/DilateFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.navArgs
10 | import com.momomomo111.camerax_opencv.R
11 | import com.momomomo111.camerax_opencv.data.DilateViewModel
12 | import com.momomomo111.camerax_opencv.databinding.FragmentDilateBinding
13 | import com.momomomo111.camerax_opencv.util.CameraUtil
14 | import com.momomomo111.camerax_opencv.util.ProcessImageAnalyzer
15 | import com.momomomo111.camerax_opencv.util.VibrationUtil
16 | import com.momomomo111.camerax_opencv.util.VibrationUtil.effectSlider
17 |
18 | class DilateFragment : Fragment() {
19 | private val dilateViewModel: DilateViewModel by viewModels()
20 | private val args: DilateFragmentArgs by navArgs()
21 |
22 | private var _binding: FragmentDilateBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | override fun onCreateView(
26 | inflater: LayoutInflater,
27 | container: ViewGroup?,
28 | savedInstanceState: Bundle?
29 | ): View {
30 | _binding = FragmentDilateBinding.inflate(inflater, container, false)
31 | return binding.root
32 | }
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 |
37 | val enableVibration = args.vibrationEnable
38 |
39 | CameraUtil.startCamera(
40 | requireContext(),
41 | ProcessImageAnalyzer(
42 | {
43 | runOnUiThread {
44 | _binding?.imageView?.setImageBitmap(
45 | it
46 | )
47 | }
48 | },
49 | dilateViewModel.params
50 | ),
51 | )
52 |
53 | val vibrator = VibrationUtil.setVibrator(this.context)
54 |
55 | _binding?.sliderKSize?.addOnChangeListener { _, value, _ ->
56 | val kSize = value.toInt()
57 | dilateViewModel.onKSizeChange(kSize)
58 | binding.kSizeText.text = getString(R.string.k_size, kSize.toString())
59 | if (enableVibration) {
60 | vibrator.effectSlider()
61 | }
62 | }
63 | _binding?.sliderIterations?.addOnChangeListener { _, value, _ ->
64 | val iterations = value.toInt()
65 | dilateViewModel.onIterationsChange(iterations)
66 | binding.iterationsText.text = getString(R.string.iterations, iterations.toString())
67 | if (enableVibration) {
68 | vibrator.effectSlider()
69 | }
70 | }
71 | }
72 |
73 | override fun onDestroyView() {
74 | super.onDestroyView()
75 | _binding = null
76 | }
77 |
78 | private fun Fragment.runOnUiThread(action: () -> Unit) {
79 | if (!isAdded) return
80 | activity?.runOnUiThread(action)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/ThresholdFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.navArgs
10 | import com.momomomo111.camerax_opencv.R
11 | import com.momomomo111.camerax_opencv.data.ThresholdViewModel
12 | import com.momomomo111.camerax_opencv.databinding.FragmentThresholdBinding
13 | import com.momomomo111.camerax_opencv.util.CameraUtil
14 | import com.momomomo111.camerax_opencv.util.ProcessImageAnalyzer
15 | import com.momomomo111.camerax_opencv.util.VibrationUtil
16 | import com.momomomo111.camerax_opencv.util.VibrationUtil.effectSlider
17 |
18 | class ThresholdFragment : Fragment() {
19 | private val thresholdViewModel: ThresholdViewModel by viewModels()
20 | private val args: ThresholdFragmentArgs by navArgs()
21 |
22 | private var _binding: FragmentThresholdBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | override fun onCreateView(
26 | inflater: LayoutInflater,
27 | container: ViewGroup?,
28 | savedInstanceState: Bundle?
29 | ): View {
30 | _binding = FragmentThresholdBinding.inflate(inflater, container, false)
31 | return binding.root
32 | }
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 |
37 | val enableVibration = args.vibrationEnable
38 |
39 | CameraUtil.startCamera(
40 | requireContext(),
41 | ProcessImageAnalyzer(
42 | {
43 | runOnUiThread {
44 | _binding?.imageView?.setImageBitmap(
45 | it
46 | )
47 | }
48 | },
49 | thresholdViewModel.params
50 | )
51 | )
52 |
53 | val vibrator = VibrationUtil.setVibrator(this.context)
54 |
55 | _binding?.sliderThresh?.addOnChangeListener { _, value, _ ->
56 | val thresh = value.toDouble()
57 | thresholdViewModel.onThreshChange(thresh)
58 | binding.thresh.text = getString(R.string.thresh, thresh.toString())
59 | if (enableVibration) {
60 | vibrator.effectSlider()
61 | }
62 | }
63 | _binding?.sliderMaxVal?.addOnChangeListener { _, value, _ ->
64 | val maxVal = value.toDouble()
65 | thresholdViewModel.onMaxValChange(maxVal)
66 | binding.MaxVal.text = getString(R.string.max_val, maxVal.toString())
67 | if (enableVibration) {
68 | vibrator.effectSlider()
69 | }
70 | }
71 | }
72 |
73 | override fun onDestroyView() {
74 | super.onDestroyView()
75 | _binding = null
76 | }
77 |
78 | private fun Fragment.runOnUiThread(action: () -> Unit) {
79 | if (!isAdded) return
80 | activity?.runOnUiThread(action)
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/GaussianBlurFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.navArgs
10 | import com.momomomo111.camerax_opencv.R
11 | import com.momomomo111.camerax_opencv.data.GaussianblurViewModel
12 | import com.momomomo111.camerax_opencv.databinding.FragmentGaussianblurBinding
13 | import com.momomomo111.camerax_opencv.util.CameraUtil
14 | import com.momomomo111.camerax_opencv.util.ProcessImageAnalyzer
15 | import com.momomomo111.camerax_opencv.util.VibrationUtil
16 | import com.momomomo111.camerax_opencv.util.VibrationUtil.effectSlider
17 |
18 | class GaussianBlurFragment : Fragment() {
19 | private val gaussianblurViewModel: GaussianblurViewModel by viewModels()
20 | private val args: GaussianBlurFragmentArgs by navArgs()
21 |
22 | private var _binding: FragmentGaussianblurBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | override fun onCreateView(
26 | inflater: LayoutInflater,
27 | container: ViewGroup?,
28 | savedInstanceState: Bundle?
29 | ): View {
30 | _binding = FragmentGaussianblurBinding.inflate(inflater, container, false)
31 | return binding.root
32 | }
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 |
37 | val enableVibration = args.vibrationEnable
38 |
39 | CameraUtil.startCamera(
40 | requireContext(),
41 | ProcessImageAnalyzer(
42 | {
43 | runOnUiThread {
44 | _binding?.imageView?.setImageBitmap(
45 | it
46 | )
47 | }
48 | },
49 | gaussianblurViewModel.params
50 | )
51 | )
52 |
53 | val vibrator = VibrationUtil.setVibrator(this.context)
54 |
55 | _binding?.sliderKSize?.addOnChangeListener { _, value, _ ->
56 | val kSize = value.toDouble()
57 | gaussianblurViewModel.onKSizeChange(kSize)
58 | binding.kSizeText.text = getString(R.string.k_size, kSize.toString())
59 | if (enableVibration) {
60 | vibrator.effectSlider()
61 | }
62 | }
63 | _binding?.sliderSigmaX?.addOnChangeListener { _, value, _ ->
64 | val sigmaX = value.toDouble()
65 | gaussianblurViewModel.onSigmaXChange(sigmaX)
66 | binding.sigmaXText.text = getString(R.string.sigma_x, sigmaX.toString())
67 | if (enableVibration) {
68 | vibrator.effectSlider()
69 | }
70 | }
71 | _binding?.sliderSigmaY?.addOnChangeListener { _, value, _ ->
72 | val sigmaY = value.toDouble()
73 | gaussianblurViewModel.onSigmaYChange(sigmaY)
74 | binding.sigmaYText.text = getString(R.string.sigma_y, sigmaY.toString())
75 | if (enableVibration) {
76 | vibrator.effectSlider()
77 | }
78 | }
79 | }
80 |
81 | override fun onDestroyView() {
82 | super.onDestroyView()
83 | _binding = null
84 | }
85 |
86 | private fun Fragment.runOnUiThread(action: () -> Unit) {
87 | if (!isAdded) return
88 | activity?.runOnUiThread(action)
89 | }
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_gaussianblur.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
39 |
40 |
50 |
51 |
61 |
62 |
72 |
73 |
83 |
84 |
--------------------------------------------------------------------------------
/.idea/$CACHE_FILE$:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Android
10 |
11 |
12 | ClassesObjective-C
13 |
14 |
15 | CorrectnessLintAndroid
16 |
17 |
18 | EditorConfig
19 |
20 |
21 | JNIAndroid
22 |
23 |
24 | JUnitJava
25 |
26 |
27 | Java
28 |
29 |
30 | Java 14Java language level migration aidsJava
31 |
32 |
33 | Java 5Java language level migration aidsJava
34 |
35 |
36 | Java 7Java language level migration aidsJava
37 |
38 |
39 | Java 8Java language level migration aidsJava
40 |
41 |
42 | Java language level migration aidsJava
43 |
44 |
45 | Java 言語レベルの移行支援Java
46 |
47 |
48 | JavadocJava
49 |
50 |
51 | Kotlin
52 |
53 |
54 | Kotlin Android
55 |
56 |
57 | LintAndroid
58 |
59 |
60 | Message resolutionObjective-C
61 |
62 |
63 | Objective-C
64 |
65 |
66 | PerformanceLintAndroid
67 |
68 |
69 | ProductivityLintAndroid
70 |
71 |
72 | SecurityLintAndroid
73 |
74 |
75 | Style issuesKotlin
76 |
77 |
78 | UsabilityLintAndroid
79 |
80 |
81 | クラス構造Java
82 |
83 |
84 | コード・スタイル問題Java
85 |
86 |
87 | ポータビリティーJava
88 |
89 |
90 | 一般
91 |
92 |
93 | 依存関係問題Java
94 |
95 |
96 | 国際化対応
97 |
98 |
99 | 国際化対応Java
100 |
101 |
102 | 宣言の冗長性Java
103 |
104 |
105 | 推定されるバグJava
106 |
107 |
108 | 数値問題Java
109 |
110 |
111 | 継承問題Java
112 |
113 |
114 | 詳細または冗長なコード構成Java
115 |
116 |
117 |
118 |
119 | Android
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/util/ProcessImageAnalyzer.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.util
2 |
3 | import android.graphics.Bitmap
4 | import androidx.camera.core.ImageAnalysis
5 | import androidx.camera.core.ImageProxy
6 | import com.momomomo111.camerax_opencv.data.Params
7 | import kotlinx.coroutines.flow.StateFlow
8 | import org.opencv.android.Utils
9 | import org.opencv.core.Core
10 | import org.opencv.core.Mat
11 | import org.opencv.core.Point
12 | import org.opencv.core.Scalar
13 | import org.opencv.core.Size
14 | import org.opencv.imgproc.Imgproc
15 |
16 | class ProcessImageAnalyzer(
17 | val runOnUiThread: (Bitmap) -> Unit,
18 | val params: StateFlow
19 | ) : ImageAnalysis.Analyzer {
20 | override fun analyze(image: ImageProxy) {
21 | val mat: Mat = CameraUtil.getMatFromImage(image)
22 | val matMask = Mat(mat.rows(), mat.cols(), 0)
23 | val matTemp = Mat(mat.rows(), mat.cols(), mat.type())
24 | val matOutput = Mat(mat.rows(), mat.cols(), mat.type())
25 |
26 | when (val params = params.value) {
27 | is Params.GaussianBlurParams -> {
28 | Imgproc.GaussianBlur(
29 | mat,
30 | matOutput,
31 | Size(params.kSize, params.kSize),
32 | params.sigmaX,
33 | params.sigmaY
34 | )
35 | }
36 | is Params.ThresholdParams -> {
37 | Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2GRAY)
38 | Imgproc.threshold(
39 | mat,
40 | matOutput,
41 | params.thresh,
42 | params.maxVal,
43 | 0
44 | )
45 | }
46 | is Params.CannyParams -> {
47 | Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2GRAY)
48 | Imgproc.Canny(
49 | mat,
50 | matOutput,
51 | params.threshold1,
52 | params.threshold2
53 | )
54 | }
55 | is Params.GrayScaleParams -> {
56 | Imgproc.cvtColor(mat, matOutput, Imgproc.COLOR_RGB2GRAY)
57 | }
58 | is Params.RgbExtractionParams -> {
59 | val sMin = Scalar(params.lowerR, params.lowerG, params.lowerB)
60 | val sMax = Scalar(params.upperR, params.upperG, params.upperB)
61 | Core.inRange(mat, sMin, sMax, matMask)
62 | Core.bitwise_and(mat, mat, matOutput, matMask)
63 | }
64 | is Params.HsvExtractionParams -> {
65 | val sMin = Scalar(params.lowerH, params.lowerS, params.lowerV)
66 | val sMax = Scalar(params.upperH, params.upperS, params.upperV)
67 | Imgproc.cvtColor(mat, mat, Imgproc.COLOR_RGB2HSV)
68 | Core.inRange(mat, sMin, sMax, matMask)
69 | Core.bitwise_and(mat, mat, matTemp, matMask)
70 | Imgproc.cvtColor(matTemp, matOutput, Imgproc.COLOR_HSV2RGB)
71 | }
72 | is Params.ErodeParams -> {
73 | Imgproc.erode(
74 | mat,
75 | matOutput,
76 | Mat(params.kSize, params.kSize, 0),
77 | Point(-1.0, -1.0),
78 | params.iterations
79 | )
80 | }
81 | is Params.DilateParams -> {
82 | Imgproc.dilate(
83 | mat,
84 | matOutput,
85 | Mat(params.kSize, params.kSize, 0),
86 | Point(-1.0, -1.0),
87 | params.iterations
88 | )
89 | }
90 | }
91 | val bitmap: Bitmap =
92 | Bitmap.createBitmap(matOutput.cols(), matOutput.rows(), Bitmap.Config.ARGB_8888)
93 | Utils.matToBitmap(matOutput, bitmap)
94 | runOnUiThread(bitmap)
95 | image.close()
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | camerax_opencv
3 |
4 | Copyright [2022] [Motoharu Asanuma]\n
5 |
6 | Licensed under the Apache License, Version 2.0 (the “License”);\n
7 | you may not use this file except in compliance with the License.\n
8 | You may obtain a copy of the License at\n
9 | http://www.apache.org/licenses/LICENSE-2.0\n
10 |
11 | Unless required by applicable law or agreed to in writing, software
12 | distributed under the License is distributed on an “AS IS” BASIS,
13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n
14 |
15 | See the License for the specific language governing permissions and
16 | limitations under the License.
17 |
18 | ksize: %s
19 | ksize: 1.0
20 | kernel: %s
21 | sigmaX: %s
22 | sigmaX: 0.0
23 | sigmaY: %s
24 | sigmaY: 0.0
25 | thresh: %s
26 | thresh: 128.0
27 | maxval: %s
28 | maxval: 255.0
29 | iterations: %s
30 | iterations: 1
31 | threshold1: %s
32 | threshold1: 255.0
33 | threshold2: %s
34 | threshold2: 255.0
35 | upper_R: \n %s
36 | upper_R: \n 255.0
37 | upper_G: \n %s
38 | upper_G: \n 255.0
39 | upper_B: \n %s
40 | upper_B: \n 255.0
41 | lower_R: \n %s
42 | lower_R: \n 0.0
43 | lower_G: \n %s
44 | lower_G: \n 0.0
45 | lower_B: \n %s
46 | lower_B: \n 0.0
47 | upper_H: \n %s
48 | upper_H: \n 255.0
49 | upper_S: \n %s
50 | upper_S: \n 255.0
51 | upper_V: \n %s
52 | upper_V: \n 255.0
53 | lower_H: \n %s
54 | lower_H: \n 0.0
55 | lower_S: \n %s
56 | lower_S: \n 0.0
57 | lower_V: \n %s
58 | lower_V: \n 0.0
59 | GaussianBlur
60 | Threshold
61 | Canny
62 | opencvのロゴマークです
63 | 画像処理された画像を表示します
64 | Licence
65 | Vibration
66 | OpenCV LICENCE
67 | GrayScale
68 | RGBExtraction
69 | HSVExtraction
70 | Erode
71 | Dilate
72 | https://github.com/momomomo111/camerax_opencv
73 | vibrationEnable
74 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 | xmlns:android
23 |
24 | ^$
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 | xmlns:.*
34 |
35 | ^$
36 |
37 |
38 | BY_NAME
39 |
40 |
41 |
42 |
43 |
44 |
45 | .*:id
46 |
47 | http://schemas.android.com/apk/res/android
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 | .*:name
57 |
58 | http://schemas.android.com/apk/res/android
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 | name
68 |
69 | ^$
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 | style
79 |
80 | ^$
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 | .*
90 |
91 | ^$
92 |
93 |
94 | BY_NAME
95 |
96 |
97 |
98 |
99 |
100 |
101 | .*
102 |
103 | http://schemas.android.com/apk/res/android
104 |
105 |
106 | ANDROID_ATTRIBUTE_ORDER
107 |
108 |
109 |
110 |
111 |
112 |
113 | .*
114 |
115 | .*
116 |
117 |
118 | BY_NAME
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_title.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
29 |
30 |
39 |
40 |
49 |
50 |
59 |
60 |
69 |
70 |
79 |
80 |
89 |
90 |
99 |
100 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/HsvExtractionFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.navArgs
10 | import com.momomomo111.camerax_opencv.R
11 | import com.momomomo111.camerax_opencv.data.HsvextractionViewModel
12 | import com.momomomo111.camerax_opencv.databinding.FragmentHsvextractionBinding
13 | import com.momomomo111.camerax_opencv.util.CameraUtil
14 | import com.momomomo111.camerax_opencv.util.ProcessImageAnalyzer
15 | import com.momomomo111.camerax_opencv.util.VibrationUtil
16 | import com.momomomo111.camerax_opencv.util.VibrationUtil.effectSlider
17 |
18 | class HsvExtractionFragment : Fragment() {
19 | private val hsvextractionViewModel: HsvextractionViewModel by viewModels()
20 | private val args: GaussianBlurFragmentArgs by navArgs()
21 |
22 | private var _binding: FragmentHsvextractionBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | override fun onCreateView(
26 | inflater: LayoutInflater,
27 | container: ViewGroup?,
28 | savedInstanceState: Bundle?
29 | ): View {
30 | _binding = FragmentHsvextractionBinding.inflate(inflater, container, false)
31 | return binding.root
32 | }
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 |
37 | val enableVibration = args.vibrationEnable
38 |
39 | CameraUtil.startCamera(
40 | requireContext(),
41 | ProcessImageAnalyzer(
42 | {
43 | runOnUiThread {
44 | _binding?.imageView?.setImageBitmap(
45 | it
46 | )
47 | }
48 | },
49 | hsvextractionViewModel.params
50 | )
51 | )
52 |
53 | val vibrator = VibrationUtil.setVibrator(this.context)
54 |
55 | val sliderH = _binding?.sliderH
56 | sliderH?.setValues(0.0F, 255.0F)
57 | sliderH?.addOnChangeListener { _, _, _ ->
58 | val values = sliderH.values
59 | val upperH = values[1].toDouble()
60 | val lowerH = values[0].toDouble()
61 | hsvextractionViewModel.onUpperHChange(upperH)
62 | hsvextractionViewModel.onLowerHChange(lowerH)
63 | binding.UpperHText.text = getString(R.string.upper_h, upperH.toString())
64 | binding.LowerHText.text = getString(R.string.lower_h, lowerH.toString())
65 | if (enableVibration) {
66 | vibrator.effectSlider()
67 | }
68 | }
69 |
70 | val sliderS = _binding?.sliderS
71 | sliderS?.setValues(0.0F, 255.0F)
72 | sliderS?.addOnChangeListener { _, _, _ ->
73 | val values = sliderS.values
74 | val upperS = values[1].toDouble()
75 | val lowerS = values[0].toDouble()
76 | hsvextractionViewModel.onUpperSChange(upperS)
77 | hsvextractionViewModel.onLowerSChange(lowerS)
78 | binding.UpperSText.text = getString(R.string.upper_s, upperS.toString())
79 | binding.LowerSText.text = getString(R.string.lower_s, lowerS.toString())
80 | if (enableVibration) {
81 | vibrator.effectSlider()
82 | }
83 | }
84 |
85 | val sliderV = _binding?.sliderV
86 | sliderV?.setValues(0.0F, 255.0F)
87 | sliderV?.addOnChangeListener { _, _, _ ->
88 | val values = sliderV.values
89 | val upperV = values[1].toDouble()
90 | val lowerV = values[0].toDouble()
91 | hsvextractionViewModel.onUpperVChange(upperV)
92 | hsvextractionViewModel.onLowerVChange(lowerV)
93 | binding.UpperVText.text = getString(R.string.upper_v, upperV.toString())
94 | binding.LowerVText.text = getString(R.string.lower_v, lowerV.toString())
95 | if (enableVibration) {
96 | vibrator.effectSlider()
97 | }
98 | }
99 | }
100 |
101 | override fun onDestroyView() {
102 | super.onDestroyView()
103 | _binding = null
104 | }
105 |
106 | private fun Fragment.runOnUiThread(action: () -> Unit) {
107 | if (!isAdded) return
108 | activity?.runOnUiThread(action)
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/RgbExtractionFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.View
6 | import android.view.ViewGroup
7 | import androidx.fragment.app.Fragment
8 | import androidx.fragment.app.viewModels
9 | import androidx.navigation.fragment.navArgs
10 | import com.momomomo111.camerax_opencv.R
11 | import com.momomomo111.camerax_opencv.data.RgbextractionViewModel
12 | import com.momomomo111.camerax_opencv.databinding.FragmentRgbextractionBinding
13 | import com.momomomo111.camerax_opencv.util.CameraUtil
14 | import com.momomomo111.camerax_opencv.util.ProcessImageAnalyzer
15 | import com.momomomo111.camerax_opencv.util.VibrationUtil
16 | import com.momomomo111.camerax_opencv.util.VibrationUtil.effectSlider
17 |
18 | class RgbExtractionFragment : Fragment() {
19 | private val rgbextractionViewModel: RgbextractionViewModel by viewModels()
20 | private val args: GaussianBlurFragmentArgs by navArgs()
21 |
22 | private var _binding: FragmentRgbextractionBinding? = null
23 | private val binding get() = _binding!!
24 |
25 | override fun onCreateView(
26 | inflater: LayoutInflater,
27 | container: ViewGroup?,
28 | savedInstanceState: Bundle?
29 | ): View {
30 | _binding = FragmentRgbextractionBinding.inflate(inflater, container, false)
31 | return binding.root
32 | }
33 |
34 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
35 | super.onViewCreated(view, savedInstanceState)
36 |
37 | val enableVibration = args.vibrationEnable
38 |
39 | CameraUtil.startCamera(
40 | requireContext(),
41 | ProcessImageAnalyzer(
42 | {
43 | runOnUiThread {
44 | _binding?.imageView?.setImageBitmap(
45 | it
46 | )
47 | }
48 | },
49 | rgbextractionViewModel.params
50 | )
51 | )
52 |
53 | val vibrator = VibrationUtil.setVibrator(this.context)
54 |
55 | val sliderR = _binding?.sliderR
56 | sliderR?.setValues(0.0F, 255.0F)
57 | sliderR?.addOnChangeListener { _, _, _ ->
58 | val values = sliderR.values
59 | val upperR = values[1].toDouble()
60 | val lowerR = values[0].toDouble()
61 | rgbextractionViewModel.onUpperRChange(upperR)
62 | rgbextractionViewModel.onLowerRChange(lowerR)
63 | binding.UpperRText.text = getString(R.string.upper_r, upperR.toString())
64 | binding.LowerRText.text = getString(R.string.lower_r, lowerR.toString())
65 | if (enableVibration) {
66 | vibrator.effectSlider()
67 | }
68 | }
69 |
70 | val sliderG = _binding?.sliderG
71 | sliderG?.setValues(0.0F, 255.0F)
72 | sliderG?.addOnChangeListener { _, _, _ ->
73 | val values = sliderG.values
74 | val upperG = values[1].toDouble()
75 | val lowerG = values[0].toDouble()
76 | rgbextractionViewModel.onUpperGChange(upperG)
77 | rgbextractionViewModel.onLowerGChange(lowerG)
78 | binding.UpperGText.text = getString(R.string.upper_g, upperG.toString())
79 | binding.LowerGText.text = getString(R.string.lower_g, lowerG.toString())
80 | if (enableVibration) {
81 | vibrator.effectSlider()
82 | }
83 | }
84 |
85 | val sliderB = _binding?.sliderB
86 | sliderB?.setValues(0.0F, 255.0F)
87 | sliderB?.addOnChangeListener { _, _, _ ->
88 | val values = sliderB.values
89 | val upperB = values[1].toDouble()
90 | val lowerB = values[0].toDouble()
91 | rgbextractionViewModel.onUpperBChange(upperB)
92 | rgbextractionViewModel.onLowerBChange(lowerB)
93 | binding.UpperBText.text = getString(R.string.upper_b, upperB.toString())
94 | binding.LowerBText.text = getString(R.string.lower_b, lowerB.toString())
95 | if (enableVibration) {
96 | vibrator.effectSlider()
97 | }
98 | }
99 | }
100 |
101 | override fun onDestroyView() {
102 | super.onDestroyView()
103 | _binding = null
104 | }
105 |
106 | private fun Fragment.runOnUiThread(action: () -> Unit) {
107 | if (!isAdded) return
108 | activity?.runOnUiThread(action)
109 | }
110 | }
111 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/util/CameraUtil.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.util
2 |
3 | import android.Manifest
4 | import android.app.Activity
5 | import android.content.Context
6 | import android.content.pm.PackageManager
7 | import android.util.Log
8 | import androidx.camera.core.CameraSelector
9 | import androidx.camera.core.ImageAnalysis
10 | import androidx.camera.core.ImageProxy
11 | import androidx.camera.lifecycle.ProcessCameraProvider
12 | import androidx.core.app.ActivityCompat
13 | import androidx.core.content.ContextCompat
14 | import androidx.lifecycle.LifecycleOwner
15 | import com.google.common.util.concurrent.ListenableFuture
16 | import org.opencv.core.Core
17 | import org.opencv.core.CvType
18 | import org.opencv.core.Mat
19 | import org.opencv.imgproc.Imgproc
20 | import java.nio.ByteBuffer
21 | import java.util.concurrent.Executors
22 |
23 | private val REQUIRED_PERMISSIONS = arrayOf(
24 | "android.permission.CAMERA",
25 | "android.permission.WRITE_EXTERNAL_STORAGE"
26 | )
27 |
28 | object CameraUtil {
29 | fun startCamera(
30 | context: Context,
31 | imageAnalyzer: ProcessImageAnalyzer
32 | ) {
33 | val cameraProviderFuture: ListenableFuture =
34 | ProcessCameraProvider.getInstance(context)
35 | cameraProviderFuture.addListener(
36 | {
37 | try {
38 | val cameraProvider: ProcessCameraProvider = cameraProviderFuture.get()
39 | val imageAnalysis = ImageAnalysis.Builder().build()
40 | imageAnalysis.setAnalyzer(Executors.newSingleThreadExecutor(), imageAnalyzer)
41 | val cameraSelector = CameraSelector.Builder()
42 | .requireLensFacing(CameraSelector.LENS_FACING_BACK).build()
43 | cameraProvider.unbindAll()
44 | cameraProvider.bindToLifecycle(
45 | (context as LifecycleOwner),
46 | cameraSelector,
47 | imageAnalysis
48 | )
49 | } catch (e: Exception) {
50 | Log.e("error", "[startCamera] Use case binding failed", e)
51 | }
52 | },
53 | ContextCompat.getMainExecutor(context)
54 | )
55 | }
56 |
57 | fun getMatFromImage(image: ImageProxy): Mat {
58 | val yBuffer: ByteBuffer = image.planes[0].buffer
59 | val uBuffer: ByteBuffer = image.planes[1].buffer
60 | val vBuffer: ByteBuffer = image.planes[2].buffer
61 | val ySize: Int = yBuffer.remaining()
62 | val uSize: Int = uBuffer.remaining()
63 | val vSize: Int = vBuffer.remaining()
64 | val nv21 = ByteArray(ySize + uSize + vSize)
65 | yBuffer.get(nv21, 0, ySize)
66 | vBuffer.get(nv21, ySize, vSize)
67 | uBuffer.get(nv21, ySize + vSize, uSize)
68 | val yuv = Mat(image.height + image.height / 2, image.width, CvType.CV_8UC1)
69 | yuv.put(0, 0, nv21)
70 | var mat = Mat()
71 | Imgproc.cvtColor(yuv, mat, Imgproc.COLOR_YUV2RGB_NV21, 3)
72 | mat = fixMatRotation(mat, image.imageInfo.rotationDegrees)
73 | return mat
74 | }
75 |
76 | private fun fixMatRotation(matOrg: Mat, rotationDegrees: Int): Mat {
77 | val mat: Mat
78 | when (rotationDegrees) {
79 | 0 -> {
80 | mat = matOrg
81 | }
82 | 90 -> {
83 | mat = Mat(matOrg.cols(), matOrg.rows(), matOrg.type())
84 | Core.transpose(matOrg, mat)
85 | Core.flip(mat, mat, 1)
86 | }
87 | 180 -> {
88 | mat = matOrg
89 | Core.flip(mat, mat, -1)
90 | }
91 | else -> {
92 | mat = matOrg
93 | }
94 | }
95 | return mat
96 | }
97 |
98 | fun checkPermissions(context: Context): Boolean {
99 | for (permission in REQUIRED_PERMISSIONS) {
100 | if (context.let {
101 | ContextCompat.checkSelfPermission(
102 | it,
103 | permission
104 | )
105 | } != PackageManager.PERMISSION_GRANTED
106 | ) {
107 | return false
108 | }
109 | }
110 | return true
111 | }
112 |
113 | fun userRequestPermissions(activity: Activity) {
114 | ActivityCompat.requestPermissions(
115 | activity,
116 | arrayOf(Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE),
117 | 2000
118 | )
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/app/src/main/res/navigation/navigation.xml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
11 |
14 |
17 |
20 |
23 |
26 |
29 |
32 |
35 |
38 |
39 |
43 |
47 |
48 |
52 |
56 |
57 |
61 |
65 |
66 |
70 |
74 |
75 |
79 |
83 |
87 |
88 |
92 |
96 |
97 |
101 |
105 |
106 |
110 |
114 |
115 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_hsvextraction.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
39 |
40 |
50 |
51 |
61 |
62 |
71 |
72 |
82 |
83 |
93 |
94 |
104 |
105 |
115 |
116 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_rgbextraction.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
18 |
19 |
29 |
30 |
39 |
40 |
50 |
51 |
61 |
62 |
71 |
72 |
82 |
83 |
84 |
94 |
95 |
105 |
106 |
116 |
117 |
--------------------------------------------------------------------------------
/app/src/main/java/com/momomomo111/camerax_opencv/ui/TitleFragment.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv.ui
2 |
3 | import android.os.Bundle
4 | import android.view.LayoutInflater
5 | import android.view.Menu
6 | import android.view.MenuInflater
7 | import android.view.MenuItem
8 | import android.view.View
9 | import android.view.ViewGroup
10 | import androidx.core.view.MenuHost
11 | import androidx.core.view.MenuProvider
12 | import androidx.fragment.app.Fragment
13 | import androidx.fragment.app.activityViewModels
14 | import androidx.lifecycle.Lifecycle
15 | import androidx.lifecycle.lifecycleScope
16 | import androidx.lifecycle.repeatOnLifecycle
17 | import androidx.navigation.findNavController
18 | import androidx.navigation.ui.NavigationUI
19 | import com.momomomo111.camerax_opencv.R
20 | import com.momomomo111.camerax_opencv.data.SettingsUiState
21 | import com.momomomo111.camerax_opencv.data.SettingsViewModel
22 | import com.momomomo111.camerax_opencv.databinding.FragmentTitleBinding
23 | import com.momomomo111.camerax_opencv.util.CameraUtil
24 | import kotlinx.coroutines.launch
25 |
26 | class TitleFragment : Fragment() {
27 | private val settingsViewModel: SettingsViewModel by activityViewModels()
28 |
29 | private var _binding: FragmentTitleBinding? = null
30 | private val binding get() = _binding!!
31 | private var isChecked = true
32 |
33 | override fun onCreateView(
34 | inflater: LayoutInflater,
35 | container: ViewGroup?,
36 | savedInstanceState: Bundle?
37 | ): View {
38 | _binding = FragmentTitleBinding.inflate(inflater, container, false)
39 | binding.gaussianBlurButton.setOnClickListener { view: View ->
40 | view.findNavController().navigate(
41 | TitleFragmentDirections.actionTitleFragmentToGaussianBlurFragment(isChecked)
42 | )
43 | }
44 | binding.thresholdButton.setOnClickListener { view: View ->
45 | view.findNavController()
46 | .navigate(TitleFragmentDirections.actionTitleFragmentToThresholdFragment(isChecked))
47 | }
48 | binding.cannyButton.setOnClickListener { view: View ->
49 | view.findNavController()
50 | .navigate(TitleFragmentDirections.actionTitleFragmentToCannyFragment(isChecked))
51 | }
52 | binding.grayScaleButton.setOnClickListener { view: View ->
53 | view.findNavController().navigate(R.id.action_titleFragment_to_grayScaleFragment)
54 | }
55 | binding.rgbExtractionButton.setOnClickListener { view: View ->
56 | view.findNavController().navigate(
57 | TitleFragmentDirections.actionTitleFragmentToRgbExtractionFragment(isChecked)
58 | )
59 | }
60 | binding.hsvExtractionButton.setOnClickListener { view: View ->
61 | view.findNavController()
62 | .navigate(
63 | TitleFragmentDirections.actionTitleFragmentToHsvExtractionFragment(isChecked)
64 | )
65 | }
66 | binding.erodeButton.setOnClickListener { view: View ->
67 | view.findNavController()
68 | .navigate(TitleFragmentDirections.actionTitleFragmentToErodeFragment(isChecked))
69 | }
70 | binding.dilateButton.setOnClickListener { view: View ->
71 | view.findNavController()
72 | .navigate(TitleFragmentDirections.actionTitleFragmentToDilateFragment(isChecked))
73 | }
74 | if (!CameraUtil.checkPermissions(requireContext())) {
75 | CameraUtil.userRequestPermissions(requireActivity())
76 | }
77 | return binding.root
78 | }
79 |
80 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
81 | super.onViewCreated(view, savedInstanceState)
82 | val menuHost: MenuHost = requireActivity()
83 |
84 | menuHost.addMenuProvider(
85 | object : MenuProvider {
86 | override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
87 | menuInflater.inflate(R.menu.options_menu, menu)
88 | }
89 |
90 | override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
91 | return when (menuItem.itemId) {
92 | R.id.licenceFragment -> {
93 | NavigationUI.onNavDestinationSelected(
94 | menuItem,
95 | requireView().findNavController()
96 | )
97 | }
98 | else -> false
99 | }
100 | }
101 | },
102 | viewLifecycleOwner, Lifecycle.State.RESUMED
103 | )
104 |
105 | viewLifecycleOwner.lifecycleScope.launch {
106 | viewLifecycleOwner.repeatOnLifecycle(Lifecycle.State.STARTED) {
107 | settingsViewModel.settingsUiState.collect {
108 | isChecked = when (it) {
109 | is SettingsUiState.Success -> {
110 | it.vibration
111 | }
112 | is SettingsUiState.None -> {
113 | false
114 | }
115 | }
116 | }
117 | }
118 | }
119 | }
120 |
121 | override fun onDestroyView() {
122 | super.onDestroyView()
123 | _binding = null
124 | }
125 | }
126 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_opencv_foreground.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
13 |
16 |
19 |
23 |
27 |
31 |
35 |
39 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-night/ic_opencv_foreground.xml:
--------------------------------------------------------------------------------
1 |
6 |
10 |
13 |
16 |
19 |
23 |
27 |
31 |
35 |
39 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/momomomo111/camerax_opencv/CameraPreviewTest.kt:
--------------------------------------------------------------------------------
1 | package com.momomomo111.camerax_opencv
2 |
3 | import android.Manifest
4 | import android.content.Context
5 | import android.graphics.ImageFormat
6 | import android.media.ImageReader
7 | import android.os.Handler
8 | import android.os.HandlerThread
9 | import android.util.Log
10 | import android.util.Size
11 | import android.view.Surface
12 | import androidx.camera.core.CameraSelector
13 | import androidx.camera.core.Preview
14 | import androidx.camera.core.SurfaceRequest
15 | import androidx.camera.lifecycle.ProcessCameraProvider
16 | import androidx.core.util.Consumer
17 | import androidx.lifecycle.Lifecycle
18 | import androidx.lifecycle.LifecycleOwner
19 | import androidx.lifecycle.LifecycleRegistry
20 | import androidx.test.annotation.UiThreadTest
21 | import androidx.test.core.app.ApplicationProvider
22 | import androidx.test.ext.junit.runners.AndroidJUnit4
23 | import androidx.test.rule.GrantPermissionRule
24 | import org.junit.After
25 | import org.junit.Assert
26 | import org.junit.Before
27 | import org.junit.Rule
28 | import org.junit.Test
29 | import org.junit.runner.RunWith
30 | import java.util.concurrent.Executors
31 | import java.util.concurrent.atomic.AtomicInteger
32 |
33 | /**
34 | * @see "https://developer.android.com/training/camerax/architecture.combine-use-cases"
35 | */
36 |
37 | @RunWith(AndroidJUnit4::class)
38 | class CameraPreviewTest : LifecycleOwner, ImageReader.OnImageAvailableListener,
39 | Consumer {
40 |
41 | @get:Rule
42 | val cameraAccess: GrantPermissionRule = GrantPermissionRule.grant(Manifest.permission.CAMERA)
43 |
44 | private var registry: LifecycleRegistry = LifecycleRegistry(this)
45 | private val thread = HandlerThread("CameraPreviewTest").also { it.start() }
46 | private var executor = Executors.newSingleThreadExecutor()
47 | private var provider: ProcessCameraProvider? = null // requires main thread
48 |
49 | /**
50 | * @implNote We can't use the main executor since it is reserved for the test framework.
51 | */
52 | @Before
53 | fun setup() {
54 | val context: Context = ApplicationProvider.getApplicationContext()
55 | Assert.assertNotNull(context)
56 | provider = ProcessCameraProvider.getInstance(context).get()
57 | Assert.assertNotNull(provider)
58 | }
59 |
60 | @UiThreadTest
61 | @After
62 | fun teardown() {
63 | provider?.unbindAll()
64 | executor?.shutdown()
65 | }
66 |
67 | /**
68 | * @implNote In checkPreviewUseCase, ImageReader will provide a Surface for camera preview test.
69 | * When each ImageProxy is acquired, the AtomicInteger will be incremented.
70 | * By doing so we can ensure the camera binding is working as expected.
71 | */
72 | private val reader = ImageReader.newInstance(1920, 1080, ImageFormat.YUV_420_888, 30)
73 | private val count = AtomicInteger(0)
74 |
75 | @Before
76 | fun setupImageReader() {
77 | reader.setOnImageAvailableListener(this, Handler(thread.looper))
78 | }
79 |
80 | @After
81 | fun teardownImageReader() {
82 | reader.close()
83 | thread.quit()
84 | }
85 |
86 | override fun onImageAvailable(reader: ImageReader) {
87 | reader.acquireNextImage().use { image ->
88 | val imageNumber = count.getAndIncrement()
89 | Log.i("CameraPreviewTest", String.format("image: %d %s", imageNumber, image))
90 | }
91 | }
92 |
93 | /**
94 | * @see ProcessCameraProvider.bindToLifecycle
95 | */
96 | override val lifecycle: Lifecycle
97 | get() = registry
98 |
99 | @Before
100 | @UiThreadTest
101 | fun markCreated() {
102 | registry.also {
103 | it.currentState = Lifecycle.State.INITIALIZED
104 | it.currentState = Lifecycle.State.CREATED
105 | }
106 | }
107 |
108 | @After
109 | @UiThreadTest
110 | fun markDestroyed() {
111 | registry.currentState = Lifecycle.State.DESTROYED
112 | }
113 |
114 | /**
115 | * @see SurfaceRequest.provideSurface
116 | */
117 | override fun accept(result: SurfaceRequest.Result) {
118 | when (result.resultCode) {
119 | SurfaceRequest.Result.RESULT_SURFACE_USED_SUCCESSFULLY -> {
120 | Log.i("CameraPreviewTest", result.toString())
121 | }
122 | SurfaceRequest.Result.RESULT_REQUEST_CANCELLED, SurfaceRequest.Result.RESULT_INVALID_SURFACE, SurfaceRequest.Result.RESULT_SURFACE_ALREADY_PROVIDED, SurfaceRequest.Result.RESULT_WILL_NOT_PROVIDE_SURFACE -> {
123 | Log.e("CameraPreviewTest", result.toString())
124 | }
125 | }
126 | }
127 |
128 |
129 | @UiThreadTest
130 | @Test
131 | fun checkPreviewUseCase() {
132 | // life cycle owner
133 | registry.currentState = Lifecycle.State.STARTED
134 |
135 | // select Back camera
136 | val selectorBuilder = CameraSelector.Builder()
137 | Assert.assertTrue(provider!!.hasCamera(CameraSelector.DEFAULT_BACK_CAMERA))
138 | selectorBuilder.requireLensFacing(CameraSelector.LENS_FACING_BACK)
139 |
140 | // fit the preview size to ImageReader
141 | val previewBuilder = Preview.Builder()
142 | previewBuilder.setTargetResolution(Size(reader.width, reader.height))
143 | previewBuilder.setTargetRotation(Surface.ROTATION_90)
144 | val preview = previewBuilder.build()
145 |
146 | // acquire camera binding
147 | provider!!.unbindAll()
148 | val camera = provider!!.bindToLifecycle(this, selectorBuilder.build(), preview)
149 | Assert.assertNotNull(camera)
150 | preview.setSurfaceProvider(executor!!) { request: SurfaceRequest ->
151 | val surface = reader.surface
152 | Log.i("CameraPreviewTest", String.format("providing: %s", surface))
153 | request.provideSurface(surface, executor!!, this)
154 | }
155 |
156 | // wait until onImageAvailable is invoked. retry several times
157 | for (repeat in 5 downTo 0) {
158 | Thread.sleep(600)
159 | val value = count.get()
160 | Log.i("CameraPreviewTest", String.format("count: %d", value))
161 | if (value > 0) return
162 | }
163 | Assert.assertNotEquals(0, count.get().toLong())
164 | }
165 | }
166 |
--------------------------------------------------------------------------------