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
73fe5174
Commit
73fe5174
authored
2 years ago
by
Mohammad Khaleeliyeh
Browse files
Options
Downloads
Patches
Plain Diff
erweiterung
parent
53cc27c5
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.py
+0
-1
0 additions, 1 deletion
filter_images.py
filter_images_V1.py
+17
-10
17 additions, 10 deletions
filter_images_V1.py
filter_images_V2.py
+176
-0
176 additions, 0 deletions
filter_images_V2.py
with
193 additions
and
11 deletions
filter_images.py
+
0
−
1
View file @
73fe5174
...
...
@@ -79,7 +79,6 @@ cv2.namedWindow(window, cv2.WINDOW_AUTOSIZE)
cv2
.
createTrackbar
(
'
Line Threshold:
'
,
window
,
line_threshold
,
100
,
line_callback
)
while
capture
.
isOpened
():
ret
,
frame
=
capture
.
read
()
if
ret
==
True
:
frame
=
cv2
.
resize
(
frame
,
(
1280
,
720
))
...
...
This diff is collapsed.
Click to expand it.
filter_images_V1.py
+
17
−
10
View file @
73fe5174
...
...
@@ -31,6 +31,9 @@ def overlay_imgs(base, top):
return
cv2
.
add
(
img1_bg
,
img2_fg
)
def
plot_points
(
x
,
y
,
px
,
py
):
fig
=
plt
.
figure
()
ax
=
fig
.
add_subplot
()
...
...
@@ -60,16 +63,20 @@ def filter_image(image):
# Use canny edge detection
image
=
cv2
.
Canny
(
image
,
min_threshold
,
max_threshold
)
# Closing operation
kernel
=
cv2
.
getStructuringElement
(
cv2
.
MORPH_ELLIPSE
,
(
5
,
5
))
# Closing operation elliptical shaped kernels
kernel
=
cv2
.
getStructuringElement
(
cv2
.
MORPH_ELLIPSE
,
(
5
,
5
))
# use --> dilation = cv2.dilate(img,kernel,iterations = 1)
# Closing operation / closing small holes
image
=
cv2
.
morphologyEx
(
image
,
cv2
.
MORPH_CLOSE
,
kernel
)
# Minimum filter: Rauschen entfernen
kernel
=
cv2
.
getStructuringElement
(
cv2
.
MORPH_RECT
,
(
3
,
3
))
# Closing operation elliptical shaped kernels
kernel
=
cv2
.
getStructuringElement
(
cv2
.
MORPH_RECT
,
(
3
,
3
))
# use another kernal shapes
# perform erosion on the image
image
=
cv2
.
erode
(
image
,
kernel
)
points
=
find_points
(
image
)
overlay
=
np
.
zeros
((
image
.
shape
[
0
],
image
.
shape
[
1
],
3
),
np
.
uint8
)
# draw a polygon on the image
cv2
.
polylines
(
overlay
,
[
points
],
False
,
(
255
,
0
,
0
),
thickness
=
3
)
#lines = cv2.HoughLinesP(image, cv2.HOUGH_PROBABILISTIC, np.pi/360, line_threshold, minLineLength=10, maxLineGap=20)
...
...
@@ -83,7 +90,9 @@ def filter_image(image):
return
overlay
def
sharpenImg
(
image
):
# median of all the pixels under the kernel area
blur
=
cv2
.
medianBlur
(
image
,
5
)
# adding tow images
sharp
=
cv2
.
addWeighted
(
image
,
1.5
,
blur
,
-
0.5
,
0.0
)
return
sharp
...
...
@@ -131,13 +140,13 @@ def calculate_function(overlay,image):
# print (p)
return
overlay
# To control the Size of the Disply
cv2
.
namedWindow
(
window
,
cv2
.
WINDOW_AUTOSIZE
)
cv2
.
createTrackbar
(
'
Line Threshold:
'
,
window
,
line_threshold
,
100
,
line_callback
)
result
=
None
while
capture
.
isOpened
():
# ret is the stat of the reading
ret
,
frame
=
capture
.
read
()
if
ret
==
True
:
frame
=
cv2
.
resize
(
frame
,
(
1280
,
720
))
...
...
@@ -145,8 +154,6 @@ while capture.isOpened():
filter
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_RGB2GRAY
)
filter
=
sharpenImg
(
filter
)
#cv2.imshow(window, filter)
if
last
is
not
None
:
diff
=
cv2
.
absdiff
(
filter
,
last
)
# Difference
overlay
=
filter_image
(
diff
)
...
...
This diff is collapsed.
Click to expand it.
filter_images_V2.py
0 → 100644
+
176
−
0
View file @
73fe5174
import
cv2
import
numpy
as
np
import
matplotlib.pyplot
as
plt
import
time
from
datetime
import
datetime
VIDEO
=
'
Videomaterial/WIN_20230414_13_41_55_Pro.mp4
'
capture
=
cv2
.
VideoCapture
(
VIDEO
)
last
=
None
frame
=
None
diff
=
None
window
=
'
Filter
'
# Einstellungen
min_threshold
=
30
max_threshold
=
110
img_threshold
=
100
line_threshold
=
30
def
overlay_imgs
(
base
,
top
):
topgray
=
cv2
.
cvtColor
(
top
,
cv2
.
COLOR_RGB2GRAY
)
_
,
mask
=
cv2
.
threshold
(
topgray
,
10
,
255
,
cv2
.
THRESH_BINARY
)
mask_inv
=
cv2
.
bitwise_not
(
mask
)
# Now black-out the area of overlay
img1_bg
=
cv2
.
bitwise_and
(
base
,
base
,
mask
=
mask_inv
)
# Take only region of from logo image.
img2_fg
=
cv2
.
bitwise_and
(
top
,
top
,
mask
=
mask
)
return
cv2
.
add
(
img1_bg
,
img2_fg
)
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
find_points
(
image
):
indices
=
np
.
where
(
image
>
0
)
if
(
indices
[
1
].
size
>
0
):
x_sort
=
np
.
sort
(
indices
[
1
])
p
=
np
.
polyfit
(
indices
[
1
],
indices
[
0
],
4
)
x
=
np
.
arange
(
x_sort
[
0
],
x_sort
[
-
1
],
1
)
y
=
np
.
polyval
(
p
,
x
)
points
=
np
.
column_stack
((
x
,
y
)).
astype
(
np
.
int32
)
return
points
return
None
def
filter_image
(
image
):
global
min_threshold
,
max_threshold
,
line_threshold
,
result
,
window
image
=
image
.
copy
()
# construct a rectangular kernel from the current size / rect shaped kernel
kernel
=
cv2
.
getStructuringElement
(
cv2
.
MORPH_RECT
,
(
3
,
3
))
# Opening operation
image
=
cv2
.
morphologyEx
(
image
,
cv2
.
MORPH_OPEN
,
kernel
)
# Closing operation / closing small holes
image
=
cv2
.
morphologyEx
(
image
,
cv2
.
MORPH_CLOSE
,
kernel
)
# Closing operation / closing small holes
image
=
cv2
.
morphologyEx
(
image
,
cv2
.
MORPH_GRADIENT
,
kernel
)
# dilation
kernel2
=
np
.
ones
((
3
,
3
),
np
.
uint8
)
image
=
cv2
.
dilate
(
image
,
kernel2
,
iterations
=
3
)
# perform erosion on the image
image
=
cv2
.
erode
(
image
,
kernel
)
# Use canny edge detection
image
=
cv2
.
Canny
(
image
,
min_threshold
,
max_threshold
)
points
=
find_points
(
image
)
overlay
=
np
.
zeros
((
image
.
shape
[
0
],
image
.
shape
[
1
],
3
),
np
.
uint8
)
# draw a polygon on the image
cv2
.
polylines
(
overlay
,
[
points
],
False
,
(
255
,
0
,
0
),
thickness
=
7
)
return
overlay
def
sharpenImg
(
image
):
# median of all the pixels under the kernel area
blur
=
cv2
.
medianBlur
(
image
,
5
)
# adding tow images
sharp
=
cv2
.
addWeighted
(
image
,
1.5
,
blur
,
-
0.5
,
0.0
)
return
sharp
def
line_callback
(
val
):
global
line_threshold
,
frame
,
diff
line_threshold
=
val
if
diff
is
not
None
:
overlay
=
filter_image
(
diff
)
result
=
overlay_imgs
(
frame
,
overlay
)
cv2
.
imshow
(
window
,
result
)
def
calculate_function
(
overlay
,
image
):
indices
=
np
.
where
(
overlay
>
[
0
])
if
((
indices
[
0
].
size
>
0
)):
p
=
np
.
polyfit
(
indices
[
0
],
indices
[
1
],
4
)
x
=
np
.
arange
(
0
,
overlay
.
shape
[
1
],
1
)
y
=
np
.
polyval
(
p
,
x
)
points
=
np
.
column_stack
((
x
,
y
)).
astype
(
np
.
int32
)
indices
=
np
.
where
(
points
<
0
)
points
=
np
.
delete
(
points
,
indices
,
axis
=
0
)
print
(
points
)
cv2
.
polylines
(
image
,
[
points
],
False
,
(
255
,
0
,
0
),
thickness
=
3
)
# plt.figure()
# plt.plot(x,y)
# plt.savefig("test.png")
# plt.show()
# time.sleep(20)
# print (p)
return
overlay
# To control the Size of the Disply
cv2
.
namedWindow
(
window
,
cv2
.
WINDOW_AUTOSIZE
)
cv2
.
createTrackbar
(
'
Line Threshold:
'
,
window
,
line_threshold
,
100
,
line_callback
)
result
=
None
while
capture
.
isOpened
():
# ret is the stat of the reading
ret
,
frame
=
capture
.
read
()
if
ret
==
True
:
frame
=
cv2
.
resize
(
frame
,
(
1280
,
720
))
filter
=
cv2
.
cvtColor
(
frame
,
cv2
.
COLOR_RGB2GRAY
)
filter
=
sharpenImg
(
filter
)
if
last
is
not
None
:
diff
=
cv2
.
absdiff
(
filter
,
last
)
# Difference
overlay
=
filter_image
(
diff
)
result
=
overlay_imgs
(
frame
,
overlay
)
#function_img=calculate_function(overlay,result)
cv2
.
imshow
(
window
,
result
)
last
=
filter
code
=
cv2
.
waitKey
(
33
)
if
code
&
0xFF
==
ord
(
'
s
'
):
now
=
datetime
.
now
()
str
=
now
.
strftime
(
"
%d_%m_%Y_%H_%M_%S
"
)
cv2
.
imwrite
(
f
'
Filter/IMG_
{
str
}
.png
'
,
result
)
if
code
&
0xFF
==
ord
(
'
q
'
):
break
else
:
break
capture
.
release
()
cv2
.
destroyAllWindows
()
\ 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