Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
CHILD INTELLIGENT ASSESSMENT TOOL
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2020-046
CHILD INTELLIGENT ASSESSMENT TOOL
Commits
931157a4
Commit
931157a4
authored
Nov 05, 2020
by
Buwaneka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ImageClassification.java
parent
0c833066
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
126 additions
and
0 deletions
+126
-0
Count/ImageClassification.java
Count/ImageClassification.java
+126
-0
No files found.
Count/ImageClassification.java
0 → 100644
View file @
931157a4
package
com.example.count
;
import
android.app.Activity
;
import
android.content.DialogInterface
;
import
android.content.Intent
;
import
android.graphics.Bitmap
;
import
android.net.Uri
;
import
android.os.Bundle
;
import
android.util.Log
;
import
android.widget.Toast
;
import
androidx.annotation.NonNull
;
import
androidx.appcompat.app.AlertDialog
;
import
com.example.count.imageclsicifiaction.Classifier
;
import
com.example.count.imageclsicifiaction.TensorFlowImageClassifier
;
import
java.io.ByteArrayOutputStream
;
import
java.text.SimpleDateFormat
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.Calendar
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.Random
;
import
java.util.TimeZone
;
import
java.util.concurrent.Executor
;
import
java.util.concurrent.Executors
;
public
class
ImageClassification
extends
Activity
{
private
static
final
String
MODEL_PATH
=
"model.tflite"
;
private
static
final
boolean
QUANT
=
false
;
private
static
final
String
LABEL_PATH
=
"labels.txt"
;
private
static
final
int
INPUT_SIZE
=
128
;
private
Classifier
classifier
;
private
Executor
executor
=
Executors
.
newSingleThreadExecutor
();
public
ArrayList
<
Bitmap
>
byteArrayPicture
=
new
ArrayList
<
Bitmap
>();
public
Boolean
Othertype
=
false
;
public
int
OtherImagePosition
;
public
Boolean
DetectOrNot
=
false
;
public
Boolean
DetectOrNotmodel
=
false
;
public
Boolean
freeOrNot
=
false
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
clasifiation_layout
);
backgroundCacification
newbackGP
=
new
backgroundCacification
();
newbackGP
.
start
();
freeOrNot
=
false
;
}
class
backgroundCacification
extends
Thread
{
List
<
Integer
>
listDitect
=
new
ArrayList
<
Integer
>();
List
<
Integer
>
listMarkOnly
=
new
ArrayList
<
Integer
>();
@Override
public
void
run
(){
initTensorFlowAndLoadModel
();
while
(
true
){
if
(
DetectOrNotmodel
){
//GlobleVariable.bitmapArrayPicture.size()
for
(
int
i
=
0
;
i
<
GlobleVariable
.
bitmapArrayPicture
.
size
()
;
i
++)
{
final
Bitmap
bmpimageDetected
=
Bitmap
.
createScaledBitmap
(
GlobleVariable
.
bitmapArrayPicture
.
get
(
i
),
INPUT_SIZE
,
INPUT_SIZE
,
false
);
final
List
<
Classifier
.
Recognition
>
results
=
classifier
.
recognizeImage
(
bmpimageDetected
);
if
(
results
.
get
(
0
).
getTitle
().
equals
(
"Y"
)){
listMarkOnly
.
add
(
i
);
}
final
int
k
=
i
;
try
{
// code runs in a thread
runOnUiThread
(
new
Runnable
()
{
@Override
public
void
run
()
{
Toast
.
makeText
(
ImageClassification
.
this
,
Integer
.
toString
(
k
),
Toast
.
LENGTH_SHORT
).
show
();
}
});
}
catch
(
final
Exception
ex
)
{
Log
.
i
(
"---"
,
"Exception in thread"
);
}
}
break
;
}
}
int
Right
=
0
;
int
Wrong
=
0
;
for
(
int
x
=
0
;
x
<
listMarkOnly
.
size
();
x
++){
if
(
GlobleVariable
.
listOriginal
.
get
(
listMarkOnly
.
get
(
x
))==
3
||
GlobleVariable
.
listOriginal
.
get
(
listMarkOnly
.
get
(
x
))==
4
){
Right
=
Right
+
1
;
}
else
{
Wrong
=
Wrong
+
1
;
}
}
GlobleVariable
.
RightGloble
=
Right
;
GlobleVariable
.
WrongGloble
=
Wrong
;
GlobleVariable
.
resultList
.
add
(
Right
-
Wrong
);
startActivity
(
new
Intent
(
ImageClassification
.
this
,
ResultActivity
.
class
));
}
private
void
initTensorFlowAndLoadModel
()
{
executor
.
execute
(
new
Runnable
()
{
@Override
public
void
run
()
{
try
{
classifier
=
TensorFlowImageClassifier
.
create
(
getAssets
(),
MODEL_PATH
,
LABEL_PATH
,
INPUT_SIZE
,
QUANT
);
DetectOrNotmodel
=
true
;
}
catch
(
final
Exception
e
)
{
throw
new
RuntimeException
(
"Error initializing TensorFlow!"
,
e
);
}
}
});
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment