Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Module_10_Project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review 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
Ştefan, R.P. (Răzvan, Student B-TCS)
Module_10_Project
Commits
4269f2ab
Commit
4269f2ab
authored
4 months ago
by
razvan841
Committed by
Niccolo de Vries
4 months ago
Browse files
Options
Downloads
Patches
Plain Diff
added debugging
parent
838d3459
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
raspberryPi.py
+35
-3
35 additions, 3 deletions
raspberryPi.py
with
35 additions
and
3 deletions
raspberryPi.py
+
35
−
3
View file @
4269f2ab
...
...
@@ -3,6 +3,8 @@ import numpy as np
from
tensorflow.keras.models
import
load_model
# type: ignore
import
os
DEBUGGING
=
True
def
extract_patches
(
image
):
height
,
width
,
_
=
image
.
shape
square_height
=
height
//
3
...
...
@@ -31,6 +33,20 @@ def predict_colors(model, image):
predicted_colors
=
[
np
.
argmax
(
pred
)
for
pred
in
predictions
]
return
predicted_colors
def
indices_to_colors
(
indices
):
"""
Converts an array of indices into a list of color names.
Args:
indices (list of int): List of color indices predicted by the model.
Returns:
list of str: List of color names corresponding to the indices.
"""
color_map
=
{
0
:
'
white
'
,
1
:
'
yellow
'
,
2
:
'
red
'
,
3
:
'
blue
'
,
4
:
'
green
'
,
5
:
'
orange
'
}
return
[
color_map
[
idx
]
for
idx
in
indices
]
def
main
():
model_path
=
"
rubiks_cube_model.h5
"
if
not
os
.
path
.
exists
(
model_path
):
...
...
@@ -58,9 +74,25 @@ def main():
# Wait for the user to press 'c' to capture or 'q' to quit
key
=
cv2
.
waitKey
(
1
)
&
0xFF
if
key
==
ord
(
'
c
'
):
print
(
"
Processing captured image...
"
)
predicted_colors
=
predict_colors
(
model
,
frame
)
print
(
"
Predicted Colors:
"
,
predicted_colors
)
# Show the captured image to the user
while
True
:
cv2
.
imshow
(
"
Captured Image - Press
'
y
'
to proceed or
'
r
'
to retake
"
,
frame
)
key_confirm
=
cv2
.
waitKey
(
0
)
&
0xFF
if
key_confirm
==
ord
(
'
y
'
):
print
(
"
Processing captured image...
"
)
predicted_colors
=
predict_colors
(
model
,
frame
)
colors
=
None
if
(
DEBUGGING
):
colors
=
indices_to_colors
(
predicted_colors
)
print
(
colors
)
else
:
print
(
"
Predicted Colors:
"
,
predicted_colors
)
break
# Exit confirmation loop and return to live feed
elif
key_confirm
==
ord
(
'
r
'
):
print
(
"
Retaking the picture...
"
)
break
# Retake the picture
elif
key
==
ord
(
'
q
'
):
print
(
"
Exiting...
"
)
break
...
...
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