Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Pokedex
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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
michael.divia
Pokedex
Commits
a4d04f4e
Commit
a4d04f4e
authored
1 month ago
by
michael.divia
Browse files
Options
Downloads
Patches
Plain Diff
Show image on screen
parent
e642f085
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
python/pokedex_rpi.py
+15
-3
15 additions, 3 deletions
python/pokedex_rpi.py
with
15 additions
and
3 deletions
python/pokedex_rpi.py
+
15
−
3
View file @
a4d04f4e
...
@@ -2,6 +2,7 @@ import cv2
...
@@ -2,6 +2,7 @@ import cv2
import
numpy
as
np
import
numpy
as
np
import
json
import
json
import
argparse
import
argparse
import
os
from
hailo_platform.pyhailort
import
HailoRT
from
hailo_platform.pyhailort
import
HailoRT
# --- Argparse ---
# --- Argparse ---
...
@@ -47,13 +48,24 @@ if not ret:
...
@@ -47,13 +48,24 @@ if not ret:
print
(
"
-- Failed to capture image
"
)
print
(
"
-- Failed to capture image
"
)
exit
(
1
)
exit
(
1
)
# --- Try to display the captured image ---
try
:
cv2
.
imshow
(
"
Captured Image
"
,
frame
)
print
(
"
-- Press any key to continue...
"
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
except
cv2
.
error
as
e
:
print
(
"
-- GUI display failed, saving and showing with feh instead...
"
)
output_path
=
"
/tmp/captured.png
"
cv2
.
imwrite
(
output_path
,
frame
)
os
.
system
(
f
"
feh --fullscreen
{
output_path
}
"
)
# --- Preprocess image ---
# --- Preprocess image ---
image
=
cv2
.
resize
(
frame
,
input_shape
)
image
=
cv2
.
resize
(
frame
,
input_shape
)
image
=
image
.
astype
(
np
.
float32
)
image
=
image
.
astype
(
np
.
float32
)
# Standard Hailo normalization
(if your model expects ImageNet style)
# Standard Hailo normalization
image
-=
[
123.68
,
116.779
,
103.939
]
image
-=
[
123.68
,
116.779
,
103.939
]
# image /= 255.0 # only if your model was trained with [0,1] normalization
# NHWC → NCHW
# NHWC → NCHW
image
=
np
.
transpose
(
image
,
(
2
,
0
,
1
))
# (H, W, C) → (C, H, W)
image
=
np
.
transpose
(
image
,
(
2
,
0
,
1
))
# (H, W, C) → (C, H, W)
...
@@ -67,4 +79,4 @@ with HailoRT.VirtualStreams(input_info, output_info, network_group) as (input_vs
...
@@ -67,4 +79,4 @@ with HailoRT.VirtualStreams(input_info, output_info, network_group) as (input_vs
# --- Postprocess ---
# --- Postprocess ---
predicted_idx
=
int
(
np
.
argmax
(
output_data
))
predicted_idx
=
int
(
np
.
argmax
(
output_data
))
predicted_name
=
class_names
[
predicted_idx
]
predicted_name
=
class_names
[
predicted_idx
]
print
(
f
"
🎯
Predicted Pokémon:
{
predicted_name
}
"
)
print
(
f
"
--
Predicted Pokémon:
{
predicted_name
}
"
)
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