Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-81
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
2022-81
2022-81
Commits
66338fc4
Commit
66338fc4
authored
Nov 11, 2022
by
P.Y.D Jayasinghe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Identification Added
parent
d158fc43
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
417 additions
and
8 deletions
+417
-8
app/build.gradle
app/build.gradle
+1
-1
app/src/main/AndroidManifest.xml
app/src/main/AndroidManifest.xml
+15
-0
app/src/main/java/com/example/eketha/MainActivity.java
app/src/main/java/com/example/eketha/MainActivity.java
+7
-7
app/src/main/java/com/example/eketha/WeedHome.java
app/src/main/java/com/example/eketha/WeedHome.java
+45
-0
app/src/main/java/com/example/eketha/WeedMain.java
app/src/main/java/com/example/eketha/WeedMain.java
+159
-0
app/src/main/res/drawable/weedseg.png
app/src/main/res/drawable/weedseg.png
+0
-0
app/src/main/res/layout/activity_weed_home.xml
app/src/main/res/layout/activity_weed_home.xml
+119
-0
app/src/main/res/layout/activity_weed_main.xml
app/src/main/res/layout/activity_weed_main.xml
+71
-0
No files found.
app/build.gradle
View file @
66338fc4
...
...
@@ -23,7 +23,7 @@ android {
}
python
{
buildPython
"
C:/p
ython/python.exe"
buildPython
"
D:/P
ython/python.exe"
pip
{
install
"opencv-contrib-python-headless"
install
"pillow"
...
...
app/src/main/AndroidManifest.xml
View file @
66338fc4
...
...
@@ -18,11 +18,26 @@
<application
android:allowBackup=
"true"
android:hardwareAccelerated=
"false"
android:icon=
"@drawable/logo"
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:theme=
"@style/Theme.EKetha"
>
<activity
android:name=
".WeedMain"
android:exported=
"false"
>
<meta-data
android:name=
"android.app.lib_name"
android:value=
""
/>
</activity>
<activity
android:name=
".WeedHome"
android:exported=
"false"
>
<meta-data
android:name=
"android.app.lib_name"
android:value=
""
/>
</activity>
<activity
android:name=
".PaddyArea.PaddyAreaView_04"
android:exported=
"false"
/>
...
...
app/src/main/java/com/example/eketha/MainActivity.java
View file @
66338fc4
...
...
@@ -43,13 +43,13 @@ public class MainActivity extends AppCompatActivity {
// }
// });
//
//
cardView2.setOnClickListener(new View.OnClickListener() {
//
@Override
//
public void onClick(View view) {
// Intent intent = new Intent(getApplicationContext(),w
eedHome.class);
//
startActivity(intent);
//
}
//
});
cardView2
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
(
getApplicationContext
(),
W
eedHome
.
class
);
startActivity
(
intent
);
}
});
//
cardView3
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
...
...
app/src/main/java/com/example/eketha/WeedHome.java
0 → 100644
View file @
66338fc4
package
com.example.eketha
;
import
androidx.appcompat.app.AppCompatActivity
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.view.View
;
import
android.widget.LinearLayout
;
import
android.widget.Toast
;
public
class
WeedHome
extends
AppCompatActivity
{
private
LinearLayout
layer1
,
layer2
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_weed_home
);
layer1
=
findViewById
(
R
.
id
.
layer2
);
layer2
=
findViewById
(
R
.
id
.
layer3
);
layer1
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
intent
=
new
Intent
(
getApplicationContext
(),
WeedMain
.
class
);
startActivity
(
intent
);
}
});
layer2
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
launchIntent
=
getPackageManager
().
getLaunchIntentForPackage
(
"org.tensorflow.lite.examples.imagesegmentation"
);
if
(
launchIntent
!=
null
)
{
startActivity
(
launchIntent
);
}
else
{
Toast
.
makeText
(
getApplicationContext
(),
"There is no package available in android"
,
Toast
.
LENGTH_LONG
).
show
();
}
}
});
}
}
\ No newline at end of file
app/src/main/java/com/example/eketha/WeedMain.java
0 → 100644
View file @
66338fc4
package
com.example.eketha
;
import
androidx.annotation.NonNull
;
import
androidx.annotation.Nullable
;
import
androidx.annotation.RequiresApi
;
import
androidx.appcompat.app.AppCompatActivity
;;
import
com.example.eketha.ml.Modelres
;
import
android.Manifest
;
import
android.content.Intent
;
import
android.content.pm.PackageManager
;
import
android.graphics.Bitmap
;
import
android.media.ThumbnailUtils
;
import
android.net.Uri
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.provider.MediaStore
;
import
android.view.View
;
import
android.widget.Button
;
import
android.widget.ImageView
;
import
android.widget.TextView
;
import
org.tensorflow.lite.DataType
;
import
org.tensorflow.lite.support.label.Category
;
import
org.tensorflow.lite.support.tensorbuffer.TensorBuffer
;
import
java.io.IOException
;
import
java.nio.ByteBuffer
;
import
java.nio.ByteOrder
;
import
java.util.Comparator
;
import
java.util.List
;
public
class
WeedMain
extends
AppCompatActivity
{
Button
camera
,
gallery
;
ImageView
imageView
;
TextView
result
;
int
imageSize
=
224
;
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_weed_main
);
camera
=
findViewById
(
R
.
id
.
btnTakePictureWeed
);
gallery
=
findViewById
(
R
.
id
.
btnLaunchGalleryweed
);
result
=
findViewById
(
R
.
id
.
classifiedWeed
);
imageView
=
findViewById
(
R
.
id
.
imageViewWeed
);
camera
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
M
)
@Override
public
void
onClick
(
View
view
)
{
if
(
checkSelfPermission
(
Manifest
.
permission
.
CAMERA
)
==
PackageManager
.
PERMISSION_GRANTED
)
{
Intent
cameraIntent
=
new
Intent
(
MediaStore
.
ACTION_IMAGE_CAPTURE
);
startActivityForResult
(
cameraIntent
,
3
);
}
else
{
requestPermissions
(
new
String
[]{
Manifest
.
permission
.
CAMERA
},
100
);
}
}
});
gallery
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
Intent
cameraIntent
=
new
Intent
(
Intent
.
ACTION_PICK
,
MediaStore
.
Images
.
Media
.
EXTERNAL_CONTENT_URI
);
startActivityForResult
(
cameraIntent
,
1
);
}
});
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
N
)
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
@Nullable
Intent
data
)
{
if
(
resultCode
==
RESULT_OK
){
if
(
requestCode
==
3
){
Bitmap
image
=
(
Bitmap
)
data
.
getExtras
().
get
(
"data"
);
int
dimension
=
Math
.
min
(
image
.
getWidth
(),
image
.
getHeight
());
image
=
ThumbnailUtils
.
extractThumbnail
(
image
,
dimension
,
dimension
);
imageView
.
setImageBitmap
(
image
);
image
=
Bitmap
.
createScaledBitmap
(
image
,
imageSize
,
imageSize
,
false
);
classifyImage
(
image
);
}
else
{
Uri
dat
=
data
.
getData
();
Bitmap
image
=
null
;
try
{
image
=
MediaStore
.
Images
.
Media
.
getBitmap
(
this
.
getContentResolver
(),
dat
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
imageView
.
setImageBitmap
(
image
);
image
=
Bitmap
.
createScaledBitmap
(
image
,
imageSize
,
imageSize
,
false
);
classifyImage
(
image
);
}
}
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
}
@RequiresApi
(
api
=
Build
.
VERSION_CODES
.
N
)
public
void
classifyImage
(
Bitmap
image
){
try
{
Modelres
model
=
Modelres
.
newInstance
(
getApplicationContext
());
// Creates inputs for reference.
TensorBuffer
inputFeature0
=
TensorBuffer
.
createFixedSize
(
new
int
[]{
1
,
224
,
224
,
3
},
DataType
.
UINT8
);
ByteBuffer
byteBuffer
=
ByteBuffer
.
allocateDirect
(
1
*
imageSize
*
imageSize
*
3
);
byteBuffer
.
order
(
ByteOrder
.
nativeOrder
());
int
[]
intValues
=
new
int
[
imageSize
*
imageSize
];
image
.
getPixels
(
intValues
,
0
,
image
.
getWidth
(),
0
,
0
,
image
.
getWidth
(),
image
.
getHeight
());
int
pixel
=
0
;
//iterate over each pixel and extract R, G, and B values. Add those values individually to the byte buffer.
for
(
int
i
=
0
;
i
<
imageSize
;
i
++){
for
(
int
j
=
0
;
j
<
imageSize
;
j
++){
int
val
=
intValues
[
pixel
++];
// RGB
byteBuffer
.
put
((
byte
)
(((
val
>>
16
)
&
0xFF
)
*
(
1
.
f
/
1
)));
byteBuffer
.
put
((
byte
)
(((
val
>>
8
)
&
0xFF
)
*
(
1
.
f
/
1
)));
byteBuffer
.
put
((
byte
)
((
val
&
0xFF
)
*
(
1
.
f
/
1
)));
}
}
inputFeature0
.
loadBuffer
(
byteBuffer
);
// Runs model inference and gets result.
Modelres
.
Outputs
outputs
=
model
.
process
(
inputFeature0
);
List
<
Category
>
probability
=
outputs
.
getProbabilityAsCategoryList
();
//TensorBuffer outputFeature0 = (TensorBuffer) outputs.getProbabilityAsCategoryList();
// find the index of the class with the biggest confidence.
// int maxPos = 0;
// float maxConfidence = 0;
// for (int i = 0; i < probability.size(); i++) {
// if (probability.get(i) > maxConfidence) {
// maxConfidence = probability[i];
// maxPos = i;
// }
// }
// String[] classes = {"unlabeled", "weed", "rice","sand"};
// result.setText(classes[maxPos]);
probability
.
sort
(
Comparator
.
comparing
(
Category:
:
getScore
,
Comparator
.
reverseOrder
()));
for
(
int
i
=
0
;
i
<
3
;
i
++)
result
.
setText
(
probability
.
get
(
i
).
getLabel
()
+
" : "
+
probability
.
get
(
i
).
getScore
());
// Releases model resources if no longer used.
model
.
close
();
}
catch
(
IOException
e
)
{
// TODO Handle the exception
}
}
}
\ No newline at end of file
app/src/main/res/drawable/weedseg.png
0 → 100644
View file @
66338fc4
2.45 MB
app/src/main/res/layout/activity_weed_home.xml
0 → 100644
View file @
66338fc4
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
tools:context=
".weedHome"
>
<LinearLayout
android:id=
"@+id/layer1"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
<ImageView
android:layout_width=
"150dp"
android:layout_height=
"150dp"
android:layout_marginLeft=
"120dp"
android:layout_marginTop=
"30dp"
app:srcCompat=
"@drawable/logo"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"match_parent"
android:text=
"Weed Management"
android:textColor=
"@color/black"
android:layout_marginTop=
"10dp"
android:layout_marginLeft=
"80dp"
android:textSize=
"30dp"
/>
</LinearLayout>
<androidx.cardview.widget.CardView
android:layout_width=
"match_parent"
android:layout_height=
"173dp"
android:layout_marginRight=
"30dp"
app:cardCornerRadius=
"8dp"
android:layout_marginTop=
"30dp"
android:layout_marginLeft=
"30dp"
>
<LinearLayout
android:id=
"@+id/layer2"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
android:background=
"@color/black"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:layout_marginLeft=
"30dp"
android:layout_marginTop=
"20dp"
android:layout_marginRight=
"30dp"
>
<ImageView
android:layout_width=
"100dp"
android:layout_height=
"100dp"
android:layout_marginLeft=
"10dp"
android:layout_marginTop=
"10dp"
app:srcCompat=
"@drawable/weeds"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textSize=
"24dp"
android:layout_marginLeft=
"20dp"
android:layout_marginTop=
"36dp"
android:textColor=
"@color/white"
android:text=
"Weed Identification"
/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView
android:layout_width=
"match_parent"
android:layout_height=
"173dp"
android:layout_marginRight=
"30dp"
app:cardCornerRadius=
"8dp"
android:layout_marginTop=
"30dp"
android:layout_marginLeft=
"30dp"
>
<LinearLayout
android:id=
"@+id/layer3"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:orientation=
"vertical"
android:background=
"@color/black"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:layout_marginLeft=
"30dp"
android:layout_marginTop=
"20dp"
android:layout_marginRight=
"30dp"
>
<ImageView
android:layout_width=
"100dp"
android:layout_height=
"100dp"
android:layout_marginLeft=
"10dp"
android:layout_marginTop=
"10dp"
app:srcCompat=
"@drawable/weedseg"
/>
<TextView
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textSize=
"24dp"
android:layout_marginLeft=
"20dp"
android:layout_marginTop=
"36dp"
android:textColor=
"@color/white"
android:text=
"Weed Segmentation"
/>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/activity_weed_main.xml
0 → 100644
View file @
66338fc4
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:tools=
"http://schemas.android.com/tools"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_margin=
"10dp"
tools:context=
".WeedMain"
>
<ImageView
android:id=
"@+id/imageViewWeed"
android:layout_width=
"370sp"
android:layout_height=
"370sp"
android:layout_centerHorizontal=
"true"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toTopOf=
"parent"
/>
<TextView
android:id=
"@+id/classifiedWeed"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/imageViewWeed"
android:layout_centerHorizontal=
"true"
android:layout_marginTop=
"16dp"
android:text=
"Classified Weed:"
android:textSize=
"20sp"
android:textStyle=
"bold"
app:layout_constraintEnd_toEndOf=
"parent"
app:layout_constraintHorizontal_bias=
"0.497"
app:layout_constraintStart_toStartOf=
"parent"
app:layout_constraintTop_toBottomOf=
"@+id/imageViewWeed"
/>
<TextView
android:id=
"@+id/resultPests"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_below=
"@+id/classifiedWeed"
android:layout_centerHorizontal=
"true"
android:text=
""
android:textColor=
"#C30000"
android:textSize=
"27sp"
android:textStyle=
"bold"
/>
<Button
android:id=
"@+id/btnTakePictureWeed"
android:layout_width=
"match_parent"
android:layout_height=
"68dp"
android:layout_above=
"@id/btnLaunchGalleryweed"
android:layout_centerInParent=
"true"
android:text=
"Take Picture"
android:textAllCaps=
"false"
android:textSize=
"21sp"
android:textStyle=
"bold"
tools:layout_editor_absoluteX=
"-52dp"
tools:layout_editor_absoluteY=
"529dp"
/>
<Button
android:id=
"@+id/btnLaunchGalleryweed"
android:layout_width=
"match_parent"
android:layout_height=
"68dp"
android:layout_alignParentBottom=
"true"
android:layout_centerInParent=
"true"
android:text=
"Launch Gallery"
android:textAllCaps=
"false"
android:textSize=
"21sp"
android:textStyle=
"bold"
tools:layout_editor_absoluteX=
"-52dp"
tools:layout_editor_absoluteY=
"444dp"
/>
</RelativeLayout>
\ No newline at end of file
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