Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
Code Computer Vision
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Jira
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
PolySTAR
RoboMaster
Computer Vision
Code Computer Vision
Commits
92bda7e7
Commit
92bda7e7
authored
4 years ago
by
Mathieu Beligon
Browse files
Options
Downloads
Patches
Plain Diff
[CV2ResultsViewer] Add callback support
parent
48bbd821
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/polystar/view/cv2_results_viewer.py
+17
-3
17 additions, 3 deletions
src/polystar/view/cv2_results_viewer.py
with
17 additions
and
3 deletions
src/polystar/view/cv2_results_viewer.py
+
17
−
3
View file @
92bda7e7
from
contextlib
import
suppress
from
typing
import
Any
,
Callable
,
Dict
import
cv2
import
cv2
import
numpy
as
np
import
numpy
as
np
...
@@ -23,10 +26,12 @@ COLORS = [
...
@@ -23,10 +26,12 @@ COLORS = [
(
23
,
190
,
207
),
(
23
,
190
,
207
),
]
# seaborn.color_palette() * 255
]
# seaborn.color_palette() * 255
Callback
=
Callable
[[],
Any
]
class
CV2ResultViewer
(
ResultViewerABC
):
class
CV2ResultViewer
(
ResultViewerABC
):
def
__init__
(
self
,
name
:
str
,
delay
:
int
=
1
,
end_key
s
:
str
=
"
q
"
):
def
__init__
(
self
,
name
:
str
,
delay
:
int
=
1
,
end_key
:
str
=
"
q
"
,
key_callbacks
:
Dict
[
str
,
Callback
]
=
None
):
self
.
end_keys
=
[
ord
(
c
)
for
c
in
end_keys
]
self
.
keycode_callbacks
=
self
.
_make_keycode_callbacks
(
end_key
,
key_callbacks
or
{})
self
.
delay
=
delay
self
.
delay
=
delay
self
.
name
=
name
self
.
name
=
name
self
.
_current_image
:
Image
=
None
self
.
_current_image
:
Image
=
None
...
@@ -70,4 +75,13 @@ class CV2ResultViewer(ResultViewerABC):
...
@@ -70,4 +75,13 @@ class CV2ResultViewer(ResultViewerABC):
def
display
(
self
):
def
display
(
self
):
cv2
.
imshow
(
self
.
name
,
self
.
_current_image
)
cv2
.
imshow
(
self
.
name
,
self
.
_current_image
)
self
.
finished
=
cv2
.
waitKey
(
self
.
delay
)
&
0xFF
in
self
.
end_keys
keycode
=
cv2
.
waitKey
(
self
.
delay
)
&
0xFF
with
suppress
(
KeyError
):
self
.
keycode_callbacks
[
keycode
]()
def
stop
(
self
):
self
.
finished
=
True
def
_make_keycode_callbacks
(
self
,
end_key
:
str
,
key_callbacks
:
Dict
[
str
,
Callback
])
->
Dict
[
int
,
Callback
]:
key_callbacks
[
end_key
]
=
self
.
stop
return
{
ord
(
k
):
f
for
k
,
f
in
key_callbacks
.
items
()}
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
register
or
sign in
to comment