Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J-84
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
KSH.Mohamed
22_23-J-84
Commits
c427696e
Commit
c427696e
authored
Jan 30, 2023
by
Bogahawatta L.B.G.D.P.K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update demo.py
parent
b542c8df
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
1 deletion
+88
-1
demo.py
demo.py
+88
-1
No files found.
demo.py
View file @
c427696e
jh
/
)
gjrjjh
ٚ
hX
*
e
֬
[
gz
\ No newline at end of file
import
cv2
import
numpy
as
np
import
matplotlib.pyplot
as
plt
net
=
cv2
.
dnn
.
readNetFromDarknet
(
"yolov3_training.cfg"
,
r"yolov3_training_10000.weights"
)
# Name custom object
classes
=
[
"Car"
,
"Van"
,
"Number Plate"
,
"Bicycle"
,
"MotorCycles"
,
"Lorry"
,
"HeavyLorry"
,
"Bus"
,
"Hand Tractors"
,
"Land Vehicle"
,
"JCB"
,
"Threewheel"
]
cap
=
cv2
.
VideoCapture
(
"vehicle3.asf"
)
while
1
:
_
,
img
=
cap
.
read
()
img
=
cv2
.
resize
(
img
,(
1280
,
720
))
hight
,
width
,
_
=
img
.
shape
blob
=
cv2
.
dnn
.
blobFromImage
(
img
,
1
/
255
,(
416
,
416
),(
0
,
0
,
0
),
swapRB
=
True
,
crop
=
False
)
net
.
setInput
(
blob
)
output_layers_name
=
net
.
getUnconnectedOutLayersNames
()
layerOutputs
=
net
.
forward
(
output_layers_name
)
boxes
=
[]
confidences
=
[]
class_ids
=
[]
for
output
in
layerOutputs
:
for
detection
in
output
:
score
=
detection
[
5
:]
class_id
=
np
.
argmax
(
score
)
confidence
=
score
[
class_id
]
if
confidence
>
0.7
:
center_x
=
int
(
detection
[
0
]
*
width
)
center_y
=
int
(
detection
[
1
]
*
hight
)
w
=
int
(
detection
[
2
]
*
width
)
h
=
int
(
detection
[
3
]
*
hight
)
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
,
.5
,
.4
)
boxes
=
[]
confidences
=
[]
class_ids
=
[]
for
output
in
layerOutputs
:
for
detection
in
output
:
score
=
detection
[
5
:]
class_id
=
np
.
argmax
(
score
)
confidence
=
score
[
class_id
]
if
confidence
>
0.5
:
center_x
=
int
(
detection
[
0
]
*
width
)
center_y
=
int
(
detection
[
1
]
*
hight
)
w
=
int
(
detection
[
2
]
*
width
)
h
=
int
(
detection
[
3
]
*
hight
)
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
,
.8
,
.4
)
font
=
cv2
.
FONT_HERSHEY_PLAIN
colors
=
np
.
random
.
uniform
(
0
,
255
,
size
=
(
len
(
boxes
),
3
))
if
len
(
indexes
)
>
0
:
for
i
in
indexes
.
flatten
():
x
,
y
,
w
,
h
=
boxes
[
i
]
label
=
str
(
classes
[
class_ids
[
i
]])
confidence
=
str
(
round
(
confidences
[
i
],
2
))
color
=
colors
[
i
]
cv2
.
rectangle
(
img
,(
x
,
y
),(
x
+
w
,
y
+
h
),
color
,
2
)
cv2
.
putText
(
img
,
label
+
" "
+
confidence
,
(
x
,
y
+
400
),
font
,
2
,
color
,
2
)
cv2
.
imshow
(
'img'
,
img
)
if
cv2
.
waitKey
(
1
)
==
ord
(
'q'
):
break
cap
.
release
()
cv2
.
destroyAllWindows
()
\ 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