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
dd241b2e
Commit
dd241b2e
authored
Nov 05, 2020
by
Buwaneka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add SeperateNumbers.java
parent
82164848
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
234 additions
and
0 deletions
+234
-0
Count/SeperateNumbers.java
Count/SeperateNumbers.java
+234
-0
No files found.
Count/SeperateNumbers.java
0 → 100644
View file @
dd241b2e
package
com.example.count
;
import
android.content.ContextWrapper
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.ColorMatrix
;
import
android.graphics.ColorMatrixColorFilter
;
import
android.graphics.Paint
;
import
java.util.ArrayList
;
import
java.util.List
;
public
class
SeperateNumbers
{
public
Bitmap
getResizedBitmap
(
Bitmap
image
,
int
maxSize
)
{
int
width
=
image
.
getWidth
();
int
height
=
image
.
getHeight
();
float
bitmapRatio
=
(
float
)
width
/
(
float
)
height
;
if
(
bitmapRatio
>
1
)
{
width
=
maxSize
;
height
=
(
int
)
(
width
/
bitmapRatio
);
}
else
{
height
=
maxSize
;
width
=
(
int
)
(
height
*
bitmapRatio
);
}
return
Bitmap
.
createScaledBitmap
(
image
,
width
,
height
,
true
);
}
public
Bitmap
toGrayscale
(
Bitmap
bmpOriginal
)
{
int
width
,
height
;
height
=
bmpOriginal
.
getHeight
();
width
=
bmpOriginal
.
getWidth
();
Bitmap
bmpGrayscale
=
Bitmap
.
createBitmap
(
width
,
height
,
Bitmap
.
Config
.
ARGB_8888
);
Canvas
c
=
new
Canvas
(
bmpGrayscale
);
Paint
paint
=
new
Paint
();
ColorMatrix
cm
=
new
ColorMatrix
();
cm
.
setSaturation
(
0
);
ColorMatrixColorFilter
f
=
new
ColorMatrixColorFilter
(
cm
);
paint
.
setColorFilter
(
f
);
c
.
drawBitmap
(
bmpOriginal
,
0
,
0
,
paint
);
return
bmpGrayscale
;
}
public
Bitmap
BlackAndWite
(
Bitmap
src
){
GlobleVariable
.
bitmapArrayPicture
.
clear
();
int
width
=
src
.
getWidth
();
int
height
=
src
.
getHeight
();
Bitmap
grayBit
=
toGrayscale
(
src
);
Bitmap
grayBitTT
=
toGrayscale
(
src
);
int
britColor
=
100
;
int
LoopCount
=
0
;
List
<
Integer
>
listy
=
new
ArrayList
();
List
<
Integer
>
listx
=
new
ArrayList
();
List
<
Integer
>
listyM
=
new
ArrayList
();
List
<
Integer
>
listxM
=
new
ArrayList
();
boolean
Loop
=
true
;
boolean
oneCheck
=
true
;
boolean
done
=
false
;
while
(
Loop
){
if
((!
listxM
.
isEmpty
()
&&
listxM
.
size
()<
26
)
||
(!
listyM
.
isEmpty
()
&&
listyM
.
size
()<
27
)
){
britColor
=
britColor
-
5
;
oneCheck
=
false
;
}
if
(
oneCheck
){
if
((!
listxM
.
isEmpty
()
&&
listxM
.
size
()>
26
)
||
(!
listyM
.
isEmpty
()
&&
listyM
.
size
()>
27
)){
britColor
=
britColor
+
5
;
}
}
if
(
LoopCount
>
4
){
Loop
=
false
;
}
LoopCount
++;
listx
.
clear
();
listxM
.
clear
();
listy
.
clear
();
listyM
.
clear
();
int
a
=
0
;
for
(
int
y
=
0
;
y
<
height
;
++
y
)
{
Boolean
flag
=
true
;
int
county
=
0
;
for
(
int
x
=
0
;
x
<
width
;
++
x
)
{
// get pixel color
int
gray
=
Color
.
red
(
grayBit
.
getPixel
(
x
,
y
));
if
(
gray
<
britColor
)
{
county
++;
gray
=
0
;
if
(
county
>
25
){
flag
=
false
;
}
}
else
{
gray
=
255
;
}
grayBitTT
.
setPixel
(
x
,
y
,
Color
.
rgb
(
gray
,
gray
,
gray
));
}
if
(
flag
){
if
(
listy
.
isEmpty
()){
listy
.
add
(
y
);
a
=
y
;
}
else
{
if
(!(
a
+
1
==
y
)){
if
((
listy
.
contains
(
a
))
){
listy
.
add
(
y
);
a
=
y
;
}
else
{
listy
.
add
(
a
);
listy
.
add
(
y
);
a
=
y
;
}
}
else
{
a
=
a
+
1
;
}
}
}
}
a
=
0
;
for
(
int
x
=
0
;
x
<
width
;
++
x
)
{
Boolean
flag
=
true
;
int
countx
=
0
;
for
(
int
y
=
0
;
y
<
height
;
++
y
)
{
// get pixel color
int
gray
=
Color
.
red
(
grayBit
.
getPixel
(
x
,
y
));
if
(
gray
<
britColor
)
{
countx
++;
if
(
countx
>
50
){
flag
=
false
;
break
;
}
}
}
if
(
flag
){
if
(
listx
.
isEmpty
()){
listx
.
add
(
x
);
a
=
x
;
}
else
{
if
(!(
a
+
1
==
x
)){
if
((
listx
.
contains
(
a
))
){
listx
.
add
(
x
);
a
=
x
;
}
else
{
listx
.
add
(
a
);
listx
.
add
(
x
);
a
=
x
;
}
}
else
{
a
=
a
+
1
;
}
}
}
}
listy
.
add
(
height
);
listx
.
add
(
width
);
for
(
int
x
=
0
;
x
<
listx
.
size
()-
1
;
x
=
x
+
2
){
listxM
.
add
((
int
)(
listx
.
get
(
x
)+
listx
.
get
(
x
+
1
))/
2
);
}
for
(
int
x
=
0
;
x
<
listy
.
size
()-
1
;
x
=
x
+
2
){
listyM
.
add
((
int
)(
listy
.
get
(
x
)+
listy
.
get
(
x
+
1
))/
2
);
}
boolean
flagchceck
=
true
;
if
(
listxM
.
size
()==
26
&&
listyM
.
size
()==
27
){
int
countCheckx
=
0
;
for
(
int
x
=
0
;
x
<
26
;
x
++)
{
for
(
int
y
=
0
;
y
<
height
;
++
y
)
{
int
gray
=
Color
.
red
(
grayBit
.
getPixel
(
listxM
.
get
(
x
),
y
));
if
(
gray
<
britColor
)
{
countCheckx
++;
if
(
countCheckx
>
50
){
flagchceck
=
false
;
break
;
}
}
}
}
int
countChecky
=
0
;
for
(
int
y
=
0
;
y
<
27
;
++
y
)
{
for
(
int
x
=
0
;
x
<
width
;
++
x
)
{
int
gray
=
Color
.
red
(
grayBit
.
getPixel
(
x
,
listyM
.
get
(
y
)));
if
(
gray
<
britColor
)
{
countChecky
++;
if
(
countChecky
>
25
){
flagchceck
=
false
;
break
;
}
}
}
}
}
if
(
listxM
.
size
()==
26
&&
listyM
.
size
()==
27
&&
flagchceck
){
for
(
int
x
=
0
;
x
<
listxM
.
size
();
x
++)
{
for
(
int
y
=
0
;
y
<
height
;
y
++)
{
src
.
setPixel
(
listxM
.
get
(
x
),
y
,
Color
.
rgb
(
0
,
0
,
0
));
}
}
for
(
int
x
=
0
;
x
<
listyM
.
size
();
x
++)
{
for
(
int
y
=
0
;
y
<
width
;
y
++)
{
src
.
setPixel
(
y
,
listyM
.
get
(
x
),
Color
.
rgb
(
0
,
0
,
0
));
}
}
for
(
int
y
=
0
;
y
<
26
;
y
++){
for
(
int
x
=
0
;
x
<
25
;
x
++){
Bitmap
resizedbitmap1
=
Bitmap
.
createBitmap
(
src
,
listxM
.
get
(
x
),
listyM
.
get
(
y
),
listxM
.
get
(
x
+
1
)-
listxM
.
get
(
x
),
listyM
.
get
(
y
+
1
)-
listyM
.
get
(
y
));
GlobleVariable
.
bitmapArrayPicture
.
add
(
resizedbitmap1
);
}
}
Loop
=
false
;
done
=
true
;
}
}
GlobleVariable
.
done
=
done
;
return
src
;
}
}
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