├── .gitignore
├── .idea
├── codeStyles
│ ├── Project.xml
│ └── codeStyleConfig.xml
├── dictionaries
│ └── anupamchugh.xml
├── encodings.xml
├── gradle.xml
├── misc.xml
└── runConfigurations.xml
├── README.md
├── app
├── .gitignore
├── build.gradle
├── proguard-rules.pro
└── src
│ ├── androidTest
│ └── java
│ │ └── com
│ │ └── anupam
│ │ └── androidcameraxtflite
│ │ └── ExampleInstrumentedTest.kt
│ ├── main
│ ├── AndroidManifest.xml
│ ├── assets
│ │ ├── labels.txt
│ │ └── mobilenet_v1_1.0_224.tflite
│ ├── java
│ │ └── com
│ │ │ └── anupam
│ │ │ └── androidcameraxtflite
│ │ │ ├── MainActivity.kt
│ │ │ └── TFLiteClassifier.kt
│ └── res
│ │ ├── drawable-v24
│ │ └── ic_launcher_foreground.xml
│ │ ├── drawable
│ │ └── ic_launcher_background.xml
│ │ ├── layout
│ │ └── activity_main.xml
│ │ ├── mipmap-anydpi-v26
│ │ ├── ic_launcher.xml
│ │ └── ic_launcher_round.xml
│ │ ├── mipmap-hdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ ├── ic_launcher.png
│ │ └── ic_launcher_round.png
│ │ └── values
│ │ ├── colors.xml
│ │ ├── strings.xml
│ │ └── styles.xml
│ └── test
│ └── java
│ └── com
│ └── anupam
│ └── androidcameraxtflite
│ └── ExampleUnitTest.kt
├── build.gradle
├── gradle.properties
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── settings.gradle
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/caches
5 | /.idea/libraries
6 | /.idea/modules.xml
7 | /.idea/workspace.xml
8 | /.idea/navEditor.xml
9 | /.idea/assetWizardSettings.xml
10 | .DS_Store
11 | /build
12 | /captures
13 | .externalNativeBuild
14 | .cxx
15 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 | xmlns:android
20 |
21 | ^$
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | xmlns:.*
31 |
32 | ^$
33 |
34 |
35 | BY_NAME
36 |
37 |
38 |
39 |
40 |
41 |
42 | .*:id
43 |
44 | http://schemas.android.com/apk/res/android
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 | .*:name
54 |
55 | http://schemas.android.com/apk/res/android
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 | name
65 |
66 | ^$
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 | style
76 |
77 | ^$
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 | .*
87 |
88 | ^$
89 |
90 |
91 | BY_NAME
92 |
93 |
94 |
95 |
96 |
97 |
98 | .*
99 |
100 | http://schemas.android.com/apk/res/android
101 |
102 |
103 | ANDROID_ATTRIBUTE_ORDER
104 |
105 |
106 |
107 |
108 |
109 |
110 | .*
111 |
112 | .*
113 |
114 |
115 | BY_NAME
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/.idea/dictionaries/anupamchugh.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.idea/encodings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
18 |
19 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 | Java
17 |
18 |
19 |
20 |
21 | TestNGJava
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # AndroidTfLiteCameraX
2 |
3 | Uses a MobileNet Model for Image Classification with CameraX and GPU Delegate
4 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | apply plugin: 'kotlin-android'
4 |
5 | apply plugin: 'kotlin-android-extensions'
6 |
7 | android {
8 | compileSdkVersion 29
9 | buildToolsVersion "29.0.1"
10 | defaultConfig {
11 | applicationId "com.anupam.androidcameraxtflite"
12 | minSdkVersion 21
13 | targetSdkVersion 29
14 | versionCode 1
15 | versionName "1.0"
16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17 | }
18 | aaptOptions {
19 | noCompress "tflite"
20 | }
21 | buildTypes {
22 | release {
23 | minifyEnabled false
24 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
25 | }
26 | }
27 | }
28 |
29 | dependencies {
30 | implementation fileTree(dir: 'libs', include: ['*.jar'])
31 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
32 | implementation 'androidx.appcompat:appcompat:1.1.0'
33 | implementation 'androidx.core:core-ktx:1.1.0'
34 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
35 |
36 | implementation 'androidx.camera:camera-core:1.0.0-alpha04'
37 | implementation 'androidx.camera:camera-camera2:1.0.0-alpha04'
38 |
39 | // Task API
40 | implementation "com.google.android.gms:play-services-tasks:17.0.0"
41 |
42 | //nightly TensorFlow Lite
43 | implementation 'org.tensorflow:tensorflow-lite:0.0.0-nightly'
44 | implementation 'org.tensorflow:tensorflow-lite-gpu:0.0.0-nightly'
45 |
46 | testImplementation 'junit:junit:4.12'
47 | androidTestImplementation 'androidx.test.ext:junit:1.1.0'
48 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
49 | }
50 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/anupam/androidcameraxtflite/ExampleInstrumentedTest.kt:
--------------------------------------------------------------------------------
1 | package com.anupam.androidcameraxtflite
2 |
3 | import androidx.test.platform.app.InstrumentationRegistry
4 | import androidx.test.ext.junit.runners.AndroidJUnit4
5 |
6 | import org.junit.Test
7 | import org.junit.runner.RunWith
8 |
9 | import org.junit.Assert.*
10 |
11 | /**
12 | * Instrumented test, which will execute on an Android device.
13 | *
14 | * See [testing documentation](http://d.android.com/tools/testing).
15 | */
16 | @RunWith(AndroidJUnit4::class)
17 | class ExampleInstrumentedTest {
18 | @Test
19 | fun useAppContext() {
20 | // Context of the app under test.
21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext
22 | assertEquals("com.anupam.androidcameraxtflite", appContext.packageName)
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/assets/labels.txt:
--------------------------------------------------------------------------------
1 | background
2 | tench
3 | goldfish
4 | great white shark
5 | tiger shark
6 | hammerhead
7 | electric ray
8 | stingray
9 | cock
10 | hen
11 | ostrich
12 | brambling
13 | goldfinch
14 | house finch
15 | junco
16 | indigo bunting
17 | robin
18 | bulbul
19 | jay
20 | magpie
21 | chickadee
22 | water ouzel
23 | kite
24 | bald eagle
25 | vulture
26 | great grey owl
27 | European fire salamander
28 | common newt
29 | eft
30 | spotted salamander
31 | axolotl
32 | bullfrog
33 | tree frog
34 | tailed frog
35 | loggerhead
36 | leatherback turtle
37 | mud turtle
38 | terrapin
39 | box turtle
40 | banded gecko
41 | common iguana
42 | American chameleon
43 | whiptail
44 | agama
45 | frilled lizard
46 | alligator lizard
47 | Gila monster
48 | green lizard
49 | African chameleon
50 | Komodo dragon
51 | African crocodile
52 | American alligator
53 | triceratops
54 | thunder snake
55 | ringneck snake
56 | hognose snake
57 | green snake
58 | king snake
59 | garter snake
60 | water snake
61 | vine snake
62 | night snake
63 | boa constrictor
64 | rock python
65 | Indian cobra
66 | green mamba
67 | sea snake
68 | horned viper
69 | diamondback
70 | sidewinder
71 | trilobite
72 | harvestman
73 | scorpion
74 | black and gold garden spider
75 | barn spider
76 | garden spider
77 | black widow
78 | tarantula
79 | wolf spider
80 | tick
81 | centipede
82 | black grouse
83 | ptarmigan
84 | ruffed grouse
85 | prairie chicken
86 | peacock
87 | quail
88 | partridge
89 | African grey
90 | macaw
91 | sulphur-crested cockatoo
92 | lorikeet
93 | coucal
94 | bee eater
95 | hornbill
96 | hummingbird
97 | jacamar
98 | toucan
99 | drake
100 | red-breasted merganser
101 | goose
102 | black swan
103 | tusker
104 | echidna
105 | platypus
106 | wallaby
107 | koala
108 | wombat
109 | jellyfish
110 | sea anemone
111 | brain coral
112 | flatworm
113 | nematode
114 | conch
115 | snail
116 | slug
117 | sea slug
118 | chiton
119 | chambered nautilus
120 | Dungeness crab
121 | rock crab
122 | fiddler crab
123 | king crab
124 | American lobster
125 | spiny lobster
126 | crayfish
127 | hermit crab
128 | isopod
129 | white stork
130 | black stork
131 | spoonbill
132 | flamingo
133 | little blue heron
134 | American egret
135 | bittern
136 | crane
137 | limpkin
138 | European gallinule
139 | American coot
140 | bustard
141 | ruddy turnstone
142 | red-backed sandpiper
143 | redshank
144 | dowitcher
145 | oystercatcher
146 | pelican
147 | king penguin
148 | albatross
149 | grey whale
150 | killer whale
151 | dugong
152 | sea lion
153 | Chihuahua
154 | Japanese spaniel
155 | Maltese dog
156 | Pekinese
157 | Shih-Tzu
158 | Blenheim spaniel
159 | papillon
160 | toy terrier
161 | Rhodesian ridgeback
162 | Afghan hound
163 | basset
164 | beagle
165 | bloodhound
166 | bluetick
167 | black-and-tan coonhound
168 | Walker hound
169 | English foxhound
170 | redbone
171 | borzoi
172 | Irish wolfhound
173 | Italian greyhound
174 | whippet
175 | Ibizan hound
176 | Norwegian elkhound
177 | otterhound
178 | Saluki
179 | Scottish deerhound
180 | Weimaraner
181 | Staffordshire bullterrier
182 | American Staffordshire terrier
183 | Bedlington terrier
184 | Border terrier
185 | Kerry blue terrier
186 | Irish terrier
187 | Norfolk terrier
188 | Norwich terrier
189 | Yorkshire terrier
190 | wire-haired fox terrier
191 | Lakeland terrier
192 | Sealyham terrier
193 | Airedale
194 | cairn
195 | Australian terrier
196 | Dandie Dinmont
197 | Boston bull
198 | miniature schnauzer
199 | giant schnauzer
200 | standard schnauzer
201 | Scotch terrier
202 | Tibetan terrier
203 | silky terrier
204 | soft-coated wheaten terrier
205 | West Highland white terrier
206 | Lhasa
207 | flat-coated retriever
208 | curly-coated retriever
209 | golden retriever
210 | Labrador retriever
211 | Chesapeake Bay retriever
212 | German short-haired pointer
213 | vizsla
214 | English setter
215 | Irish setter
216 | Gordon setter
217 | Brittany spaniel
218 | clumber
219 | English springer
220 | Welsh springer spaniel
221 | cocker spaniel
222 | Sussex spaniel
223 | Irish water spaniel
224 | kuvasz
225 | schipperke
226 | groenendael
227 | malinois
228 | briard
229 | kelpie
230 | komondor
231 | Old English sheepdog
232 | Shetland sheepdog
233 | collie
234 | Border collie
235 | Bouvier des Flandres
236 | Rottweiler
237 | German shepherd
238 | Doberman
239 | miniature pinscher
240 | Greater Swiss Mountain dog
241 | Bernese mountain dog
242 | Appenzeller
243 | EntleBucher
244 | boxer
245 | bull mastiff
246 | Tibetan mastiff
247 | French bulldog
248 | Great Dane
249 | Saint Bernard
250 | Eskimo dog
251 | malamute
252 | Siberian husky
253 | dalmatian
254 | affenpinscher
255 | basenji
256 | pug
257 | Leonberg
258 | Newfoundland
259 | Great Pyrenees
260 | Samoyed
261 | Pomeranian
262 | chow
263 | keeshond
264 | Brabancon griffon
265 | Pembroke
266 | Cardigan
267 | toy poodle
268 | miniature poodle
269 | standard poodle
270 | Mexican hairless
271 | timber wolf
272 | white wolf
273 | red wolf
274 | coyote
275 | dingo
276 | dhole
277 | African hunting dog
278 | hyena
279 | red fox
280 | kit fox
281 | Arctic fox
282 | grey fox
283 | tabby
284 | tiger cat
285 | Persian cat
286 | Siamese cat
287 | Egyptian cat
288 | cougar
289 | lynx
290 | leopard
291 | snow leopard
292 | jaguar
293 | lion
294 | tiger
295 | cheetah
296 | brown bear
297 | American black bear
298 | ice bear
299 | sloth bear
300 | mongoose
301 | meerkat
302 | tiger beetle
303 | ladybug
304 | ground beetle
305 | long-horned beetle
306 | leaf beetle
307 | dung beetle
308 | rhinoceros beetle
309 | weevil
310 | fly
311 | bee
312 | ant
313 | grasshopper
314 | cricket
315 | walking stick
316 | cockroach
317 | mantis
318 | cicada
319 | leafhopper
320 | lacewing
321 | dragonfly
322 | damselfly
323 | admiral
324 | ringlet
325 | monarch
326 | cabbage butterfly
327 | sulphur butterfly
328 | lycaenid
329 | starfish
330 | sea urchin
331 | sea cucumber
332 | wood rabbit
333 | hare
334 | Angora
335 | hamster
336 | porcupine
337 | fox squirrel
338 | marmot
339 | beaver
340 | guinea pig
341 | sorrel
342 | zebra
343 | hog
344 | wild boar
345 | warthog
346 | hippopotamus
347 | ox
348 | water buffalo
349 | bison
350 | ram
351 | bighorn
352 | ibex
353 | hartebeest
354 | impala
355 | gazelle
356 | Arabian camel
357 | llama
358 | weasel
359 | mink
360 | polecat
361 | black-footed ferret
362 | otter
363 | skunk
364 | badger
365 | armadillo
366 | three-toed sloth
367 | orangutan
368 | gorilla
369 | chimpanzee
370 | gibbon
371 | siamang
372 | guenon
373 | patas
374 | baboon
375 | macaque
376 | langur
377 | colobus
378 | proboscis monkey
379 | marmoset
380 | capuchin
381 | howler monkey
382 | titi
383 | spider monkey
384 | squirrel monkey
385 | Madagascar cat
386 | indri
387 | Indian elephant
388 | African elephant
389 | lesser panda
390 | giant panda
391 | barracouta
392 | eel
393 | coho
394 | rock beauty
395 | anemone fish
396 | sturgeon
397 | gar
398 | lionfish
399 | puffer
400 | abacus
401 | abaya
402 | academic gown
403 | accordion
404 | acoustic guitar
405 | aircraft carrier
406 | airliner
407 | airship
408 | altar
409 | ambulance
410 | amphibian
411 | analog clock
412 | apiary
413 | apron
414 | ashcan
415 | assault rifle
416 | backpack
417 | bakery
418 | balance beam
419 | balloon
420 | ballpoint
421 | Band Aid
422 | banjo
423 | bannister
424 | barbell
425 | barber chair
426 | barbershop
427 | barn
428 | barometer
429 | barrel
430 | barrow
431 | baseball
432 | basketball
433 | bassinet
434 | bassoon
435 | bathing cap
436 | bath towel
437 | bathtub
438 | beach wagon
439 | beacon
440 | beaker
441 | bearskin
442 | beer bottle
443 | beer glass
444 | bell cote
445 | bib
446 | bicycle-built-for-two
447 | bikini
448 | binder
449 | binoculars
450 | birdhouse
451 | boathouse
452 | bobsled
453 | bolo tie
454 | bonnet
455 | bookcase
456 | bookshop
457 | bottlecap
458 | bow
459 | bow tie
460 | brass
461 | brassiere
462 | breakwater
463 | breastplate
464 | broom
465 | bucket
466 | buckle
467 | bulletproof vest
468 | bullet train
469 | butcher shop
470 | cab
471 | caldron
472 | candle
473 | cannon
474 | canoe
475 | can opener
476 | cardigan
477 | car mirror
478 | carousel
479 | carpenter's kit
480 | carton
481 | car wheel
482 | cash machine
483 | cassette
484 | cassette player
485 | castle
486 | catamaran
487 | CD player
488 | cello
489 | cellular telephone
490 | chain
491 | chainlink fence
492 | chain mail
493 | chain saw
494 | chest
495 | chiffonier
496 | chime
497 | china cabinet
498 | Christmas stocking
499 | church
500 | cinema
501 | cleaver
502 | cliff dwelling
503 | cloak
504 | clog
505 | cocktail shaker
506 | coffee mug
507 | coffeepot
508 | coil
509 | combination lock
510 | computer keyboard
511 | confectionery
512 | container ship
513 | convertible
514 | corkscrew
515 | cornet
516 | cowboy boot
517 | cowboy hat
518 | cradle
519 | crane
520 | crash helmet
521 | crate
522 | crib
523 | Crock Pot
524 | croquet ball
525 | crutch
526 | cuirass
527 | dam
528 | desk
529 | desktop computer
530 | dial telephone
531 | diaper
532 | digital clock
533 | digital watch
534 | dining table
535 | dishrag
536 | dishwasher
537 | disk brake
538 | dock
539 | dogsled
540 | dome
541 | doormat
542 | drilling platform
543 | drum
544 | drumstick
545 | dumbbell
546 | Dutch oven
547 | electric fan
548 | electric guitar
549 | electric locomotive
550 | entertainment center
551 | envelope
552 | espresso maker
553 | face powder
554 | feather boa
555 | file
556 | fireboat
557 | fire engine
558 | fire screen
559 | flagpole
560 | flute
561 | folding chair
562 | football helmet
563 | forklift
564 | fountain
565 | fountain pen
566 | four-poster
567 | freight car
568 | French horn
569 | frying pan
570 | fur coat
571 | garbage truck
572 | gasmask
573 | gas pump
574 | goblet
575 | go-kart
576 | golf ball
577 | golfcart
578 | gondola
579 | gong
580 | gown
581 | grand piano
582 | greenhouse
583 | grille
584 | grocery store
585 | guillotine
586 | hair slide
587 | hair spray
588 | half track
589 | hammer
590 | hamper
591 | hand blower
592 | hand-held computer
593 | handkerchief
594 | hard disc
595 | harmonica
596 | harp
597 | harvester
598 | hatchet
599 | holster
600 | home theater
601 | honeycomb
602 | hook
603 | hoopskirt
604 | horizontal bar
605 | horse cart
606 | hourglass
607 | iPod
608 | iron
609 | jack-o'-lantern
610 | jean
611 | jeep
612 | jersey
613 | jigsaw puzzle
614 | jinrikisha
615 | joystick
616 | kimono
617 | knee pad
618 | knot
619 | lab coat
620 | ladle
621 | lampshade
622 | laptop
623 | lawn mower
624 | lens cap
625 | letter opener
626 | library
627 | lifeboat
628 | lighter
629 | limousine
630 | liner
631 | lipstick
632 | Loafer
633 | lotion
634 | loudspeaker
635 | loupe
636 | lumbermill
637 | magnetic compass
638 | mailbag
639 | mailbox
640 | maillot
641 | maillot
642 | manhole cover
643 | maraca
644 | marimba
645 | mask
646 | matchstick
647 | maypole
648 | maze
649 | measuring cup
650 | medicine chest
651 | megalith
652 | microphone
653 | microwave
654 | military uniform
655 | milk can
656 | minibus
657 | miniskirt
658 | minivan
659 | missile
660 | mitten
661 | mixing bowl
662 | mobile home
663 | Model T
664 | modem
665 | monastery
666 | monitor
667 | moped
668 | mortar
669 | mortarboard
670 | mosque
671 | mosquito net
672 | motor scooter
673 | mountain bike
674 | mountain tent
675 | mouse
676 | mousetrap
677 | moving van
678 | muzzle
679 | nail
680 | neck brace
681 | necklace
682 | nipple
683 | notebook
684 | obelisk
685 | oboe
686 | ocarina
687 | odometer
688 | oil filter
689 | organ
690 | oscilloscope
691 | overskirt
692 | oxcart
693 | oxygen mask
694 | packet
695 | paddle
696 | paddlewheel
697 | padlock
698 | paintbrush
699 | pajama
700 | palace
701 | panpipe
702 | paper towel
703 | parachute
704 | parallel bars
705 | park bench
706 | parking meter
707 | passenger car
708 | patio
709 | pay-phone
710 | pedestal
711 | pencil box
712 | pencil sharpener
713 | perfume
714 | Petri dish
715 | photocopier
716 | pick
717 | pickelhaube
718 | picket fence
719 | pickup
720 | pier
721 | piggy bank
722 | pill bottle
723 | pillow
724 | ping-pong ball
725 | pinwheel
726 | pirate
727 | pitcher
728 | plane
729 | planetarium
730 | plastic bag
731 | plate rack
732 | plow
733 | plunger
734 | Polaroid camera
735 | pole
736 | police van
737 | poncho
738 | pool table
739 | pop bottle
740 | pot
741 | potter's wheel
742 | power drill
743 | prayer rug
744 | printer
745 | prison
746 | projectile
747 | projector
748 | puck
749 | punching bag
750 | purse
751 | quill
752 | quilt
753 | racer
754 | racket
755 | radiator
756 | radio
757 | radio telescope
758 | rain barrel
759 | recreational vehicle
760 | reel
761 | reflex camera
762 | refrigerator
763 | remote control
764 | restaurant
765 | revolver
766 | rifle
767 | rocking chair
768 | rotisserie
769 | rubber eraser
770 | rugby ball
771 | rule
772 | running shoe
773 | safe
774 | safety pin
775 | saltshaker
776 | sandal
777 | sarong
778 | sax
779 | scabbard
780 | scale
781 | school bus
782 | schooner
783 | scoreboard
784 | screen
785 | screw
786 | screwdriver
787 | seat belt
788 | sewing machine
789 | shield
790 | shoe shop
791 | shoji
792 | shopping basket
793 | shopping cart
794 | shovel
795 | shower cap
796 | shower curtain
797 | ski
798 | ski mask
799 | sleeping bag
800 | slide rule
801 | sliding door
802 | slot
803 | snorkel
804 | snowmobile
805 | snowplow
806 | soap dispenser
807 | soccer ball
808 | sock
809 | solar dish
810 | sombrero
811 | soup bowl
812 | space bar
813 | space heater
814 | space shuttle
815 | spatula
816 | speedboat
817 | spider web
818 | spindle
819 | sports car
820 | spotlight
821 | stage
822 | steam locomotive
823 | steel arch bridge
824 | steel drum
825 | stethoscope
826 | stole
827 | stone wall
828 | stopwatch
829 | stove
830 | strainer
831 | streetcar
832 | stretcher
833 | studio couch
834 | stupa
835 | submarine
836 | suit
837 | sundial
838 | sunglass
839 | sunglasses
840 | sunscreen
841 | suspension bridge
842 | swab
843 | sweatshirt
844 | swimming trunks
845 | swing
846 | switch
847 | syringe
848 | table lamp
849 | tank
850 | tape player
851 | teapot
852 | teddy
853 | television
854 | tennis ball
855 | thatch
856 | theater curtain
857 | thimble
858 | thresher
859 | throne
860 | tile roof
861 | toaster
862 | tobacco shop
863 | toilet seat
864 | torch
865 | totem pole
866 | tow truck
867 | toyshop
868 | tractor
869 | trailer truck
870 | tray
871 | trench coat
872 | tricycle
873 | trimaran
874 | tripod
875 | triumphal arch
876 | trolleybus
877 | trombone
878 | tub
879 | turnstile
880 | typewriter keyboard
881 | umbrella
882 | unicycle
883 | upright
884 | vacuum
885 | vase
886 | vault
887 | velvet
888 | vending machine
889 | vestment
890 | viaduct
891 | violin
892 | volleyball
893 | waffle iron
894 | wall clock
895 | wallet
896 | wardrobe
897 | warplane
898 | washbasin
899 | washer
900 | water bottle
901 | water jug
902 | water tower
903 | whiskey jug
904 | whistle
905 | wig
906 | window screen
907 | window shade
908 | Windsor tie
909 | wine bottle
910 | wing
911 | wok
912 | wooden spoon
913 | wool
914 | worm fence
915 | wreck
916 | yawl
917 | yurt
918 | web site
919 | comic book
920 | crossword puzzle
921 | street sign
922 | traffic light
923 | book jacket
924 | menu
925 | plate
926 | guacamole
927 | consomme
928 | hot pot
929 | trifle
930 | ice cream
931 | ice lolly
932 | French loaf
933 | bagel
934 | pretzel
935 | cheeseburger
936 | hotdog
937 | mashed potato
938 | head cabbage
939 | broccoli
940 | cauliflower
941 | zucchini
942 | spaghetti squash
943 | acorn squash
944 | butternut squash
945 | cucumber
946 | artichoke
947 | bell pepper
948 | cardoon
949 | mushroom
950 | Granny Smith
951 | strawberry
952 | orange
953 | lemon
954 | fig
955 | pineapple
956 | banana
957 | jackfruit
958 | custard apple
959 | pomegranate
960 | hay
961 | carbonara
962 | chocolate sauce
963 | dough
964 | meat loaf
965 | pizza
966 | potpie
967 | burrito
968 | red wine
969 | espresso
970 | cup
971 | eggnog
972 | alp
973 | bubble
974 | cliff
975 | coral reef
976 | geyser
977 | lakeside
978 | promontory
979 | sandbar
980 | seashore
981 | valley
982 | volcano
983 | ballplayer
984 | groom
985 | scuba diver
986 | rapeseed
987 | daisy
988 | yellow lady's slipper
989 | corn
990 | acorn
991 | hip
992 | buckeye
993 | coral fungus
994 | agaric
995 | gyromitra
996 | stinkhorn
997 | earthstar
998 | hen-of-the-woods
999 | bolete
1000 | ear
1001 | toilet tissue
--------------------------------------------------------------------------------
/app/src/main/assets/mobilenet_v1_1.0_224.tflite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/assets/mobilenet_v1_1.0_224.tflite
--------------------------------------------------------------------------------
/app/src/main/java/com/anupam/androidcameraxtflite/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.anupam.androidcameraxtflite
2 |
3 | import androidx.appcompat.app.AppCompatActivity
4 | import android.os.Bundle
5 | import android.util.DisplayMetrics
6 | import android.util.Rational
7 | import android.util.Size
8 | import android.view.Surface
9 | import kotlinx.android.synthetic.main.activity_main.*
10 | import android.content.pm.PackageManager
11 | import android.graphics.*
12 | import android.os.Handler
13 | import android.os.HandlerThread
14 | import android.util.Log
15 | import androidx.core.content.ContextCompat
16 | import android.widget.Toast
17 | import androidx.camera.core.*
18 | import androidx.core.app.ActivityCompat
19 | import java.io.ByteArrayOutputStream
20 |
21 |
22 | class MainActivity : AppCompatActivity() {
23 |
24 | private var lensFacing = CameraX.LensFacing.BACK
25 | private val TAG = "MainActivity"
26 |
27 | private val REQUEST_CODE_PERMISSIONS = 101
28 | private val REQUIRED_PERMISSIONS = arrayOf("android.permission.CAMERA")
29 |
30 | private var tfLiteClassifier: TFLiteClassifier = TFLiteClassifier(this@MainActivity)
31 |
32 | override fun onCreate(savedInstanceState: Bundle?) {
33 | super.onCreate(savedInstanceState)
34 | setContentView(R.layout.activity_main)
35 |
36 | if (allPermissionsGranted()) {
37 | textureView.post { startCamera() }
38 | textureView.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
39 | updateTransform()
40 | }
41 | } else {
42 | ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS);
43 | }
44 |
45 | tfLiteClassifier
46 | .initialize()
47 | .addOnSuccessListener { }
48 | .addOnFailureListener { e -> Log.e(TAG, "Error in setting up the classifier.", e) }
49 |
50 | }
51 |
52 | private fun startCamera() {
53 | val metrics = DisplayMetrics().also { textureView.display.getRealMetrics(it) }
54 | val screenSize = Size(metrics.widthPixels, metrics.heightPixels)
55 | val screenAspectRatio = Rational(1, 1)
56 |
57 | val previewConfig = PreviewConfig.Builder().apply {
58 | setLensFacing(lensFacing)
59 | setTargetResolution(screenSize)
60 | setTargetAspectRatio(screenAspectRatio)
61 | setTargetRotation(windowManager.defaultDisplay.rotation)
62 | setTargetRotation(textureView.display.rotation)
63 | }.build()
64 |
65 | val preview = Preview(previewConfig)
66 | preview.setOnPreviewOutputUpdateListener {
67 | textureView.surfaceTexture = it.surfaceTexture
68 | updateTransform()
69 | }
70 |
71 |
72 | val analyzerConfig = ImageAnalysisConfig.Builder().apply {
73 | // Use a worker thread for image analysis to prevent glitches
74 | val analyzerThread = HandlerThread("AnalysisThread").apply {
75 | start()
76 | }
77 | setCallbackHandler(Handler(analyzerThread.looper))
78 | setImageReaderMode(ImageAnalysis.ImageReaderMode.ACQUIRE_LATEST_IMAGE)
79 | }.build()
80 |
81 |
82 | val analyzerUseCase = ImageAnalysis(analyzerConfig)
83 | analyzerUseCase.analyzer =
84 | ImageAnalysis.Analyzer { image: ImageProxy, rotationDegrees: Int ->
85 |
86 | val bitmap = image.toBitmap()
87 |
88 | tfLiteClassifier
89 | .classifyAsync(bitmap)
90 | .addOnSuccessListener { resultText -> predictedTextView?.text = resultText }
91 | .addOnFailureListener { error -> }
92 |
93 | }
94 | CameraX.bindToLifecycle(this, preview, analyzerUseCase)
95 | }
96 |
97 | fun ImageProxy.toBitmap(): Bitmap {
98 | val yBuffer = planes[0].buffer // Y
99 | val uBuffer = planes[1].buffer // U
100 | val vBuffer = planes[2].buffer // V
101 |
102 | val ySize = yBuffer.remaining()
103 | val uSize = uBuffer.remaining()
104 | val vSize = vBuffer.remaining()
105 |
106 | val nv21 = ByteArray(ySize + uSize + vSize)
107 |
108 | yBuffer.get(nv21, 0, ySize)
109 | vBuffer.get(nv21, ySize, vSize)
110 | uBuffer.get(nv21, ySize + vSize, uSize)
111 |
112 | val yuvImage = YuvImage(nv21, ImageFormat.NV21, this.width, this.height, null)
113 | val out = ByteArrayOutputStream()
114 | yuvImage.compressToJpeg(Rect(0, 0, yuvImage.width, yuvImage.height), 100, out)
115 | val imageBytes = out.toByteArray()
116 | return BitmapFactory.decodeByteArray(imageBytes, 0, imageBytes.size)
117 | }
118 |
119 | private fun updateTransform() {
120 | val matrix = Matrix()
121 | val centerX = textureView.width / 2f
122 | val centerY = textureView.height / 2f
123 |
124 | val rotationDegrees = when (textureView.display.rotation) {
125 | Surface.ROTATION_0 -> 0
126 | Surface.ROTATION_90 -> 90
127 | Surface.ROTATION_180 -> 180
128 | Surface.ROTATION_270 -> 270
129 | else -> return
130 | }
131 | matrix.postRotate(-rotationDegrees.toFloat(), centerX, centerY)
132 | textureView.setTransform(matrix)
133 | }
134 |
135 | override fun onRequestPermissionsResult(
136 | requestCode: Int,
137 | permissions: Array,
138 | grantResults: IntArray
139 | ) {
140 |
141 | if (requestCode == REQUEST_CODE_PERMISSIONS) {
142 | if (allPermissionsGranted()) {
143 | startCamera()
144 | } else {
145 | Toast.makeText(this, "Permissions not granted by the user.", Toast.LENGTH_SHORT)
146 | .show()
147 | finish()
148 | }
149 | }
150 | }
151 |
152 | private fun allPermissionsGranted(): Boolean {
153 |
154 | for (permission in REQUIRED_PERMISSIONS) {
155 | if (ContextCompat.checkSelfPermission(
156 | this,
157 | permission
158 | ) != PackageManager.PERMISSION_GRANTED
159 | ) {
160 | return false
161 | }
162 | }
163 | return true
164 | }
165 |
166 | override fun onDestroy() {
167 | tfLiteClassifier.close()
168 | super.onDestroy()
169 | }
170 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/anupam/androidcameraxtflite/TFLiteClassifier.kt:
--------------------------------------------------------------------------------
1 | package com.anupam.androidcameraxtflite
2 |
3 | import android.content.Context
4 | import android.content.res.AssetManager
5 | import android.os.SystemClock
6 | import android.util.Log
7 | import com.google.android.gms.tasks.Task
8 | import com.google.android.gms.tasks.Tasks.call
9 | import org.tensorflow.lite.gpu.GpuDelegate
10 | import java.io.FileInputStream
11 | import java.io.IOException
12 | import java.io.InputStreamReader
13 | import java.nio.ByteBuffer
14 | import java.nio.ByteOrder
15 | import java.nio.channels.FileChannel
16 | import java.util.*
17 | import java.util.concurrent.Callable
18 | import java.util.concurrent.ExecutorService
19 | import java.util.concurrent.Executors
20 | import kotlin.collections.ArrayList
21 | import android.graphics.Bitmap
22 | import org.tensorflow.lite.Interpreter
23 |
24 | class TFLiteClassifier(private val context: Context) {
25 |
26 | private var interpreter: Interpreter? = null
27 | var isInitialized = false
28 | private set
29 |
30 | private var gpuDelegate: GpuDelegate? = null
31 |
32 | var labels = ArrayList()
33 |
34 | private val executorService: ExecutorService = Executors.newCachedThreadPool()
35 |
36 | private var inputImageWidth: Int = 0
37 | private var inputImageHeight: Int = 0
38 | private var modelInputSize: Int = 0
39 |
40 | fun initialize(): Task {
41 | return call(
42 | executorService,
43 | Callable {
44 | initializeInterpreter()
45 | null
46 | }
47 | )
48 | }
49 |
50 | @Throws(IOException::class)
51 | private fun initializeInterpreter() {
52 |
53 |
54 |
55 | val assetManager = context.assets
56 | val model = loadModelFile(assetManager, "mobilenet_v1_1.0_224.tflite")
57 |
58 | labels = loadLines(context, "labels.txt")
59 | val options = Interpreter.Options()
60 | gpuDelegate = GpuDelegate()
61 | options.addDelegate(gpuDelegate)
62 | val interpreter = Interpreter(model, options)
63 |
64 | val inputShape = interpreter.getInputTensor(0).shape()
65 | inputImageWidth = inputShape[1]
66 | inputImageHeight = inputShape[2]
67 | modelInputSize = FLOAT_TYPE_SIZE * inputImageWidth * inputImageHeight * CHANNEL_SIZE
68 |
69 | this.interpreter = interpreter
70 |
71 | isInitialized = true
72 | }
73 |
74 | @Throws(IOException::class)
75 | private fun loadModelFile(assetManager: AssetManager, filename: String): ByteBuffer {
76 | val fileDescriptor = assetManager.openFd(filename)
77 | val inputStream = FileInputStream(fileDescriptor.fileDescriptor)
78 | val fileChannel = inputStream.channel
79 | val startOffset = fileDescriptor.startOffset
80 | val declaredLength = fileDescriptor.declaredLength
81 | return fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength)
82 | }
83 |
84 | @Throws(IOException::class)
85 | fun loadLines(context: Context, filename: String): ArrayList {
86 | val s = Scanner(InputStreamReader(context.assets.open(filename)))
87 | val labels = ArrayList()
88 | while (s.hasNextLine()) {
89 | labels.add(s.nextLine())
90 | }
91 | s.close()
92 | return labels
93 | }
94 |
95 | private fun getMaxResult(result: FloatArray): Int {
96 | var probability = result[0]
97 | var index = 0
98 | for (i in result.indices) {
99 | if (probability < result[i]) {
100 | probability = result[i]
101 | index = i
102 | }
103 | }
104 | return index
105 | }
106 |
107 |
108 | private fun classify(bitmap: Bitmap): String {
109 |
110 | check(isInitialized) { "TF Lite Interpreter is not initialized yet." }
111 | val resizedImage =
112 | Bitmap.createScaledBitmap(bitmap, inputImageWidth, inputImageHeight, true)
113 |
114 | val byteBuffer = convertBitmapToByteBuffer(resizedImage)
115 |
116 | val output = Array(1) { FloatArray(labels.size) }
117 | val startTime = SystemClock.uptimeMillis()
118 | interpreter?.run(byteBuffer, output)
119 | val endTime = SystemClock.uptimeMillis()
120 |
121 | var inferenceTime = endTime - startTime
122 | var index = getMaxResult(output[0])
123 | var result = "Prediction is ${labels[index]}\nInference Time $inferenceTime ms"
124 |
125 | return result
126 | }
127 |
128 | fun classifyAsync(bitmap: Bitmap): Task {
129 | return call(executorService, Callable { classify(bitmap) })
130 | }
131 |
132 | fun close() {
133 | call(
134 | executorService,
135 | Callable {
136 | interpreter?.close()
137 | if (gpuDelegate != null) {
138 | gpuDelegate!!.close()
139 | gpuDelegate = null
140 | }
141 |
142 | Log.d(TAG, "Closed TFLite interpreter.")
143 | null
144 | }
145 | )
146 | }
147 |
148 | private fun convertBitmapToByteBuffer(bitmap: Bitmap): ByteBuffer {
149 | val byteBuffer = ByteBuffer.allocateDirect(modelInputSize)
150 | byteBuffer.order(ByteOrder.nativeOrder())
151 |
152 | val pixels = IntArray(inputImageWidth * inputImageHeight)
153 | bitmap.getPixels(pixels, 0, bitmap.width, 0, 0, bitmap.width, bitmap.height)
154 | var pixel = 0
155 | for (i in 0 until inputImageWidth) {
156 | for (j in 0 until inputImageHeight) {
157 | val pixelVal = pixels[pixel++]
158 |
159 | byteBuffer.putFloat(((pixelVal shr 16 and 0xFF) - IMAGE_MEAN) / IMAGE_STD)
160 | byteBuffer.putFloat(((pixelVal shr 8 and 0xFF) - IMAGE_MEAN) / IMAGE_STD)
161 | byteBuffer.putFloat(((pixelVal and 0xFF) - IMAGE_MEAN) / IMAGE_STD)
162 |
163 | }
164 | }
165 | bitmap.recycle()
166 |
167 | return byteBuffer
168 | }
169 |
170 | companion object {
171 | private const val TAG = "TfliteClassifier"
172 | private const val FLOAT_TYPE_SIZE = 4
173 | private const val CHANNEL_SIZE = 3
174 | private const val IMAGE_MEAN = 127.5f
175 | private const val IMAGE_STD = 127.5f
176 | }
177 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
18 |
19 |
20 |
28 |
29 |
37 |
38 |
39 |
40 |
41 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | AndroidTfliteCameraX
3 |
4 |
5 | - GPU
6 | - CPU
7 | - NNAPI
8 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/test/java/com/anupam/androidcameraxtflite/ExampleUnitTest.kt:
--------------------------------------------------------------------------------
1 | package com.anupam.androidcameraxtflite
2 |
3 | import org.junit.Test
4 |
5 | import org.junit.Assert.*
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * See [testing documentation](http://d.android.com/tools/testing).
11 | */
12 | class ExampleUnitTest {
13 | @Test
14 | fun addition_isCorrect() {
15 | assertEquals(4, 2 + 2)
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | ext.kotlin_version = '1.3.50'
5 | repositories {
6 | google()
7 | jcenter()
8 |
9 | }
10 | dependencies {
11 | classpath 'com.android.tools.build:gradle:3.5.1'
12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
13 | // NOTE: Do not place your application dependencies here; they belong
14 | // in the individual module build.gradle files
15 | }
16 | }
17 |
18 | allprojects {
19 | repositories {
20 | google()
21 | jcenter()
22 |
23 | }
24 | }
25 |
26 | task clean(type: Delete) {
27 | delete rootProject.buildDir
28 | }
29 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | android.enableJetifier=true
20 | # Kotlin code style for this project: "official" or "obsolete":
21 | kotlin.code.style=official
22 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/anupamchugh/AndroidTfLiteCameraX/399aae7324da005801dc4651e27ef6ef3ec0dfa3/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Wed Oct 30 08:09:09 IST 2019
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='AndroidTfliteCameraX'
3 |
--------------------------------------------------------------------------------