Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
exapunks-hackmatch-bot
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
Taddeüs Kroes
exapunks-hackmatch-bot
Commits
6cadb61c
Commit
6cadb61c
authored
Apr 04, 2020
by
Taddeüs Kroes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add screenshot analysis utility
parent
7e2942ed
Pipeline
#31
failed with stages
in 1 minute and 2 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
0 deletions
+52
-0
analyze.py
analyze.py
+52
-0
No files found.
analyze.py
0 → 100755
View file @
6cadb61c
#!/usr/bin/env python3
import
os
import
numpy
as
np
from
PIL
import
Image
from
parser
import
BLOCK_SIZE
,
COLUMN_VSHIFT
,
MIN_COLUMN_VAL
,
MIN_COLUMN_SAT
,
\
detect_blocks
,
detect_exa
,
detect_held
,
print_board
,
\
detect_columns
from
strategy
import
State
def
cut_board
(
board
):
y
=
detect_columns
(
board
)
-
BLOCK_SIZE
i
=
row
=
0
while
y
>=
0
:
for
col
,
shift
in
enumerate
(
COLUMN_VSHIFT
):
x
=
col
*
BLOCK_SIZE
block
=
board
.
crop
((
x
,
y
+
shift
,
x
+
BLOCK_SIZE
,
y
+
shift
+
BLOCK_SIZE
))
yield
col
,
row
,
block
i
+=
1
y
-=
BLOCK_SIZE
row
+=
1
def
make_bitmap
(
board
):
h
,
s
,
v
=
board
.
split
()
v
=
[
int
(
v
>
MIN_COLUMN_VAL
and
s
>
MIN_COLUMN_SAT
)
*
255
for
h
,
s
,
v
in
zip
(
h
.
getdata
(),
s
.
getdata
(),
v
.
getdata
())]
v
=
Image
.
fromarray
(
np
.
uint8
(
v
).
reshape
((
board
.
height
,
board
.
width
)))
return
Image
.
merge
(
'RGB'
,
(
v
,
v
,
v
))
if
__name__
==
'__main__'
:
import
sys
ident
=
int
(
sys
.
argv
[
1
])
extensive
=
sys
.
argv
[
2
]
==
'y'
if
len
(
sys
.
argv
)
>
2
else
False
board
=
Image
.
open
(
'screens/board%d.png'
%
ident
).
convert
(
'HSV'
)
#board.crop((0, 0, board.width, detect_columns(board))).show()
state
=
State
.
detect
(
board
)
blocks
=
list
(
detect_blocks
(
board
))
exa
=
detect_exa
(
board
)
held
=
detect_held
(
board
,
exa
)
print_board
(
blocks
,
exa
,
held
)
if
extensive
:
make_bitmap
(
board
).
save
(
'screens/bitmap%d.png'
%
ident
)
os
.
makedirs
(
'blocks/board%d'
%
ident
,
exist_ok
=
True
)
for
row
,
col
,
block
in
cut_board
(
board
):
f
=
'blocks/board%d/row%d-col%d.png'
%
(
ident
,
row
,
col
)
block
.
convert
(
'RGB'
).
save
(
f
)
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