Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
plants_detection_counting
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
CI / CD Analytics
Repository Analytics
Value Stream Analytics
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
rupa.lingmore
plants_detection_counting
Commits
21d526e7
Commit
21d526e7
authored
Mar 21, 2022
by
rupa.lingmore
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Upload New File
parent
7c71b4a6
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
78 additions
and
0 deletions
+78
-0
videocount.py
videocount.py
+78
-0
No files found.
videocount.py
0 → 100644
View file @
21d526e7
import
cv2
from
yolov5processor.infer
import
ExecuteInference
import
glob
import
numpy
as
np
#from google.colab.patches import cv2_imshow
yp
=
ExecuteInference
(
weight
=
"E:
\b
uds
\b
est.pt"
,
confidence
=
0.75
,
iou
=
0.45
,
agnostic_nms
=
False
,
img_size
=
416
)
#yp = ExecuteInference(weight=r"E:\buds\best.pt")
vid
=
cv2
.
VideoCapture
(
"E:
\b
uds
\
original video
\
predict.mp4"
)
frame_width
=
int
(
vid
.
get
(
3
))
frame_height
=
int
(
vid
.
get
(
4
))
#count_line_position=550
detect
=
[]
offset
=
6
while
(
True
):
faulty_count
=
0
good_count
=
0
rejected_count
=
0
ret
,
image
=
vid
.
read
()
pred
=
yp
.
predict
(
image
)
print
(
pred
)
for
det
in
pred
:
conf
=
"{:.2f}"
.
format
(
int
(
det
[
'conf'
]
*
100
))
if
int
(
det
[
'conf'
]
*
100
)
>
50
:
# print(det['class'])
label
=
det
[
'class'
]
# print(label.item())
det
=
det
[
'points'
]
if
label
==
"faulty"
:
cv2
.
rectangle
(
image
,
(
int
(
det
[
0
]),
int
(
det
[
1
])),
(
int
(
det
[
2
]),
int
(
det
[
3
])),
(
0
,
0
,
255
),
2
)
cv2
.
putText
(
img
=
image
,
text
=
conf
+
label
,
org
=
(
int
(
det
[
0
]),
int
(
det
[
1
])
-
10
),
color
=
(
0
,
0
,
225
),
thickness
=
3
,
fontScale
=
1
,
fontFace
=
cv2
.
LINE_AA
)
faulty_count
+=
1
elif
label
==
"good"
:
cv2
.
rectangle
(
image
,
(
int
(
det
[
0
]),
int
(
det
[
1
])),
(
int
(
det
[
2
]),
int
(
det
[
3
])),
(
0
,
0
,
255
),
2
)
cv2
.
putText
(
img
=
image
,
text
=
conf
+
label
,
org
=
(
int
(
det
[
0
]),
int
(
det
[
1
])
-
10
),
color
=
(
0
,
0
,
225
),
thickness
=
3
,
fontScale
=
1
,
fontFace
=
cv2
.
LINE_AA
)
good_count
+=
1
else
:
cv2
.
rectangle
(
image
,
(
int
(
det
[
0
]),
int
(
det
[
1
])),
(
int
(
det
[
2
]),
int
(
det
[
3
])),
(
0
,
0
,
255
),
2
)
cv2
.
putText
(
img
=
image
,
text
=
conf
+
label
,
org
=
(
int
(
det
[
0
]),
int
(
det
[
1
])
-
10
),
color
=
(
0
,
0
,
225
),
thickness
=
3
,
fontScale
=
1
,
fontFace
=
cv2
.
LINE_AA
)
rejected_count
+=
1
print
(
f
"good-{good_count}, faulty-{faulty_count}, rejected-{rejected_count}"
)
print
(
"good:"
,
good_count
)
print
(
"faulty:"
,
faulty_count
)
print
(
"rejected:"
,
rejected_count
)
result
=
f
"Good: {good_count}, Faulty: {faulty_count}, Rejected: {rejected_count}"
cv2
.
putText
(
image
,
result
,(
450
,
70
),
cv2
.
FONT_HERSHEY_SIMPLEX
,
2
,(
0
,
0
,
255
),
5
)
cv2
.
imshow
(
'frame'
,
cv2
.
resize
(
image
,
(
720
,
560
)))
#cv2_imshow(cv2.resize(image, (720, 560)))
if
cv2
.
waitKey
(
1
)
&
0xFF
==
ord
(
'q'
):
break
# After the loop release the cap object
vid
.
release
()
# Destroy all the windowsss
\ 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