Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
wheel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
benjamin.sitbon
wheel
Commits
b7128b84
Commit
b7128b84
authored
5 years ago
by
benjamin.sitbon
Browse files
Options
Downloads
Patches
Plain Diff
Un peu d'ordre dans le code
parent
fc34dcd3
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
wheel.py
+66
-37
66 additions, 37 deletions
wheel.py
with
66 additions
and
37 deletions
wheel.py
+
66
−
37
View file @
b7128b84
...
@@ -4,12 +4,18 @@ import cv2
...
@@ -4,12 +4,18 @@ import cv2
import
time
import
time
import
numpy
as
np
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
matplotlib.pyplot
as
plt
import
cmath
as
math
#Variables utile pour trouver le centre de nos legos
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
"
-v
"
,
"
--video
"
,
help
=
"
path to the video file
"
)
ap
.
add_argument
(
"
-a
"
,
"
--min-area
"
,
type
=
int
,
default
=
500
,
help
=
"
minimum area size
"
)
args
=
vars
(
ap
.
parse_args
())
def
nothing
(
x
):
def
nothing
(
x
):
pass
pass
def
calc_
angle
(
x1
,
y1
,
x2
,
y2
):
def
angle
(
x1
,
y1
,
x2
,
y2
):
if
x2
-
x1
==
0
:
if
x2
-
x1
==
0
:
return
0
return
0
...
@@ -21,48 +27,71 @@ def find_center(mask):
...
@@ -21,48 +27,71 @@ def find_center(mask):
cnts
=
cv2
.
findContours
(
mask
.
copy
(),
cv2
.
RETR_EXTERNAL
,
cv2
.
CHAIN_APPROX_SIMPLE
)
cnts
=
cv2
.
findContours
(
mask
.
copy
(),
cv2
.
RETR_EXTERNAL
,
cv2
.
CHAIN_APPROX_SIMPLE
)
cnts
=
imutils
.
grab_contours
(
cnts
)
cnts
=
imutils
.
grab_contours
(
cnts
)
c
x
=
0
x
=
0
c
y
=
0
y
=
0
for
c
in
cnts
:
for
c
in
cnts
:
if
cv2
.
contourArea
(
c
)
>
args
[
"
min_area
"
]:
if
cv2
.
contourArea
(
c
)
>
args
[
"
min_area
"
]:
M
=
cv2
.
moments
(
c
)
M
=
cv2
.
moments
(
c
)
c
x
=
int
(
M
[
"
m10
"
]
/
M
[
"
m00
"
])
x
=
int
(
M
[
"
m10
"
]
/
M
[
"
m00
"
])
c
y
=
int
(
M
[
"
m01
"
]
/
M
[
"
m00
"
])
y
=
int
(
M
[
"
m01
"
]
/
M
[
"
m00
"
])
return
c
x
,
c
y
return
x
,
y
cap
=
cv2
.
VideoCapture
(
'
wheel_racing.avi
'
)
# video
ap
=
argparse
.
ArgumentParser
()
ap
.
add_argument
(
"
-v
"
,
"
--video
"
,
help
=
"
path to the video file
"
)
ap
.
add_argument
(
"
-a
"
,
"
--min-area
"
,
type
=
int
,
default
=
500
,
help
=
"
minimum area size
"
)
args
=
vars
(
ap
.
parse_args
())
angles
=
np
.
array
([])
temps
=
np
.
array
([])
count
=
0
cv2
.
namedWindow
(
'
red
'
)
def
Red_Trackbars
():
cv2
.
namedWindow
(
'
orange
'
)
cv2
.
namedWindow
(
'
main
'
)
cv2
.
createTrackbar
(
'
red_h_min
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
red_h_min
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
red_h_min
'
,
'
red
'
,
170
)
cv2
.
createTrackbar
(
'
red_s_min
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
red_s_min
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
red_s_min
'
,
'
red
'
,
145
)
cv2
.
createTrackbar
(
'
red_v_min
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
red_v_min
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
red_v_min
'
,
'
red
'
,
220
)
cv2
.
createTrackbar
(
'
red_h_max
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
red_h_max
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
red_h_max
'
,
'
red
'
,
179
)
cv2
.
createTrackbar
(
'
red_s_max
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
red_s_max
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
red_s_max
'
,
'
red
'
,
255
)
cv2
.
createTrackbar
(
'
red_v_max
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
red_v_max
'
,
'
red
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
red_v_max
'
,
'
red
'
,
255
)
def
Orange_Trackbars
():
cv2
.
createTrackbar
(
'
orange_h_min
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
orange_h_min
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
orange_h_min
'
,
'
orange
'
,
10
)
cv2
.
createTrackbar
(
'
orange_s_min
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
orange_s_min
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
orange_s_min
'
,
'
orange
'
,
120
)
cv2
.
createTrackbar
(
'
orange_v_min
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
orange_v_min
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
orange_v_min
'
,
'
orange
'
,
240
)
cv2
.
createTrackbar
(
'
orange_h_max
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
orange_h_max
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
orange_h_max
'
,
'
orange
'
,
35
)
cv2
.
createTrackbar
(
'
orange_s_max
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
orange_s_max
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
orange_s_max
'
,
'
orange
'
,
255
)
cv2
.
createTrackbar
(
'
orange_v_max
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
createTrackbar
(
'
orange_v_max
'
,
'
orange
'
,
0
,
255
,
nothing
)
cv2
.
setTrackbarPos
(
'
orange_v_max
'
,
'
orange
'
,
255
)
cap
=
cv2
.
VideoCapture
(
'
wheel_racing.avi
'
)
# video
tab_ang
=
np
.
array
([])
sec
=
np
.
array
([])
count
=
0
cv2
.
namedWindow
(
'
red
'
)
cv2
.
namedWindow
(
'
orange
'
)
cv2
.
namedWindow
(
'
main
'
)
Red_Trackbars
()
Orange_Trackbars
()
while
True
:
while
True
:
...
@@ -106,17 +135,17 @@ while True:
...
@@ -106,17 +135,17 @@ while True:
kernel
=
np
.
ones
((
5
,
5
),
np
.
uint8
)
kernel
=
np
.
ones
((
5
,
5
),
np
.
uint8
)
#
rempli les trou dans les objets
#
Il arrivait d'avoir des zones noir dans le carré, j'ai donc tenté de remplir avec une fermeture
mask_red
=
cv2
.
morphologyEx
(
RedMask
,
cv2
.
MORPH_CLOSE
,
kernel
)
RedMask
=
cv2
.
morphologyEx
(
RedMask
,
cv2
.
MORPH_CLOSE
,
kernel
)
mask_o
range
=
cv2
.
morphologyEx
(
OrangeMask
,
cv2
.
MORPH_CLOSE
,
kernel
)
O
range
Mask
=
cv2
.
morphologyEx
(
OrangeMask
,
cv2
.
MORPH_CLOSE
,
kernel
)
x1
,
y1
=
find_center
(
mask_red
)
x1
,
y1
=
find_center
(
RedMask
)
x2
,
y2
=
find_center
(
mask_o
range
)
x2
,
y2
=
find_center
(
O
range
Mask
)
ang
le
=
calc_
angle
(
x1
,
y1
,
x2
,
y2
)
ang
=
angle
(
x1
,
y1
,
x2
,
y2
)
ang
les
=
np
.
append
(
ang
les
,
ang
le
)
tab_
ang
=
np
.
append
(
tab_
ang
,
ang
)
temps
=
np
.
append
(
temps
,
count
)
sec
=
np
.
append
(
sec
,
count
)
count
+=
1
count
+=
1
cv2
.
imshow
(
'
main
'
,
mask
)
cv2
.
imshow
(
'
main
'
,
mask
)
...
@@ -139,6 +168,6 @@ while True:
...
@@ -139,6 +168,6 @@ while True:
cap
.
release
()
cap
.
release
()
cv2
.
destroyAllWindows
()
cv2
.
destroyAllWindows
()
plt
.
plot
(
temps
,
angles
,
'
g
'
)
plt
.
plot
(
sec
,
tab_ang
,
'
g
'
)
plt
.
yscale
(
'
linear
'
)
plt
.
yscale
(
'
linear
'
)
plt
.
show
()
plt
.
show
()
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment