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
d80297fd
Commit
d80297fd
authored
4 years ago
by
Mathieu Beligon
Browse files
Options
Downloads
Patches
Plain Diff
[demo] add toggle for communication
parent
92bda7e7
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/polystar/communication/togglabe_cs_link.py
+16
-0
16 additions, 0 deletions
src/polystar/communication/togglabe_cs_link.py
src/research/scripts/demo_pipeline_camera.py
+39
-24
39 additions, 24 deletions
src/research/scripts/demo_pipeline_camera.py
with
55 additions
and
24 deletions
src/polystar/communication/togglabe_cs_link.py
0 → 100644
+
16
−
0
View file @
d80297fd
from
polystar.communication.command
import
Command
from
polystar.communication.cs_link_abc
import
CSLinkABC
class
TogglableCSLink
(
CSLinkABC
):
def
__init__
(
self
,
cs_link
:
CSLinkABC
,
is_on
:
bool
):
self
.
is_on
=
is_on
self
.
cs_link
=
cs_link
def
send_command
(
self
,
command
:
Command
):
if
not
self
.
is_on
:
return
self
.
cs_link
.
send_command
(
command
)
def
toggle
(
self
):
self
.
is_on
=
not
self
.
is_on
This diff is collapsed.
Click to expand it.
src/research/scripts/demo_pipeline_camera.py
+
39
−
24
View file @
d80297fd
from
injector
import
inject
from
polystar.communication.cs_link_abc
import
CSLinkABC
from
polystar.communication.togglabe_cs_link
import
TogglableCSLink
from
polystar.dependency_injection
import
make_injector
from
polystar.frame_generators.frames_generator_abc
import
FrameGeneratorABC
from
polystar.models.image
import
Image
from
polystar.target_pipeline.debug_pipeline
import
DebugTargetPipeline
from
polystar.target_pipeline.target_pipeline
import
NoTargetFoundException
from
polystar.utils.fps
import
FPS
from
polystar.view.cv2_results_viewer
import
CV2ResultViewer
@inject
def
demo_pipeline_on_camera
(
pipeline
:
DebugTargetPipeline
,
webcam
:
FrameGeneratorABC
,
cs_link
:
CSLinkABC
):
fps
,
pipeline_fps
=
FPS
(),
FPS
()
with
CV2ResultViewer
(
"
TensorRT demo
"
)
as
viewer
:
persistence_last_detection
:
int
=
0
for
image
in
webcam
.
generate
():
pipeline_fps
.
skip
()
try
:
target
=
pipeline
.
predict_target
(
image
)
cs_link
.
send_target
(
target
)
persistence_last_detection
=
5
except
NoTargetFoundException
:
if
persistence_last_detection
:
persistence_last_detection
-=
1
else
:
cs_link
.
send_no_target
()
pipeline_fps
.
tick
(),
fps
.
tick
()
viewer
.
add_debug_info
(
pipeline
.
debug_info_
)
viewer
.
add_text
(
f
"
FPS:
{
fps
:
.
1
f
}
/
{
pipeline_fps
:
.
1
f
}
"
,
10
,
10
,
(
0
,
0
,
0
))
viewer
.
display
()
fps
.
skip
()
if
viewer
.
finished
:
return
class
CameraPipelineDemo
:
@inject
def
__init__
(
self
,
pipeline
:
DebugTargetPipeline
,
webcam
:
FrameGeneratorABC
,
cs_link
:
CSLinkABC
):
self
.
cs_link
=
TogglableCSLink
(
cs_link
,
is_on
=
False
)
self
.
webcam
=
webcam
self
.
pipeline
=
pipeline
self
.
fps
,
self
.
pipeline_fps
=
FPS
(),
FPS
()
self
.
persistence_last_detection
=
0
def
run
(
self
):
with
CV2ResultViewer
(
"
TensorRT demo
"
,
key_callbacks
=
{
"
"
:
self
.
cs_link
.
toggle
})
as
viewer
:
for
image
in
self
.
webcam
.
generate
():
self
.
pipeline_fps
.
skip
()
self
.
_detect
(
image
)
self
.
pipeline_fps
.
tick
(),
self
.
fps
.
tick
()
self
.
_display
(
viewer
)
self
.
fps
.
skip
()
if
viewer
.
finished
:
return
def
_detect
(
self
,
image
:
Image
):
try
:
target
=
self
.
pipeline
.
predict_target
(
image
)
self
.
cs_link
.
send_target
(
target
)
self
.
persistence_last_detection
=
5
except
NoTargetFoundException
:
if
self
.
persistence_last_detection
:
self
.
persistence_last_detection
-=
1
else
:
self
.
cs_link
.
send_no_target
()
def
_display
(
self
,
viewer
:
CV2ResultViewer
):
viewer
.
add_debug_info
(
self
.
pipeline
.
debug_info_
)
viewer
.
add_text
(
f
"
FPS:
{
self
.
fps
:
.
1
f
}
/
{
self
.
pipeline_fps
:
.
1
f
}
"
,
10
,
10
,
(
0
,
0
,
0
))
viewer
.
add_text
(
"
Communication:
"
+
(
"
[ON]
"
if
self
.
cs_link
.
is_on
else
"
[OFF]
"
),
10
,
30
,
(
0
,
0
,
0
))
viewer
.
display
()
if
__name__
==
"
__main__
"
:
make_injector
().
call_with_injection
(
demo_pipeline_on_camera
)
make_injector
().
get
(
CameraPipelineDemo
).
run
(
)
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