Skip to content

Commit a3748b9

Browse files
add logic for expiry detection:
Signed-off-by: the-dagger <[email protected]>
1 parent 5f863c0 commit a3748b9

File tree

9 files changed

+163
-5
lines changed

9 files changed

+163
-5
lines changed
544 Bytes
Binary file not shown.

.idea/codeStyles/Project.xml

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 34 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package io.github.the_dagger.mlkit.activity
2+
3+
import android.graphics.Bitmap
4+
import android.os.Bundle
5+
import android.support.design.widget.BottomSheetBehavior
6+
import android.util.Log
7+
import android.view.View
8+
import android.widget.Toast
9+
import com.google.firebase.ml.vision.FirebaseVision
10+
import com.google.firebase.ml.vision.common.FirebaseVisionImage
11+
import io.github.the_dagger.mlkit.R
12+
import kotlinx.android.synthetic.main.activity_main.*
13+
import kotlinx.android.synthetic.main.layout_card_scanner.*
14+
15+
class CardScannerActivity : BaseCameraActivity() {
16+
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(savedInstanceState)
19+
setupBottomSheet(R.layout.layout_card_scanner)
20+
}
21+
22+
override fun onClick(v: View?) {
23+
fabProgressCircle.show()
24+
cameraView.captureImage { cameraKitImage ->
25+
// Get the Bitmap from the captured shot
26+
getCardDetails(cameraKitImage.bitmap)
27+
runOnUiThread {
28+
showPreview()
29+
imagePreview.setImageBitmap(cameraKitImage.bitmap)
30+
}
31+
}
32+
}
33+
34+
private fun getCardDetails(bitmap: Bitmap) {
35+
val image = FirebaseVisionImage.fromBitmap(bitmap)
36+
val firebaseVisionTextDetector = FirebaseVision.getInstance().visionCloudTextDetector
37+
38+
firebaseVisionTextDetector.detectInImage(image)
39+
.addOnSuccessListener {
40+
val words = it.text.split("\n")
41+
for (word in words) {
42+
Log.e("TAG", word)
43+
//REGEX for detecting a credit card
44+
if (word.replace(" ", "").matches(Regex("^(?:4[0-9]{12}(?:[0-9]{3})?|[25][1-7][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})\$")))
45+
tvCardNumber.text = word
46+
//Find a better way to do this
47+
if (word.contains("/")) {
48+
for (year in word.split(" ")) {
49+
if (year.contains("/"))
50+
tvCardExpiry.text = year
51+
}
52+
}
53+
}
54+
sheetBehavior.state = BottomSheetBehavior.STATE_EXPANDED
55+
fabProgressCircle.hide()
56+
}
57+
.addOnFailureListener {
58+
fabProgressCircle.hide()
59+
Toast.makeText(baseContext, "Sorry, something went wrong!", Toast.LENGTH_SHORT).show()
60+
}
61+
}
62+
}

app/src/main/java/io/github/the_dagger/mlkit/activity/FaceDetectionActivity.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import com.google.firebase.ml.vision.FirebaseVision
77
import com.google.firebase.ml.vision.common.FirebaseVisionImage
88
import com.google.firebase.ml.vision.face.FirebaseVisionFaceDetector
99
import com.wonderkiln.camerakit.CameraKit
10+
import io.github.the_dagger.mlkit.R
11+
import io.github.the_dagger.mlkit.R.id.*
1012
import io.github.the_dagger.mlkit.activity.BaseCameraActivity
1113
import kotlinx.android.synthetic.main.activity_main.*
1214

@@ -15,6 +17,7 @@ class FaceDetectionActivity : BaseCameraActivity(){
1517
override fun onCreate(savedInstanceState: Bundle?) {
1618
super.onCreate(savedInstanceState)
1719
cameraView.facing = CameraKit.Constants.FACING_FRONT
20+
setupBottomSheet(R.layout.layout_image_label)
1821
}
1922

2023
private fun getFaceDetails(bitmap: Bitmap) {

app/src/main/java/io/github/the_dagger/mlkit/activity/HomeActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class HomeActivity : AppCompatActivity() {
1818
super.onCreate(savedInstanceState)
1919
setContentView(R.layout.activity_home)
2020
apiList.add(PojoApi(R.drawable.image_labelling, getString(R.string.title_labelling), getString(R.string.desc_labelling), 0))
21+
apiList.add(PojoApi(R.drawable.text_recognition, getString(R.string.title_text), getString(R.string.desc_text), 3))
2122
apiList.add(PojoApi(R.drawable.face_detection, getString(R.string.title_face), getString(R.string.desc_face), 1))
2223
apiList.add(PojoApi(R.drawable.barcode_scanning, getString(R.string.title_barcode), getString(R.string.desc_barcode), 2))
23-
apiList.add(PojoApi(R.drawable.text_recognition, getString(R.string.title_text), getString(R.string.desc_text), 3))
2424
apiList.add(PojoApi(R.drawable.landmark_identification, getString(R.string.title_landmark), getString(R.string.desc_landmark), 4))
2525

2626
rvHome.layoutManager = LinearLayoutManager(this)

app/src/main/java/io/github/the_dagger/mlkit/adapter/HomeAdapter.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlinx.android.synthetic.main.item_row_home.view.*
1515

1616
class HomeAdapter(private val apiList: List<PojoApi>) : RecyclerView.Adapter<HomeAdapter.HomeHolder>() {
1717

18-
lateinit var context: Context
18+
private lateinit var context: Context
1919

2020
class HomeHolder(itemView: View?) : RecyclerView.ViewHolder(itemView)
2121

@@ -28,9 +28,9 @@ class HomeAdapter(private val apiList: List<PojoApi>) : RecyclerView.Adapter<Hom
2828
cViewHome.setOnClickListener {
2929
when(currItem.id){
3030
0 -> context.startActivity(Intent(context, ImageLabelActivity::class.java))
31-
1 -> context.startActivity(Intent(context, FaceDetectionActivity::class.java))
32-
2 -> Toast.makeText(context,"Work in Progress",Toast.LENGTH_SHORT).show()
33-
3 -> context.startActivity(Intent(context, CardScannerActivity::class.java))
31+
1 -> context.startActivity(Intent(context, CardScannerActivity::class.java))
32+
2 -> context.startActivity(Intent(context, FaceDetectionActivity::class.java))
33+
3 -> Toast.makeText(context,"Work in Progress",Toast.LENGTH_SHORT).show()
3434
4 -> Toast.makeText(context,"Work in Progress",Toast.LENGTH_SHORT).show()
3535
}
3636
}

0 commit comments

Comments
 (0)