Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,11 @@ dependencies {
implementation "androidx.lifecycle:lifecycle-extensions:$archXVersion"
implementation "androidx.lifecycle:lifecycle-reactivestreams-ktx:$archXVersion"
implementation "androidx.lifecycle:lifecycle-common-java8:$archXVersion"
implementation "com.google.android.gms:play-services-vision:$playServicesVersionVision"
implementation "com.google.android.gms:play-services-auth:$playServicesVersionAuth"
implementation "com.google.firebase:firebase-crashlytics:$firebaseCrashlyticsVersion"
implementation "com.google.firebase:firebase-core:$firebaseVersionCore"
implementation "com.google.firebase:firebase-config:$firebaseVersionConfig"
implementation "com.google.firebase:firebase-auth:$firebaseVersionAuth"
implementation "com.google.firebase:firebase-ml-vision:$firebaseMLVision"


implementation ('com.google.http-client:google-http-client-gson:1.36.0') {
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ ext {
firebaseVersionCore = "18.0.0"
firebaseVersionConfig = "20.0.0"
firebaseVersionAuth = "20.0.0"
firebaseMLVision = "24.1.0"
firebaseAnalyticsVersion = "17.6.0"
firebaseCrashlyticsVersion = "17.2.2"

playServicesVersionVision = "20.1.2"
playServicesVersionAuth = "19.0.0"
mlBarcodeVersion = "16.0.3"

daggerVersion = "2.27"
retrofitVersion = "2.9.0"
Expand Down
2 changes: 1 addition & 1 deletion camera/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ dependencies {
implementation "androidx.camera:camera-extensions:${rootProject.cameraXExtensionVersion}"

implementation "com.jakewharton.timber:timber:$timberVersion"
implementation "com.google.firebase:firebase-ml-vision:$firebaseMLVision"
implementation "com.google.mlkit:barcode-scanning:$mlBarcodeVersion"
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,22 @@ package at.shockbytes.dante.camera.analyzer

import android.annotation.SuppressLint
import android.util.Size
import android.view.Surface.ROTATION_180
import android.view.Surface.ROTATION_270
import android.view.Surface.ROTATION_90
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageProxy
import at.shockbytes.dante.camera.IsbnVisionBarcode
import com.google.firebase.ml.vision.FirebaseVision
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcode
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetector
import com.google.firebase.ml.vision.barcode.FirebaseVisionBarcodeDetectorOptions
import com.google.firebase.ml.vision.common.FirebaseVisionImage
import com.google.firebase.ml.vision.common.FirebaseVisionImageMetadata
import com.google.mlkit.vision.barcode.Barcode
import com.google.mlkit.vision.barcode.BarcodeScanner
import com.google.mlkit.vision.barcode.BarcodeScannerOptions
import com.google.mlkit.vision.barcode.BarcodeScanning
import com.google.mlkit.vision.common.InputImage
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import timber.log.Timber
import java.util.concurrent.TimeUnit

class BarcodeAnalyzer(private val rotationDegrees: Int) : ImageAnalysis.Analyzer {

private val detector: FirebaseVisionBarcodeDetector
private val detector: BarcodeScanner

private var lastAnalyzedTimestamp = 0L

Expand All @@ -33,16 +29,14 @@ class BarcodeAnalyzer(private val rotationDegrees: Int) : ImageAnalysis.Analyzer

init {

val options = FirebaseVisionBarcodeDetectorOptions.Builder()
val options = BarcodeScannerOptions.Builder()
.setBarcodeFormats(
FirebaseVisionBarcode.FORMAT_EAN_13,
FirebaseVisionBarcode.FORMAT_EAN_8
Barcode.FORMAT_EAN_13,
Barcode.FORMAT_EAN_8
)
.build()

detector = FirebaseVision
.getInstance()
.getVisionBarcodeDetector(options)
detector = BarcodeScanning.getClient(options)
}

@SuppressLint("UnsafeExperimentalUsageError")
Expand All @@ -52,16 +46,15 @@ class BarcodeAnalyzer(private val rotationDegrees: Int) : ImageAnalysis.Analyzer

val size = Size(imageProxy.width, imageProxy.height)

val proxImage = imageProxy.image
if (proxImage == null) {
val proxyImage = imageProxy.image
if (proxyImage == null) {
Timber.e("CAM: Image is null")
return
}

val rotationCompensation = getRotation(rotationDegrees)
val image = FirebaseVisionImage.fromMediaImage(proxImage, rotationCompensation)
val image = InputImage.fromMediaImage(proxyImage, imageProxy.imageInfo.rotationDegrees)

detector.detectInImage(image)
detector.process(image)
.addOnSuccessListener { codes ->
if (codes.isNotEmpty()) {

Expand Down Expand Up @@ -94,13 +87,4 @@ class BarcodeAnalyzer(private val rotationDegrees: Int) : ImageAnalysis.Analyzer
// Close proxy at the end
imageProxy.close()
}

private fun getRotation(rotationCompensation: Int): Int {
return when (rotationCompensation) {
ROTATION_90 -> FirebaseVisionImageMetadata.ROTATION_90
ROTATION_180 -> FirebaseVisionImageMetadata.ROTATION_180
ROTATION_270 -> FirebaseVisionImageMetadata.ROTATION_270
else -> FirebaseVisionImageMetadata.ROTATION_0
}
}
}