Skip to content

Commit

Permalink
Merge pull request #18 from regulaforensics/release-6.2
Browse files Browse the repository at this point in the history
Release 6.2
  • Loading branch information
DzmitrySmaliakou authored Jun 7, 2024
2 parents 690e3be + 07dac1d commit 2bc2a4b
Show file tree
Hide file tree
Showing 22 changed files with 345 additions and 95 deletions.
9 changes: 2 additions & 7 deletions CertificatePinningSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,6 @@ android {
buildFeatures {
viewBinding true
}

//Required to add
aaptOptions {
noCompress "Regula/faceSdkResource.dat"
}
}

dependencies {
Expand All @@ -39,9 +34,9 @@ dependencies {
implementation "androidx.core:core-ktx:1.7.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation ('com.regula.face:api:6.1.+@aar'){
implementation ('com.regula.face:api:6.2.+@aar'){
transitive = true
}

implementation ('com.regula.face.core:basic:6.1.+@aar')
implementation ('com.regula.face.core:basic:6.2.+@aar')
}
9 changes: 2 additions & 7 deletions FaceSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

//Required to add
aaptOptions {
noCompress "Regula/faceSdkResource.dat"
}
}

dependencies {
Expand All @@ -39,9 +34,9 @@ dependencies {

implementation "androidx.recyclerview:recyclerview:1.2.1"

implementation ('com.regula.face:api:6.1.+@aar'){
implementation ('com.regula.face:api:6.2.+@aar'){
transitive = true
}

implementation ('com.regula.face.core:basic:6.1.+@aar')
implementation ('com.regula.face.core:basic:6.2.+@aar')
}
9 changes: 2 additions & 7 deletions FaceSampleKotlin/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ android {
buildFeatures {
viewBinding true
}

//Required to add
aaptOptions {
noCompress "Regula/faceSdkResource.dat"
}
}

dependencies {
Expand All @@ -45,9 +40,9 @@ dependencies {
implementation "androidx.core:core-ktx:1.7.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

implementation ('com.regula.face:api:6.1.+@aar'){
implementation ('com.regula.face:api:6.2.+@aar'){
transitive = true
}

implementation ('com.regula.face.core:basic:6.1.+@aar')
implementation ('com.regula.face.core:basic:6.2.+@aar')
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class CategoryDataProvider {
LivenessScreenConfigurationItem(),
FaceCaptureConfigurationItem(),

LivenessNotificationItem(),
HideCloseButtonItem(),
HideFlashButtonItem(),
HideNotificationViewItem(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.regula.facesamplekotlin

import android.Manifest
import android.app.Activity
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.*
import android.graphics.drawable.BitmapDrawable
import android.os.Bundle
Expand All @@ -15,9 +17,11 @@ import android.view.ViewGroup
import android.widget.Button
import android.widget.ImageView
import android.widget.PopupMenu
import android.widget.Toast
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.fragment.app.DialogFragment
import com.regula.facesamplekotlin.databinding.ActivityDetectFacesBinding
import com.regula.facesamplekotlin.util.RandomColors
Expand Down Expand Up @@ -45,6 +49,7 @@ class DetectFacesActivity : AppCompatActivity() {
private lateinit var scenario: Scenario
private lateinit var response: DetectFacesResponse
private lateinit var bitmapToDetect: Bitmap
private lateinit var externalBitmap: Bitmap

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -54,10 +59,27 @@ class DetectFacesActivity : AppCompatActivity() {

setImage(R.drawable.detect_face1)
binding.imageViewMain.setOnClickListener { showMenu(binding.imageViewMain) }
binding.imageViewSample1.setOnClickListener { setImage(R.drawable.detect_face1) }
binding.imageViewSample2.setOnClickListener { setImage(R.drawable.detect_face2) }
binding.imageViewSample3.setOnClickListener { setImage(R.drawable.detect_face3) }
binding.imageViewSample4.setOnClickListener { setImage(R.drawable.detect_face4) }
binding.imageViewSample1.setOnClickListener {
setImage(R.drawable.detect_face1)
binding.imageViewBackground1.setBackgroundColor(Color.BLUE)
}
binding.imageViewSample2.setOnClickListener {
setImage(R.drawable.detect_face2)
binding.imageViewBackground2.setBackgroundColor(Color.BLUE)
}
binding.imageViewSample3.setOnClickListener {
setImage(R.drawable.detect_face3)
binding.imageViewBackground3.setBackgroundColor(Color.BLUE)
}
binding.imageViewSample4.setOnClickListener {
setImage(R.drawable.detect_face4)
binding.imageViewBackground4.setBackgroundColor(Color.BLUE)
}
binding.imageViewSample5.setOnClickListener {
setImage(externalBitmap)
}

binding.imageViewBackground1.setBackgroundColor(Color.BLUE)

binding.button1.setOnClickListener { updateScenario(Scenario.CROP_CENTER, it) }
binding.button2.setOnClickListener { updateScenario(Scenario.CROP_ALL, it) }
Expand All @@ -79,15 +101,22 @@ class DetectFacesActivity : AppCompatActivity() {
}

private fun setImage(res: Int) {
clearImageBackground()
val option = BitmapFactory.Options()
option.inScaled = false
val bitmap = BitmapFactory.decodeResource(resources, res, option)
setImage(bitmap)
bitmapToDetect = bitmap;
binding.imageViewMain.setImageBitmap(bitmapToDetect);
}

private fun setImage(bitmap: Bitmap) {
bitmapToDetect = bitmap;
binding.imageViewMain.setImageBitmap(bitmapToDetect);
clearImageBackground()
bitmapToDetect = bitmap
externalBitmap = bitmap
binding.imageViewMain.setImageBitmap(bitmapToDetect)
binding.imageViewSample5.setImageBitmap(bitmapToDetect)
binding.imageViewBackground5.visibility = View.VISIBLE
binding.imageViewBackground5.setBackgroundColor(Color.BLUE)
}

private fun updateScenario(scenario: Scenario, view: View) {
Expand Down Expand Up @@ -240,7 +269,40 @@ class DetectFacesActivity : AppCompatActivity() {
}
}


private val requestPermissionLauncher =
registerForActivityResult(
ActivityResultContracts.RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
launchCamera()
} else {
Toast.makeText(
this@DetectFacesActivity,
"Camera permission denied",
Toast.LENGTH_SHORT
).show()
}
}

private fun openDefaultCamera() {
when {
ContextCompat.checkSelfPermission(
this@DetectFacesActivity,
Manifest.permission.CAMERA
) == PackageManager.PERMISSION_GRANTED -> {
launchCamera()
}

else -> {
requestPermissionLauncher.launch(
Manifest.permission.CAMERA
)
}
}
}

private fun launchCamera() {
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startCameraForResult.launch(cameraIntent)
}
Expand All @@ -267,6 +329,13 @@ class DetectFacesActivity : AppCompatActivity() {
}
}

private fun clearImageBackground() {
binding.imageViewBackground1.setBackgroundColor(0)
binding.imageViewBackground2.setBackgroundColor(0)
binding.imageViewBackground3.setBackgroundColor(0)
binding.imageViewBackground4.setBackgroundColor(0)
binding.imageViewBackground5.setBackgroundColor(0)
}

class ImageDialogFragment : DialogFragment() {
override fun onCreateView(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,30 @@
package com.regula.facesamplekotlin

import android.app.Activity
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.Color
import android.graphics.drawable.BitmapDrawable
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.view.MenuItem
import android.widget.*
import android.widget.Button
import android.widget.ImageView
import android.widget.PopupMenu
import android.widget.RadioButton
import android.widget.RadioGroup
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.ActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.activity.result.contract.ActivityResultContracts.RequestPermission
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SwitchCompat
import androidx.core.content.ContextCompat
import com.regula.facesamplekotlin.util.ResizeTransformation
import com.regula.facesdk.FaceSDK
import com.regula.facesdk.configuration.FaceCaptureConfiguration
import com.regula.facesdk.detection.request.OutputImageCrop
Expand All @@ -25,9 +40,11 @@ import com.regula.facesdk.model.results.matchfaces.MatchFacesSimilarityThreshold
import com.regula.facesdk.request.MatchFacesRequest


class MatchFacesActivity : Activity() {
class MatchFacesActivity : AppCompatActivity() {
private lateinit var imageView1: ImageView
private lateinit var imageView2: ImageView
private lateinit var switchDetectAll1: SwitchCompat
private lateinit var switchDetectAll2: SwitchCompat
private lateinit var imageViewResult1: ImageView
private lateinit var imageViewResult2: ImageView
private lateinit var group0: RadioGroup
Expand All @@ -40,6 +57,8 @@ class MatchFacesActivity : Activity() {
private lateinit var textViewSimilarity: TextView
private lateinit var textViewLiveness: TextView

private var currentImageView: ImageView? = null

private var imageUri: Uri? = null

public override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -55,6 +74,9 @@ class MatchFacesActivity : Activity() {
imageViewResult1 = findViewById(R.id.imageViewResult1)
imageViewResult2 = findViewById(R.id.imageViewResult2)

switchDetectAll1 = findViewById(R.id.detectAll1)
switchDetectAll2 = findViewById(R.id.detectAll2)

group0 = findViewById(R.id.rbGroup0)
group1 = findViewById(R.id.rbGroup1)

Expand Down Expand Up @@ -112,13 +134,63 @@ class MatchFacesActivity : Activity() {
startFaceCaptureActivity(imageView, radioGroup)
return@setOnMenuItemClickListener true
}
R.id.photo -> {
currentImageView = imageView
openDefaultCamera()
return@setOnMenuItemClickListener true
}
else -> return@setOnMenuItemClickListener false
}
}
popupMenu.menuInflater.inflate(R.menu.menu, popupMenu.menu)
popupMenu.show()
}


private val requestPermissionLauncher =
registerForActivityResult(
RequestPermission()
) { isGranted: Boolean ->
if (isGranted) {
launchCamera()
} else {
Toast.makeText(
this@MatchFacesActivity,
"Camera permission denied",
Toast.LENGTH_SHORT
).show()
}
}

private fun openDefaultCamera() {
when {
ContextCompat.checkSelfPermission(
this@MatchFacesActivity,
Manifest.permission.CAMERA
) == PackageManager.PERMISSION_GRANTED -> {
launchCamera()
}

else -> {
requestPermissionLauncher.launch(
Manifest.permission.CAMERA
)
}
}
}

private fun launchCamera() {
val cameraIntent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
startCameraForResult.launch(cameraIntent)
}

private val startCameraForResult =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result: ActivityResult ->
val photo = result.data?.extras?.get("data")
if (photo is Bitmap)
currentImageView?.setImageBitmap(photo);
}

private fun getImageBitmap(imageView: ImageView?): Bitmap {
imageView?.invalidate()
val drawable = imageView?.drawable as BitmapDrawable
Expand Down Expand Up @@ -163,14 +235,20 @@ class MatchFacesActivity : Activity() {
group = group1
}

imageView?.setImageURI(imageUri)
imageUri?.let {
val bitmap = contentResolver?.openInputStream(it).use { data ->
BitmapFactory.decodeStream(data)
}
val resizedBitmap = ResizeTransformation(1080).transform(bitmap)
imageView?.setImageBitmap(resizedBitmap)
}

setGroupSelection(group, ImageType.PRINTED)
}

private fun matchFaces(first: Bitmap, second: Bitmap) {
val firstImage = MatchFacesImage(first, getGroupSelection(group0), true)
val secondImage = MatchFacesImage(second, getGroupSelection(group1), true)
val firstImage = MatchFacesImage(first, getGroupSelection(group0), switchDetectAll1.isChecked)
val secondImage = MatchFacesImage(second, getGroupSelection(group1), switchDetectAll1.isChecked)
val matchFacesRequest = MatchFacesRequest(arrayListOf(firstImage, secondImage))

val crop = OutputImageCrop(
Expand Down
Loading

0 comments on commit 2bc2a4b

Please sign in to comment.