Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-104
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-104
2022-104
Commits
80e70fec
Commit
80e70fec
authored
Nov 14, 2022
by
P.M.P.C Bandara
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Live measures file added
parent
1d11de18
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
0 deletions
+66
-0
Live_measures.py
Live_measures.py
+66
-0
No files found.
Live_measures.py
0 → 100644
View file @
80e70fec
import
cv2
from
object_detector
import
*
import
numpy
as
np
# Load Aruco detector
parameters
=
cv2
.
aruco
.
DetectorParameters_create
()
aruco_dict
=
cv2
.
aruco
.
Dictionary_get
(
cv2
.
aruco
.
DICT_5X5_50
)
# Load Object Detector
detector
=
HomogeneousBgDetector
()
# Load Cap
cap
=
cv2
.
VideoCapture
(
'http://192.168.8.126:8080/video'
)
#cap = cv2.VideoCapture(0)
cap
.
set
(
cv2
.
CAP_PROP_FRAME_WIDTH
,
1280
)
cap
.
set
(
cv2
.
CAP_PROP_FRAME_HEIGHT
,
720
)
while
True
:
_
,
img
=
cap
.
read
()
# Get Aruco marker
corners
,
_
,
_
=
cv2
.
aruco
.
detectMarkers
(
img
,
aruco_dict
,
parameters
=
parameters
)
if
corners
:
# Draw polygon around the marker
int_corners
=
np
.
int0
(
corners
)
cv2
.
polylines
(
img
,
int_corners
,
True
,
(
0
,
255
,
0
),
5
)
# Aruco Perimeter
aruco_perimeter
=
cv2
.
arcLength
(
corners
[
0
],
True
)
# Pixel to cm ratio
pixel_cm_ratio
=
aruco_perimeter
/
20
contours
=
detector
.
detect_objects
(
img
)
# Draw objects boundaries
for
cnt
in
contours
:
# Get rect
rect
=
cv2
.
minAreaRect
(
cnt
)
(
x
,
y
),
(
w
,
h
),
angle
=
rect
# Get Width and Height of the Objects by applying the Ratio pixel to cm
object_width
=
w
/
pixel_cm_ratio
object_height
=
h
/
pixel_cm_ratio
# Display rectangle
box
=
cv2
.
boxPoints
(
rect
)
box
=
np
.
int0
(
box
)
cv2
.
circle
(
img
,
(
int
(
x
),
int
(
y
)),
5
,
(
0
,
0
,
255
),
-
1
)
cv2
.
polylines
(
img
,
[
box
],
True
,
(
255
,
0
,
0
),
2
)
cv2
.
putText
(
img
,
"Width {} cm"
.
format
(
round
(
object_width
,
1
)),
(
int
(
x
-
100
),
int
(
y
-
20
)),
cv2
.
FONT_HERSHEY_PLAIN
,
2
,
(
100
,
200
,
0
),
2
)
cv2
.
putText
(
img
,
"Length {} cm"
.
format
(
round
(
object_height
,
1
)),
(
int
(
x
-
100
),
int
(
y
+
15
)),
cv2
.
FONT_HERSHEY_PLAIN
,
2
,
(
100
,
200
,
0
),
2
)
cv2
.
imshow
(
"Image"
,
img
)
key
=
cv2
.
waitKey
(
1
)
if
key
==
27
:
break
cap
.
release
()
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