Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Bildverarbeitung
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
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Moh Kh
Bildverarbeitung
Commits
1e7e12b3
Commit
1e7e12b3
authored
2 years ago
by
Mohammad Khaleeliyeh
Browse files
Options
Downloads
Patches
Plain Diff
Code modified
parent
e876300a
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
filter_images_V5.py
+1
-1
1 addition, 1 deletion
filter_images_V5.py
filter_pipeline.py
+16
-7
16 additions, 7 deletions
filter_pipeline.py
filters.py
+111
-3
111 additions, 3 deletions
filters.py
with
128 additions
and
11 deletions
filter_images_V5.py
+
1
−
1
View file @
1e7e12b3
...
...
@@ -5,7 +5,7 @@ import time
from
datetime
import
datetime
import
pandas
as
pd
VIDEO
=
'
Videomaterial/WIN_20230
414
_1
3
_4
1_55
_Pro.mp4
'
VIDEO
=
'
Videomaterial/WIN_20230
602
_1
4
_4
2_19
_Pro.mp4
'
capture
=
cv2
.
VideoCapture
(
VIDEO
)
...
...
This diff is collapsed.
Click to expand it.
filter_pipeline.py
+
16
−
7
View file @
1e7e12b3
...
...
@@ -4,10 +4,11 @@ import matplotlib.pyplot as plt
import
time
from
datetime
import
datetime
import
pandas
as
pd
import
filters
VIDEO
=
'
Videomaterial/WIN_20230
414_13_41_55
_Pro.mp4
'
VIDEO
=
'
Videomaterial/WIN_20230
602_14_45_52
_Pro.mp4
'
capture
=
cv2
.
VideoCapture
(
VIDEO
)
capture
.
set
(
cv2
.
CAP_PROP_POS_FRAMES
,
30
*
4
0
)
# skip 40 seconds
capture
.
set
(
cv2
.
CAP_PROP_POS_FRAMES
,
30
*
0
)
# skip 40 seconds
last
=
None
frame
=
None
...
...
@@ -34,23 +35,29 @@ def overlay_imgs(base, top):
return
cv2
.
add
(
img1_bg
,
img2_fg
)
def
nothing_cb
(
val
):
pass
# To control the Size of the Disply
cv2
.
namedWindow
(
window
,
cv2
.
WINDOW_
AUTOSIZE
)
cv2
.
createTrackbar
(
'
Canny_Min
'
,
window
,
5
0
,
255
,
nothing_cb
)
cv2
.
createTrackbar
(
'
Canny_Max
'
,
window
,
1
0
0
,
255
,
nothing_cb
)
cv2
.
namedWindow
(
window
,
cv2
.
WINDOW_
NORMAL
)
cv2
.
createTrackbar
(
'
Canny_Min
'
,
window
,
9
0
,
255
,
nothing_cb
)
cv2
.
createTrackbar
(
'
Canny_Max
'
,
window
,
1
5
0
,
255
,
nothing_cb
)
cv2
.
createTrackbar
(
'
Diff_Mix
'
,
window
,
40
,
100
,
nothing_cb
)
cv2
.
createTrackbar
(
'
HSV_Min
'
,
window
,
40
,
255
,
nothing_cb
)
cv2
.
createTrackbar
(
'
HSV_Max
'
,
window
,
100
,
255
,
nothing_cb
)
import
filters
pipeline
=
[
(
'
Original
'
,
filters
.
none
),
#('GreenChannel', filters.greenfilter),
(
'
Gray scale
'
,
filters
.
grayscale
),
(
'
Contrast and Blur
'
,
filters
.
medianBlur
),
(
'
Video Diff Multiple
'
,
filters
.
video_absdiff2
),
(
'
Green filter abs
'
,
filters
.
green_absfilter
),
(
'
Canny edge detection
'
,
filters
.
filter_canny
),
(
'
Morph close
'
,
filters
.
filter_close
),
(
'
gitter_filter
'
,
filters
.
gitter
),
#('Morph open', filters.filter_open),
(
'
Point extraction
'
,
filters
.
points_extract
),
(
'
Polyfit lines
'
,
filters
.
points_overlay
)
...
...
@@ -59,7 +66,7 @@ pipeline = [
state
=
{}
# Empty dictionary to store filters state
info
=
{
'
abs_diff
'
:
3
,
# 3 images for difference,
'
abs_diff
'
:
2
,
# 3 images for difference,
'
dim
'
:
(
1920
,
1080
),
#
'
params
'
:
{}
}
...
...
@@ -76,6 +83,8 @@ while capture.isOpened():
info
[
'
params
'
][
'
mix
'
]
=
cv2
.
getTrackbarPos
(
'
Diff_Mix
'
,
window
)
/
100.0
info
[
'
params
'
][
'
canny_min
'
]
=
cv2
.
getTrackbarPos
(
'
Canny_Min
'
,
window
)
info
[
'
params
'
][
'
canny_max
'
]
=
cv2
.
getTrackbarPos
(
'
Canny_Max
'
,
window
)
info
[
'
params
'
][
'
hsv_min
'
]
=
cv2
.
getTrackbarPos
(
'
HSV_Min
'
,
window
)
info
[
'
params
'
][
'
hsv_max
'
]
=
cv2
.
getTrackbarPos
(
'
HSV_Max
'
,
window
)
result
=
frame
for
i
,
(
name
,
filter
)
in
enumerate
(
pipeline
):
...
...
This diff is collapsed.
Click to expand it.
filters.py
+
111
−
3
View file @
1e7e12b3
import
cv2
as
cv
import
numpy
as
np
import
pandas
as
pd
import
matplotlib.pyplot
as
plt
from
collections
import
deque
def
none
(
info
,
image
,
state
):
if
'
bufferOrginal
'
not
in
state
:
state
[
'
bufferOrginal
'
]
=
deque
(
maxlen
=
info
[
'
abs_diff
'
])
bufferOrginal
=
state
[
'
bufferOrginal
'
]
bufferOrginal
.
append
(
image
)
return
image
,
False
def
plot_points
(
x
,
y
,
px
,
py
):
fig
=
plt
.
figure
()
ax
=
fig
.
add_subplot
()
ax
.
scatter
(
px
,
py
,
c
=
'
r
'
)
ax
.
plot
(
x
,
y
)
ax
.
set_xlim
([
0
,
1280
])
ax
.
set_ylim
([
720
,
0
])
plt
.
show
()
def
gitter
(
info
,
image
,
state
):
list_of_lines
=
[]
# image Range ((1280, 720))
fig
=
plt
.
figure
()
ax
=
fig
.
add_subplot
()
ax
.
set_xlim
([
0
,
1280
])
ax
.
set_ylim
([
720
,
0
])
ax
.
grid
(
True
,
which
=
'
major
'
)
diff_x
=
50
diff_y
=
50
treshold
=
50
ax
.
set_xticks
(
range
(
0
,
1280
,
diff_x
))
ax
.
set_yticks
(
range
(
0
,
720
,
diff_y
))
for
x
in
range
(
0
,
1280
,
diff_x
):
for
y
in
range
(
0
,
720
,
diff_y
):
subimg
=
image
[
y
:
y
+
diff_y
,
x
:
x
+
diff_x
]
indices
=
np
.
where
(
subimg
>
0
)
if
(
indices
[
1
].
size
>
treshold
):
x_so
=
indices
[
1
]
+
x
y_so
=
indices
[
0
]
+
y
list_xy
=
np
.
column_stack
((
x_so
,
y_so
)).
astype
(
np
.
int32
)
poly_xy
=
polyfit2
(
list_xy
,
x
,
x
+
diff_x
,
y
,
y
+
diff_y
)
list_of_lines
.
append
(
poly_xy
)
ax
.
scatter
(
x_so
,
y_so
,
c
=
'
r
'
)
ax
.
plot
(
poly_xy
[:,
0
],
poly_xy
[:,
1
],
'
b
'
)
#fig.show()
#plot_points(poly_xy[:,0], poly_xy[:,1], x_so, y_so)
plt
.
show
()
return
image
,
False
# Cut green kanal
def
greenfilter
(
info
,
image
,
state
):
# Umwandeln des Bildes in den Farbraum HSV
hsv
=
cv
.
cvtColor
(
image
,
cv
.
COLOR_BGR2HSV
)
# Definition des grünen Farbbereichs in HSV
lower_green
=
np
.
array
([
40
,
10
,
10
])
upper_green
=
np
.
array
([
80
,
240
,
240
])
# Erstellen einer Maske, die den grünen Farbbereich ausschließt
mask
=
cv
.
inRange
(
hsv
,
lower_green
,
upper_green
)
# Invertieren der Maske, um den grünen Farbbereich auszuschließen
inverted_mask
=
cv
.
bitwise_not
(
mask
)
# Anwenden der Maske auf das Bild
res
=
cv
.
bitwise_and
(
image
,
image
,
mask
=
inverted_mask
)
return
res
,
False
def
greenfilter_mask
(
image
,
info
):
min_threshold
=
info
[
'
params
'
][
'
hsv_min
'
]
max_threshold
=
info
[
'
params
'
][
'
hsv_max
'
]
# Umwandeln des Bildes in den Farbraum HSV
hsv
=
cv
.
cvtColor
(
image
,
cv
.
COLOR_BGR2HSV
)
# Definition des grünen Farbbereichs in HSV
lower_green
=
np
.
array
([
min_threshold
,
10
,
10
])
upper_green
=
np
.
array
([
max_threshold
,
240
,
240
])
# Erstellen einer Maske, die den grünen Farbbereich ausschließt
mask
=
cv
.
inRange
(
hsv
,
lower_green
,
upper_green
)
return
mask
def
green_absfilter
(
info
,
image
,
state
):
bufferOrginal
=
state
[
'
bufferOrginal
'
]
res
=
None
for
img
in
bufferOrginal
:
mask
=
greenfilter_mask
(
img
,
info
)
if
res
is
None
:
res
=
mask
else
:
res
=
cv
.
bitwise_or
(
res
,
mask
)
res_inv
=
cv
.
bitwise_not
(
res
)
res_img
=
cv
.
bitwise_and
(
image
,
image
,
mask
=
res_inv
)
return
res_img
,
False
# Resize image to 1280x720 pixels
def
resize
(
info
,
image
,
state
):
res
=
cv
.
resize
(
image
,
(
1280
,
720
))
...
...
@@ -65,10 +162,21 @@ def find_points(image):
return
None
def
polyfit2
(
n_list
,
xs
,
xe
,
ys
,
ye
):
if
n_list
is
not
None
:
p
=
np
.
polyfit
(
n_list
[:,
0
],
n_list
[:,
1
],
1
)
x
=
np
.
arange
(
xs
,
xe
,
1
)
y
=
np
.
polyval
(
p
,
x
)
points
=
np
.
column_stack
((
x
,
y
)).
astype
(
np
.
int32
)
points
=
points
[(
y
>=
ys
)
&
(
y
<=
ye
)]
return
points
return
None
def
polyfit
(
n_list
):
def
polyfit
(
n_list
,
n
=
4
):
if
n_list
is
not
None
:
p
=
np
.
polyfit
(
n_list
[:,
0
],
n_list
[:,
1
],
6
)
p
=
np
.
polyfit
(
n_list
[:,
0
],
n_list
[:,
1
],
n
)
x
=
np
.
arange
(
n_list
[:,
0
][
0
],
n_list
[:,
0
][
-
1
],
1
)
y
=
np
.
polyval
(
p
,
x
)
points
=
np
.
column_stack
((
x
,
y
)).
astype
(
np
.
int32
)
...
...
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