Skip to content

Commit

Permalink
1
Browse files Browse the repository at this point in the history
  • Loading branch information
Knightwood committed Jun 28, 2024
1 parent 1fc873a commit 430bc8f
Show file tree
Hide file tree
Showing 37 changed files with 530 additions and 324 deletions.
446 changes: 253 additions & 193 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
//设置支持的SO库架构(开发者可以根据需要,选择一个或多个平台的so)
// abiFilters += listOf("armeabi", "armeabi-v7a", "arm64-v8a")
//noinspection ChromeOsAbiSupport
abiFilters += listOf("armeabi-v7a")
abiFilters += rootProject.ext["abi"] as List<String>
}
}

Expand Down Expand Up @@ -58,7 +58,7 @@ dependencies {
implementation ("com.google.android.material:material:1.9.0")
implementation ("androidx.constraintlayout:constraintlayout:2.1.4")
implementation(project(":camerax_lib"))
implementation(project(":camerax_analyzer"))
implementation(project(":camerax_analyzer_mlkit"))
implementation(project(":camerax_analyzer_tensorflow"))
implementation ("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.Intent
import android.util.Log
import android.util.Size
import com.google.mlkit.vision.face.Face
import com.kiylx.camera.camerax_analyzer.face.FaceContourDetectionProcessor
import com.kiylx.camera.camerax_analyzer_mlkit.face.FaceContourDetectionProcessor
import com.kiylx.camerax_lib.R
import com.kiylx.camerax_lib.main.manager.CameraHolder
import com.kiylx.camerax_lib.main.manager.analyer.base.AnalyzeResultListener
Expand All @@ -17,14 +17,17 @@ import com.kiylx.camerax_lib.main.store.ImageCaptureConfig
import com.kiylx.camerax_lib.main.store.SaveFileData
import com.kiylx.camerax_lib.main.store.VideoRecordConfig
import com.kiylx.camerax_lib.main.ui.BaseCameraXActivity
import com.kiylx.camerax_lib.view.ControllerPanelUseCaseMode
import com.kiylx.cameraxexample.graphic2.BitmapProcessor
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flow

class CameraExampleActivity : BaseCameraXActivity() {


/** 这里直接构建了配置,我没有使用intent传入配置。 */
/**
* 这里直接构建了配置,我没有使用intent传入配置。
*/
override fun configAll(intent: Intent): ManagerConfig {
val useImageDetection = intent.getBooleanExtra(ImageDetection, false)
//视频录制配置(可选)
Expand All @@ -40,7 +43,7 @@ class CameraExampleActivity : BaseCameraXActivity() {
return ManagerConfig().apply {
this.recordConfig = videoRecordConfig
//这里指定了用例组合,当然你也可以调用UseCaseMode.customGroup方法自定义用例组合
this.useCaseBundle =
this.useCaseMode =
if (useImageDetection) UseCaseMode.imageAnalysis else UseCaseMode.takePhoto
this.flashMode = FlashModel.CAMERA_FLASH_AUTO
//android R以下时,在少数display为null的情况下,设置预览,拍照的默认分辨率
Expand All @@ -57,6 +60,7 @@ class CameraExampleActivity : BaseCameraXActivity() {
}, 500)
}
}

lateinit var analyzer: FaceContourDetectionProcessor
override fun cameraHolderInitStart(cameraHolder: CameraHolder) {
super.cameraHolderInitStart(cameraHolder)
Expand Down Expand Up @@ -105,19 +109,29 @@ class CameraExampleActivity : BaseCameraXActivity() {
override fun cameraHolderInitFinish(cameraHolder: CameraHolder) {
super.cameraHolderInitFinish(cameraHolder)
if (cameraConfig.isUsingImageAnalyzer()) {//使用了图像分析
if (cameraConfig.isUsingVideoRecorder()) {
controllerPanel.switchBetweenCaptureAndRecord(ControllerPanelUseCaseMode.recordVideo)
} else {
if (!cameraConfig.isUsingImageCapture()) {
controllerPanel.showHideControllerButton(true)
}
}
controllerPanel.showHideUseCaseSwitch(true)
controllerPanel.showHideControllerButton(true)
}
}

/** 拍完照片 */
/**
* 拍完照片
*/
override fun onPhotoTaken(saveFileData: SaveFileData?) {
super.onPhotoTaken(saveFileData)
Log.d("CameraXFragment", "onPhotoTaken: $saveFileData")
cameraXF.indicateTakePhoto()//拍照闪光
}

/** 录完视频 */
/**
* 录完视频
*/
override fun onVideoRecorded(saveFileData: SaveFileData?) {
super.onVideoRecorded(saveFileData)
saveFileData?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CameraExampleActivity2 : AppCompatActivity(), CameraXFragmentEventListener
//整体的配置
return ManagerConfig().apply {
this.recordConfig = videoRecordConfig
this.useCaseBundle =
this.useCaseMode =
if (useImageDetection) UseCaseMode.imageAnalysis else UseCaseMode.takePhoto
this.flashMode = FlashModel.CAMERA_FLASH_AUTO
this.size = Size(1920, 1080)//拍照,预览的分辨率,期望值,不一定会用这个值
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/com/kiylx/cameraxexample/TestFileDecActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package com.kiylx.cameraxexample
import android.os.Bundle
import android.widget.Button
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.updatePadding
import com.kiylx.camera.camerax_analyzer.filevision.MyFileProcessor
import com.kiylx.camera.camerax_analyzer_mlkit.filevision.MyFileProcessor
import com.kiylx.camera.camerax_analyzer_tensorflow.facedetection.FaceDetection
import com.kiylx.camerax_lib.main.manager.util.setWindowEdgeToEdge
import com.kiylx.camerax_lib.main.manager.util.statusBarTheme
Expand All @@ -14,21 +15,21 @@ import com.kiylx.store_lib.StoreX

class TestFileDecActivity : AppCompatActivity() {
private lateinit var model: FaceDetection
private lateinit var page :ActivityTestFileDecBinding
private lateinit var page: ActivityTestFileDecBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
page= ActivityTestFileDecBinding.inflate(layoutInflater)
page = ActivityTestFileDecBinding.inflate(layoutInflater)
setContentView(page.root)
setWindowEdgeToEdge{
page.root.updatePadding(top=it.top,bottom=it.bottom)
setWindowEdgeToEdge {
page.root.updatePadding(top = it.top, bottom = it.bottom)
}
statusBarTheme(true)

findViewById<Button>(R.id.select).setOnClickListener {
selectFileShow()
}
model= FaceDetection.create(
model = FaceDetection.create(
this.assets,
TF_OD_API_MODEL_FILE,
TF_OD_API_LABELS_FILE,
Expand All @@ -45,9 +46,13 @@ class TestFileDecActivity : AppCompatActivity() {
//处理bitmap,获取面部特征点
it?.let { it1 ->
//将bitmap转换成特定尺寸bitmap
val tmp = com.kiylx.camera.camerax_analyzer_tensorflow.facedetection.FaceDetection.convertBitmap(it1)
val tmp =
FaceDetection.convertBitmap(
it1
)
//获取特征点
val masks = model.detectionBitmap(tmp)
page.tvMasks.setText("特征点:\n" + masks.joinToString(), TextView.BufferType.NORMAL)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.graphics.Bitmap
import android.view.View
import com.google.android.gms.tasks.OnSuccessListener
import com.google.mlkit.vision.face.Face
import com.kiylx.camera.camerax_analyzer.filevision.FileVisionProcessor
import com.kiylx.camera.camerax_analyzer_mlkit.filevision.FileVisionProcessor
import com.kiylx.camerax_lib.main.manager.analyer.base.AnalyzeResultListener
import com.kiylx.camerax_lib.main.manager.analyer.graphic_view.GraphicOverlayView
import kotlinx.coroutines.Dispatchers
Expand Down
40 changes: 26 additions & 14 deletions app/src/main/res/layout/activity_test_file_dec.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".TestFileDecActivity">

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/backgrounds/scenic" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<Button
android:id="@+id/select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:text="选择图像文件" />
</LinearLayout>
<ImageView
android:id="@+id/imageView"
android:layout_width="300dp"
android:layout_height="300dp"
tools:srcCompat="@tools:sample/backgrounds/scenic" />

<Button
android:id="@+id/select"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|bottom"
android:text="选择图像文件" />

<TextView
android:id="@+id/tv_masks"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>


</androidx.core.widget.NestedScrollView>
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ plugins {
}

ext {
this["version"] = "1.2.0"
this["version"] = "1.3.1"
this["abi"] = listOf("arm64-v8a") //listOf("armeabi", "armeabi-v7a", "arm64-v8a")
}
40 changes: 0 additions & 40 deletions camerax_analyzer/build.gradle.kts

This file was deleted.

File renamed without changes.
70 changes: 70 additions & 0 deletions camerax_analyzer_mlkit/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
plugins {
id("com.android.library")
id("org.jetbrains.kotlin.android")
id("maven-publish")

}

android {
namespace = "com.kiylx.camera.camerax_analyzer_mlkit"
compileSdk = 34

defaultConfig {
minSdk = 23
consumerProguardFiles("consumer-rules.pro")

ndk {
//设置支持的SO库架构(开发者可以根据需要,选择一个或多个平台的so)
// abiFilters += listOf("armeabi", "armeabi-v7a", "arm64-v8a")
//noinspection ChromeOsAbiSupport
abiFilters += rootProject.ext["abi"] as List<String>
}
}

buildTypes {
release {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = "1.8"
}
publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}

dependencies {
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.10.0")
api("com.google.mlkit:face-detection:16.1.5")
compileOnly(project(":camerax_lib"))

}

afterEvaluate {
publishing {
publications {
create<MavenPublication>("release") {
groupId = "com.github.Knightwood"
artifactId = "camerax_analyzer_mlkit"
version = rootProject.ext["version"].toString()
afterEvaluate {
from(components["release"])
}
}
}
}
}
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kiylx.camera.camerax_analyzer
package com.kiylx.camera.camerax_analyzer_mlkit

import android.annotation.SuppressLint
import android.graphics.Matrix
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kiylx.camera.camerax_analyzer.bitmap
package com.kiylx.camera.camerax_analyzer_mlkit.bitmap

import android.graphics.Bitmap
import android.text.TextUtils
Expand All @@ -10,8 +10,6 @@ import kotlinx.coroutines.withContext
import java.io.File
import java.io.FileOutputStream
import java.io.IOException
import java.text.SimpleDateFormat
import java.util.*


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.kiylx.camera.camerax_analyzer.bitmap;
package com.kiylx.camera.camerax_analyzer_mlkit.bitmap;

import android.content.ContentResolver;
import android.graphics.Bitmap;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package com.kiylx.camera.camerax_analyzer.bitmap;
package com.kiylx.camera.camerax_analyzer_mlkit.bitmap;

/** Describing a frame info. */
public class FrameMetadata {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.kiylx.camera.camerax_analyzer.bitmap
package com.kiylx.camera.camerax_analyzer_mlkit.bitmap

import android.annotation.SuppressLint
import android.content.Context
Expand Down
Loading

0 comments on commit 430bc8f

Please sign in to comment.