Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-099
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2022-099
2022-099
Commits
ef799199
Commit
ef799199
authored
Nov 11, 2022
by
R.K.D.M.P.Rathnayake
🎓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
System Initialization Code Done
parent
e7aefecc
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
0 deletions
+90
-0
test.py
test.py
+90
-0
No files found.
test.py
0 → 100644
View file @
ef799199
import
cv2
from
cvzone.HandTrackingModule
import
HandDetector
from
cvzone.ClassificationModule
import
Classifier
import
numpy
as
np
import
math
from
collections
import
Counter
import
time
cap
=
cv2
.
VideoCapture
(
0
)
detector
=
HandDetector
(
maxHands
=
1
)
classifier
=
Classifier
(
"Model/keras_model.h5"
,
"Model/labels.txt"
)
offset
=
20
imgSize
=
300
folder
=
"Data/Yes"
counter
=
0
labels
=
[
"Fine"
,
"Home"
,
"Later"
,
"Law"
,
"Me"
,
"No"
,
"See"
,
"Study"
,
"Thanks"
,
"Visit"
,
"Yes"
]
while
True
:
success
,
img
=
cap
.
read
()
imgOutput
=
img
.
copy
()
hands
,
img
=
detector
.
findHands
(
img
)
if
hands
:
hand
=
hands
[
0
]
x
,
y
,
w
,
h
=
hand
[
'bbox'
]
imgWhite
=
np
.
ones
((
imgSize
,
imgSize
,
3
),
np
.
uint8
)
*
255
imgCrop
=
img
[
y
-
offset
:
y
+
h
+
offset
,
x
-
offset
:
x
+
w
+
offset
]
imgCropShape
=
imgCrop
.
shape
aspectRatio
=
h
/
w
if
aspectRatio
>
1
:
k
=
imgSize
/
h
wCal
=
math
.
ceil
(
k
*
w
)
imgResize
=
cv2
.
resize
(
imgCrop
,
(
wCal
,
imgSize
))
imgResizeShape
=
imgResize
.
shape
wGap
=
math
.
ceil
((
imgSize
-
wCal
)
/
2
)
imgWhite
[:,
wGap
:
wCal
+
wGap
]
=
imgResize
prediction
,
index
=
classifier
.
getPrediction
(
imgWhite
,
draw
=
False
)
print
(
prediction
,
index
)
else
:
k
=
imgSize
/
w
hCal
=
math
.
ceil
(
k
*
h
)
imgResize
=
cv2
.
resize
(
imgCrop
,
(
imgSize
,
hCal
))
imgResizeShape
=
imgResize
.
shape
hGap
=
math
.
ceil
((
imgSize
-
hCal
)
/
2
)
imgWhite
[
hGap
:
hCal
+
hGap
,
:]
=
imgResize
prediction
,
index
=
classifier
.
getPrediction
(
imgWhite
,
draw
=
False
)
cv2
.
rectangle
(
imgOutput
,
(
x
-
offset
,
y
-
offset
-
50
),
(
x
-
offset
+
100
,
y
-
offset
-
50
+
50
),
(
255
,
0
,
255
),
cv2
.
FILLED
)
cv2
.
putText
(
imgOutput
,
labels
[
index
],
(
x
,
y
-
30
),
cv2
.
FONT_HERSHEY_COMPLEX
,
2
,
(
255
,
255
,
255
),
2
)
cv2
.
rectangle
(
imgOutput
,
(
x
-
offset
,
y
-
offset
),
(
x
+
w
+
offset
,
y
+
h
+
offset
),
(
255
,
0
,
255
),
4
)
f
=
open
(
"test.txt"
,
"a"
)
new
=
(
labels
[
index
])
f
.
write
(
new
)
f
.
close
()
array
=
[]
def
word_count
(
filename
):
with
open
(
filename
)
as
f
:
return
Counter
(
f
.
read
()
.
split
())
file
=
"D:/RealTimeSignDetection/test.txt"
counter
=
word_count
(
'D:/RealTimeSignDetection/test.txt'
)
for
i
in
counter
:
array
.
append
(
i
)
sentence
=
' '
.
join
(
array
)
print
(
array
)
print
(
sentence
)
ThisFile
=
open
(
file
,
"w"
)
ThisFile
.
write
(
str
(
sentence
)
+
str
(
"
\n
"
))
cv2
.
imshow
(
"ImageCrop"
,
imgCrop
)
cv2
.
imshow
(
"ImageWhite"
,
imgWhite
)
cv2
.
imshow
(
"Image"
,
imgOutput
)
cv2
.
waitKey
(
1
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment