Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
Secure smart parking solution
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
2021-122
Secure smart parking solution
Commits
1db2d2ab
Commit
1db2d2ab
authored
May 10, 2021
by
Methsarani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
vehicle detection main file add
parent
caf587a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
+62
-0
main.py
main.py
+62
-0
No files found.
main.py
0 → 100644
View file @
1db2d2ab
import
cv2
import
numpy
as
np
# Load Yolo
net
=
cv2
.
dnn
.
readNet
(
"yolov3.weights"
,
"yolov3.cfg"
)
classes
=
[]
with
open
(
"coco.names"
,
"r"
)
as
f
:
classes
=
[
line
.
strip
()
for
line
in
f
.
readlines
()]
layer_names
=
net
.
getLayerNames
()
output_layers
=
[
layer_names
[
i
[
0
]
-
1
]
for
i
in
net
.
getUnconnectedOutLayers
()]
colors
=
np
.
random
.
uniform
(
0
,
255
,
size
=
(
len
(
classes
),
3
))
# Loading image
img
=
cv2
.
imread
(
"car_park.jpg"
)
img
=
cv2
.
resize
(
img
,
None
,
fx
=
0.7
,
fy
=
0.7
)
height
,
width
,
channels
=
img
.
shape
# Detecting objects
blob
=
cv2
.
dnn
.
blobFromImage
(
img
,
0.00392
,
(
416
,
416
),
(
0
,
0
,
0
),
True
,
crop
=
False
)
net
.
setInput
(
blob
)
outs
=
net
.
forward
(
output_layers
)
# Showing informations on the screen
class_ids
=
[]
confidences
=
[]
boxes
=
[]
for
out
in
outs
:
for
detection
in
out
:
scores
=
detection
[
5
:]
class_id
=
np
.
argmax
(
scores
)
confidence
=
scores
[
class_id
]
if
confidence
>
0.5
:
# Object detected
center_x
=
int
(
detection
[
0
]
*
width
)
center_y
=
int
(
detection
[
1
]
*
height
)
w
=
int
(
detection
[
2
]
*
width
)
h
=
int
(
detection
[
3
]
*
height
)
# Rectangle coordinates
x
=
int
(
center_x
-
w
/
2
)
y
=
int
(
center_y
-
h
/
2
)
boxes
.
append
([
x
,
y
,
w
,
h
])
confidences
.
append
(
float
(
confidence
))
class_ids
.
append
(
class_id
)
indexes
=
cv2
.
dnn
.
NMSBoxes
(
boxes
,
confidences
,
0.5
,
0.4
)
font
=
cv2
.
FONT_HERSHEY_PLAIN
for
i
in
range
(
len
(
boxes
)):
if
i
in
indexes
:
x
,
y
,
w
,
h
=
boxes
[
i
]
label
=
str
(
classes
[
class_ids
[
i
]])
color
=
colors
[
i
]
cv2
.
rectangle
(
img
,
(
x
,
y
),
(
x
+
w
,
y
+
h
),
color
,
2
)
cv2
.
putText
(
img
,
label
,
(
x
,
y
+
30
),
font
,
3
,
color
,
3
)
cv2
.
imshow
(
"Image"
,
img
)
cv2
.
waitKey
(
0
)
cv2
.
destroyAllWindows
()
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