Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
memory_lib
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
memody_ifs
memory_lib
Commits
4be3470f
Commit
4be3470f
authored
Jul 16, 2021
by
Adrien Lescourt
Browse files
Options
Downloads
Patches
Plain Diff
Separate rising and falling edges
in PieceTakenEdgeDetection
parent
9b3491c9
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
memory_lib/board.py
+11
-9
11 additions, 9 deletions
memory_lib/board.py
memory_lib/memory.py
+3
-3
3 additions, 3 deletions
memory_lib/memory.py
with
14 additions
and
12 deletions
memory_lib/board.py
+
11
−
9
View file @
4be3470f
...
@@ -426,22 +426,24 @@ class ArucoPieceVisibilityDetector:
...
@@ -426,22 +426,24 @@ class ArucoPieceVisibilityDetector:
)
)
class
Average
PieceTakenTrigger
:
class
PieceTaken
DetectionEdges
Trigger
:
"""
Call
'
trigger
'
function when after a piece is taken
"""
Call
'
trigger
'
function when after a piece is taken
It waits for
'
avg
'
times the same piece detection state before triggering
It waits for
'
rising_count
'
times the same piece detection state before triggering when we take a piece
It waits for
'
falling_count
'
times the same piece detection state before triggering when we put back a piece
TODO: replace this average impl with a counter to increase perf
TODO: replace this average impl with a counter to increase perf
"""
"""
def
__init__
(
self
,
trigger
:
Callable
[[
int
],
None
],
avg
:
int
=
5
):
def
__init__
(
self
,
trigger
:
Callable
[[
int
],
None
],
rising_count
:
int
=
5
,
falling_count
:
int
=
5
):
self
.
trigger
=
trigger
self
.
trigger
=
trigger
self
.
avg
=
avg
self
.
rising_count
=
rising_count
self
.
falling_count
=
falling_count
self
.
last_boards
:
List
[
Board
]
=
[]
self
.
last_boards
:
List
[
Board
]
=
[]
self
.
out_board
:
Optional
[
Board
]
=
None
self
.
out_board
:
Optional
[
Board
]
=
None
def
add_board
(
self
,
board
:
Board
)
->
None
:
def
add_board
(
self
,
board
:
Board
)
->
None
:
if
len
(
self
.
last_boards
)
>
self
.
avg
*
2
:
# FIFO size
if
len
(
self
.
last_boards
)
>
max
(
self
.
rising_count
,
self
.
falling_count
)
+
1
:
# FIFO size
self
.
last_boards
.
pop
(
0
)
self
.
last_boards
.
pop
(
0
)
self
.
last_boards
.
append
(
board
)
self
.
last_boards
.
append
(
board
)
self
.
out_board
=
self
.
_average_board
()
self
.
out_board
=
self
.
_average_board
()
...
@@ -449,20 +451,20 @@ class AveragePieceTakenTrigger:
...
@@ -449,20 +451,20 @@ class AveragePieceTakenTrigger:
def
_average_board
(
self
)
->
Board
:
def
_average_board
(
self
)
->
Board
:
next_out_board
=
Board
.
from_board
(
self
.
last_boards
[
-
1
])
next_out_board
=
Board
.
from_board
(
self
.
last_boards
[
-
1
])
for
idx
in
range
(
16
):
for
idx
in
range
(
16
):
avg
=
0
current_count
=
0
for
board
in
self
.
last_boards
:
for
board
in
self
.
last_boards
:
avg
+=
int
(
board
.
pieces
[
idx
].
is_visible
)
current_count
+=
int
(
board
.
pieces
[
idx
].
is_visible
)
if
self
.
out_board
:
if
self
.
out_board
:
if
self
.
out_board
.
pieces
[
idx
].
is_visible
:
if
self
.
out_board
.
pieces
[
idx
].
is_visible
:
if
avg
<
1
:
if
current_count
<
len
(
self
.
last_boards
)
-
self
.
falling_count
:
next_out_board
.
pieces
[
idx
].
is_visible
=
False
next_out_board
.
pieces
[
idx
].
is_visible
=
False
else
:
else
:
next_out_board
.
pieces
[
idx
].
is_visible
=
self
.
out_board
.
pieces
[
next_out_board
.
pieces
[
idx
].
is_visible
=
self
.
out_board
.
pieces
[
idx
idx
].
is_visible
].
is_visible
else
:
else
:
if
avg
>
self
.
avg
:
if
current_count
>
self
.
rising_count
:
next_out_board
.
pieces
[
idx
].
is_visible
=
True
next_out_board
.
pieces
[
idx
].
is_visible
=
True
self
.
trigger
(
idx
)
self
.
trigger
(
idx
)
else
:
else
:
...
...
This diff is collapsed.
Click to expand it.
memory_lib/memory.py
+
3
−
3
View file @
4be3470f
...
@@ -18,7 +18,7 @@ from .board import (
...
@@ -18,7 +18,7 @@ from .board import (
ArucoPieceVisibilityDetector
,
ArucoPieceVisibilityDetector
,
ABMExtractor
,
ABMExtractor
,
AverageColorAndMovementPieceVisibilityDetector
,
AverageColorAndMovementPieceVisibilityDetector
,
Average
PieceTakenTrigger
,
PieceTaken
DetectionEdges
Trigger
,
)
)
from
.model
import
Board
,
PiecesObserver
,
Rect
,
Point
from
.model
import
Board
,
PiecesObserver
,
Rect
,
Point
...
@@ -76,7 +76,7 @@ class MemoryAruco(Memory):
...
@@ -76,7 +76,7 @@ class MemoryAruco(Memory):
self
.
visibility_detector
=
visibility_detector
self
.
visibility_detector
=
visibility_detector
self
.
aruco_dict
=
cv
.
aruco
.
Dictionary_get
(
cv
.
aruco
.
DICT_4X4_250
)
self
.
aruco_dict
=
cv
.
aruco
.
Dictionary_get
(
cv
.
aruco
.
DICT_4X4_250
)
self
.
aruco_params
=
cv
.
aruco
.
DetectorParameters_create
()
self
.
aruco_params
=
cv
.
aruco
.
DetectorParameters_create
()
self
.
average_trigger
=
Average
PieceTakenTrigger
(
self
.
piece_trigger
,
5
)
self
.
average_trigger
=
PieceTaken
DetectionEdges
Trigger
(
self
.
piece_trigger
,
10
,
40
)
self
.
frame_counter
=
0
self
.
frame_counter
=
0
def
process
(
self
,
img
:
np
.
ndarray
)
->
None
:
def
process
(
self
,
img
:
np
.
ndarray
)
->
None
:
...
@@ -118,7 +118,7 @@ class MemoryABM(Memory):
...
@@ -118,7 +118,7 @@ class MemoryABM(Memory):
self
.
abm_extractor
=
abm_extractor
self
.
abm_extractor
=
abm_extractor
self
.
visibility_detector
=
visibility_detector
self
.
visibility_detector
=
visibility_detector
self
.
frame_counter
=
0
self
.
frame_counter
=
0
self
.
average_trigger
=
Average
PieceTakenTrigger
(
self
.
piece_trigger
,
5
)
self
.
average_trigger
=
PieceTaken
DetectionEdges
Trigger
(
self
.
piece_trigger
,
5
)
self
.
last_board
=
None
self
.
last_board
=
None
def
process
(
self
,
img
:
np
.
ndarray
)
->
None
:
def
process
(
self
,
img
:
np
.
ndarray
)
->
None
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
sign in
to comment