Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-286
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
1
Merge Requests
1
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
2023-286
2023-286
Commits
64f8ace8
Commit
64f8ace8
authored
May 27, 2023
by
Fernando M.I.N IT20016616
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added collecting signs .py file
parent
fec76e3d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
105 additions
and
0 deletions
+105
-0
.DS_Store
.DS_Store
+0
-0
Collecting_data/collect_data_for_signs.py
Collecting_data/collect_data_for_signs.py
+105
-0
No files found.
.DS_Store
0 → 100644
View file @
64f8ace8
File added
Collecting_data/collect_data_for_signs.py
0 → 100644
View file @
64f8ace8
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import
cv2
import
numpy
as
np
import
os
import
string
# Create the directory structure
if
not
os
.
path
.
exists
(
"data"
):
os
.
makedirs
(
"data"
)
if
not
os
.
path
.
exists
(
"data/train"
):
os
.
makedirs
(
"data/train"
)
if
not
os
.
path
.
exists
(
"data/test"
):
os
.
makedirs
(
"data/test"
)
for
i
in
range
(
3
):
if
not
os
.
path
.
exists
(
"data/train/"
+
str
(
i
)):
os
.
makedirs
(
"data/train/"
+
str
(
i
))
if
not
os
.
path
.
exists
(
"data/test/"
+
str
(
i
)):
os
.
makedirs
(
"data/test/"
+
str
(
i
))
# Train or test
mode
=
'train'
directory
=
'data/'
+
mode
+
'/'
minValue
=
70
cap
=
cv2
.
VideoCapture
(
0
)
interrupt
=
-
1
while
True
:
_
,
frame
=
cap
.
read
()
# Simulating mirror image
frame
=
cv2
.
flip
(
frame
,
1
)
# Getting count of existing images
count
=
{
'zero'
:
len
(
os
.
listdir
(
directory
+
"/0"
)),
'one'
:
len
(
os
.
listdir
(
directory
+
"/1"
)),
'two'
:
len
(
os
.
listdir
(
directory
+
"/2"
))
}
# Printing the count in each set to the screen
# cv2.putText(frame, "MODE : "+mode, (10, 50), cv2.FONT_HERSHEY_PLAIN, 1, (0,255,255), 1)
# cv2.putText(frame, "IMAGE COUNT", (10, ), cv2.FONT_HERSHEY_PLAIN, 1, (0,255,255), 1)
cv2
.
putText
(
frame
,
"ZERO : "
+
str
(
count
[
'zero'
]),
(
10
,
70
),
cv2
.
FONT_HERSHEY_PLAIN
,
1
,
(
0
,
255
,
255
),
1
)
cv2
.
putText
(
frame
,
"ONE : "
+
str
(
count
[
'one'
]),
(
10
,
80
),
cv2
.
FONT_HERSHEY_PLAIN
,
1
,
(
0
,
255
,
255
),
1
)
cv2
.
putText
(
frame
,
"TWO : "
+
str
(
count
[
'two'
]),
(
10
,
90
),
cv2
.
FONT_HERSHEY_PLAIN
,
1
,
(
0
,
255
,
255
),
1
)
# Coordinates of the ROI
x1
=
int
(
0.5
*
frame
.
shape
[
1
])
y1
=
10
x2
=
frame
.
shape
[
1
]
-
10
y2
=
int
(
0.5
*
frame
.
shape
[
1
])
# Drawing the ROI
# The increment/decrement by 1 is to compensate for the bounding box
cv2
.
rectangle
(
frame
,
(
220
-
1
,
9
),
(
620
+
1
,
419
),
(
255
,
0
,
0
)
,
1
)
# Extracting the ROI
roi
=
frame
[
10
:
410
,
220
:
520
]
# roi = cv2.resize(roi, (64, 64))
cv2
.
imshow
(
"Frame"
,
frame
)
gray
=
cv2
.
cvtColor
(
roi
,
cv2
.
COLOR_BGR2GRAY
)
blur
=
cv2
.
GaussianBlur
(
gray
,(
5
,
5
),
2
)
# #blur = cv2.bilateralFilter(roi,9,75,75)
th3
=
cv2
.
adaptiveThreshold
(
blur
,
255
,
cv2
.
ADAPTIVE_THRESH_GAUSSIAN_C
,
cv2
.
THRESH_BINARY_INV
,
11
,
2
)
ret
,
test_image
=
cv2
.
threshold
(
th3
,
minValue
,
255
,
cv2
.
THRESH_BINARY_INV
+
cv2
.
THRESH_OTSU
)
#time.sleep(5)
#cv2.imwrite("/home/rc/Downloads/soe/im1.jpg", roi)
#test_image = func("/home/rc/Downloads/soe/im1.jpg")
test_image
=
cv2
.
resize
(
test_image
,
(
300
,
300
))
cv2
.
imshow
(
"test"
,
test_image
)
interrupt
=
cv2
.
waitKey
(
10
)
if
interrupt
&
0xFF
==
27
:
# esc key
break
if
interrupt
&
0xFF
==
ord
(
'0'
):
cv2
.
imwrite
(
directory
+
'0/'
+
str
(
count
[
'zero'
])
+
'.jpg'
,
roi
)
if
interrupt
&
0xFF
==
ord
(
'1'
):
cv2
.
imwrite
(
directory
+
'1/'
+
str
(
count
[
'one'
])
+
'.jpg'
,
roi
)
if
interrupt
&
0xFF
==
ord
(
'2'
):
cv2
.
imwrite
(
directory
+
'2/'
+
str
(
count
[
'two'
])
+
'.jpg'
,
roi
)
cap
.
release
()
cv2
.
destroyAllWindows
()
# In[ ]:
# In[ ]:
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