Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-235 Vehicle parking system
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
3
Merge Requests
3
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-235
2022-235 Vehicle parking system
Commits
d0d57bc4
Commit
d0d57bc4
authored
Nov 14, 2022
by
@Thilakasiri_M.D.T.S
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update component 2
parent
2ee7f4df
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
41 additions
and
4 deletions
+41
-4
component_2/__pycache__/parking_violation.cpython-38.pyc
component_2/__pycache__/parking_violation.cpython-38.pyc
+0
-0
component_2/out/out.png
component_2/out/out.png
+0
-0
component_2/parking_violation.py
component_2/parking_violation.py
+25
-4
component_2/sample_data/0.JPG
component_2/sample_data/0.JPG
+0
-0
component_2/sample_data/1.JPG
component_2/sample_data/1.JPG
+0
-0
component_2/test.py
component_2/test.py
+16
-0
No files found.
component_2/__pycache__/parking_violation.cpython-38.pyc
View file @
d0d57bc4
No preview for this file type
component_2/out/out.png
0 → 100644
View file @
d0d57bc4
1.38 MB
component_2/parking_violation.py
View file @
d0d57bc4
...
@@ -7,7 +7,7 @@ import random
...
@@ -7,7 +7,7 @@ import random
model_vehicle
=
torch
.
hub
.
load
(
'ultralytics/yolov5'
,
'yolov5s'
)
model_vehicle
=
torch
.
hub
.
load
(
'ultralytics/yolov5'
,
'yolov5s'
)
guide_line_database
=
[
527
,
215
,
611
,
345
]
# sample guideline
guide_line_database
=
[
180
,
270
,
520
,
750
]
# sample guideline
def
is_inside
(
x1
,
y1
,
x1b
,
y1b
,
x2
,
y2
,
x2b
,
y2b
):
def
is_inside
(
x1
,
y1
,
x1b
,
y1b
,
x2
,
y2
,
x2b
,
y2b
):
...
@@ -18,9 +18,12 @@ def is_inside(x1, y1, x1b, y1b, x2, y2, x2b, y2b):
...
@@ -18,9 +18,12 @@ def is_inside(x1, y1, x1b, y1b, x2, y2, x2b, y2b):
def
is_vehicle_parked_correctly
(
slot_index
=
0
):
def
is_vehicle_parked_correctly
(
slot_index
=
0
):
# sample_imgs = os.listdir('sample_data')
sample_imgs
=
os
.
listdir
(
'component_2/sample_data'
)
sample_imgs
=
os
.
listdir
(
'component_2/sample_data'
)
# read_filename = 'sample_data/' + str(random.choice(sample_imgs))
img
=
cv2
.
imread
(
'component_2/sample_data/'
+
str
(
random
.
choice
(
sample_imgs
)))
read_filename
=
'component_2/sample_data/'
+
str
(
random
.
choice
(
sample_imgs
))
img
=
cv2
.
imread
(
read_filename
)
# img = cv2.imread('component_2/sample_data/' + str(random.choice(sample_imgs)))
result
=
model_vehicle
(
img
)
result
=
model_vehicle
(
img
)
json_string
=
result
.
pandas
()
.
xyxy
[
0
]
.
to_json
(
orient
=
'records'
)
json_string
=
result
.
pandas
()
.
xyxy
[
0
]
.
to_json
(
orient
=
'records'
)
...
@@ -34,14 +37,32 @@ def is_vehicle_parked_correctly(slot_index=0):
...
@@ -34,14 +37,32 @@ def is_vehicle_parked_correctly(slot_index=0):
y
=
int
(
i
[
"ymin"
])
y
=
int
(
i
[
"ymin"
])
w
=
int
(
i
[
"xmax"
])
w
=
int
(
i
[
"xmax"
])
h
=
int
(
i
[
"ymax"
])
h
=
int
(
i
[
"ymax"
])
name
=
i
[
"name"
]
# cv2.rectangle(img, (x, y), (w, h), (0, 255, 0), 2)
# print((x, y), (w, h))
# cv2.rectangle(img, (guide_line_database[0], guide_line_database[1]),
# (guide_line_database[2], guide_line_database[3]), (0, 0, 255), 2)
# cv2.imwrite('out/out.png', img)
object_list
.
append
([
x
,
y
,
w
,
h
])
object_list
.
append
([
x
,
y
,
w
,
h
])
if
len
(
json_obj
)
==
0
:
if
len
(
json_obj
)
==
0
:
return
True
cv2
.
putText
(
img
,
'Correct'
,
(
20
,
20
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.9
,
(
0
,
255
,
0
),
2
)
cv2
.
imwrite
(
'out/out.png'
,
img
)
return
True
,
read_filename
if
is_inside
(
object_list
[
slot_index
][
0
],
object_list
[
slot_index
][
1
],
object_list
[
slot_index
][
2
],
object_list
[
slot_index
][
3
],
guide_line_database
[
0
],
guide_line_database
[
1
],
guide_line_database
[
2
],
guide_line_database
[
3
]):
cv2
.
putText
(
img
,
'Correct'
,
(
20
,
20
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.9
,
(
0
,
255
,
0
),
2
)
cv2
.
imwrite
(
'out/out.png'
,
img
)
else
:
cv2
.
putText
(
img
,
'Incorrect'
,
(
20
,
20
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
0.9
,
(
0
,
0
,
255
),
2
)
cv2
.
imwrite
(
'out/out.png'
,
img
)
return
is_inside
(
object_list
[
slot_index
][
0
],
object_list
[
slot_index
][
1
],
object_list
[
slot_index
][
2
],
return
is_inside
(
object_list
[
slot_index
][
0
],
object_list
[
slot_index
][
1
],
object_list
[
slot_index
][
2
],
object_list
[
slot_index
][
3
],
guide_line_database
[
0
],
guide_line_database
[
1
],
guide_line_database
[
2
],
object_list
[
slot_index
][
3
],
guide_line_database
[
0
],
guide_line_database
[
1
],
guide_line_database
[
2
],
guide_line_database
[
3
])
guide_line_database
[
3
])
# print(is_vehicle_parked_correctly())
# print(is_vehicle_parked_correctly())
component_2/sample_data/0.JPG
0 → 100644
View file @
d0d57bc4
282 KB
component_2/sample_data/1.JPG
0 → 100644
View file @
d0d57bc4
292 KB
component_2/test.py
0 → 100644
View file @
d0d57bc4
import
cv2
img
=
cv2
.
imread
(
'sample_data/0001.jpg'
)
img
=
cv2
.
resize
(
img
,
(
630
,
420
))
cv2
.
imwrite
(
'1.jpg'
,
img
)
print
(
img
.
shape
)
img2
=
cv2
.
imread
(
'sample_data/0002.jpg'
)
img2
=
cv2
.
resize
(
img2
,
(
630
,
420
))
cv2
.
imwrite
(
'2.jpg'
,
img2
)
print
(
img2
.
shape
)
img3
=
cv2
.
imread
(
'sample_data/0003.jpg'
)
img3
=
cv2
.
resize
(
img3
,
(
630
,
420
))
cv2
.
imwrite
(
'3.jpg'
,
img3
)
print
(
img3
.
shape
)
\ No newline at end of file
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