commit 3e5a8772d7c63e4cd77113e9f7a6fccaa8743fcd Author: SaiD Date: Tue Nov 25 20:35:23 2025 +0530 Animal Rating diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/AndroidProjectSystem.xml b/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b86273d --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..cca7557 --- /dev/null +++ b/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/deviceManager.xml b/.idea/deviceManager.xml new file mode 100644 index 0000000..91f9558 --- /dev/null +++ b/.idea/deviceManager.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..639c779 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/migrations.xml b/.idea/migrations.xml new file mode 100644 index 0000000..f8051a6 --- /dev/null +++ b/.idea/migrations.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..b2c751a --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/.idea/studiobot.xml b/.idea/studiobot.xml new file mode 100644 index 0000000..539e3b8 --- /dev/null +++ b/.idea/studiobot.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts new file mode 100644 index 0000000..25b8a5e --- /dev/null +++ b/app/build.gradle.kts @@ -0,0 +1,74 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.compose) +} + +android { + namespace = "com.example.animalrating" + compileSdk { + version = release(36) + } + + defaultConfig { + applicationId = "com.example.animalrating" + minSdk = 24 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } + buildFeatures { + compose = true + } +} + +dependencies { + val cameraxVersion = "1.5.1" + implementation("androidx.appcompat:appcompat:1.7.0") + implementation("androidx.cardview:cardview:1.0.0") + implementation("androidx.camera:camera-core:$cameraxVersion") + implementation("androidx.camera:camera-camera2:$cameraxVersion") + implementation("androidx.camera:camera-lifecycle:$cameraxVersion") + implementation("androidx.camera:camera-view:$cameraxVersion") + implementation("androidx.camera:camera-mlkit-vision:$cameraxVersion") + + // ML Kit Object Detection + implementation("com.google.mlkit:object-detection:17.0.2") + // ML Kit Subject Segmentation (Google Play Services version) + implementation("com.google.android.gms:play-services-mlkit-subject-segmentation:16.0.0-beta1") + + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.compose.ui) + implementation(libs.androidx.compose.ui.graphics) + implementation(libs.androidx.compose.ui.tooling.preview) + implementation(libs.androidx.compose.material3) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.compose.ui.test.junit4) + debugImplementation(libs.androidx.compose.ui.tooling) + debugImplementation(libs.androidx.compose.ui.test.manifest) +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/example/animalrating/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/example/animalrating/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..9100cbf --- /dev/null +++ b/app/src/androidTest/java/com/example/animalrating/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.example.animalrating + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.example.animalrating", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9987565 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/animalrating/CameraProcessor.kt b/app/src/main/java/com/example/animalrating/CameraProcessor.kt new file mode 100644 index 0000000..fd57a73 --- /dev/null +++ b/app/src/main/java/com/example/animalrating/CameraProcessor.kt @@ -0,0 +1,301 @@ +package com.example.animalrating + +import android.Manifest +import android.content.pm.ActivityInfo +import android.graphics.Bitmap +import android.graphics.BitmapFactory +import android.graphics.Color +import android.graphics.Matrix +import android.os.Bundle +import android.util.Log +import android.widget.Button +import android.widget.ImageView +import android.widget.Toast +import androidx.activity.result.contract.ActivityResultContracts +import androidx.appcompat.app.AppCompatActivity +import androidx.camera.core.ImageAnalysis +import androidx.camera.core.ImageCapture +import androidx.camera.core.ImageCaptureException +import androidx.camera.core.ImageProxy +import androidx.camera.lifecycle.ProcessCameraProvider +import androidx.camera.view.PreviewView +import androidx.core.content.ContextCompat +import com.example.animalrating.ml.CowAnalyzer +import com.example.animalrating.ui.SilhouetteOverlay +import java.io.File +import java.io.FileOutputStream +import java.util.concurrent.Executors + +class CameraProcessor : AppCompatActivity(), CowAnalyzer.CowListener { + + private lateinit var previewView: PreviewView + private lateinit var overlay: SilhouetteOverlay + private lateinit var segmentationOverlay: ImageView + private lateinit var savedMaskOverlay: ImageView + private var imageCapture: ImageCapture? = null + private lateinit var frameProcessor: FrameProcessor + + private val cameraExecutor = Executors.newSingleThreadExecutor() + + private var cowName: String? = null + private var orientation: String? = null + private var currentMask: Bitmap? = null + private var savedMaskBitmap: Bitmap? = null + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + cowName = intent.getStringExtra("COW_NAME") + orientation = intent.getStringExtra("ORIENTATION") + + // Set orientation based on selected view + if (orientation == "front" || orientation == "back") { + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + } else { + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE + } + + previewView = findViewById(R.id.cameraPreview) + overlay = findViewById(R.id.silhouetteOverlay) + segmentationOverlay = findViewById(R.id.segmentationOverlay) + savedMaskOverlay = findViewById(R.id.savedMaskOverlay) + + frameProcessor = FrameProcessor { maskBitmap -> + runOnUiThread { + if (maskBitmap != null && (orientation == "front" || orientation == "back")) { + try { + val matrix = Matrix() + matrix.postRotate(90f) + val rotatedBitmap = Bitmap.createBitmap( + maskBitmap, 0, 0, maskBitmap.width, maskBitmap.height, matrix, true + ) + currentMask = rotatedBitmap + segmentationOverlay.setImageBitmap(rotatedBitmap) + } catch (e: Exception) { + Log.e("CameraProcessor", "Error rotating mask", e) + currentMask = maskBitmap + segmentationOverlay.setImageBitmap(maskBitmap) + } + } else { + currentMask = maskBitmap + segmentationOverlay.setImageBitmap(maskBitmap) + } + } + } + + val btnSave = findViewById