Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
889df76e
Commit
889df76e
authored
Jun 10, 2012
by
Alexander Mordvintsev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added lappyr.py sample
parent
139e790f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
common.py
samples/python2/common.py
+4
-0
lappyr.py
samples/python2/lappyr.py
+64
-0
No files found.
samples/python2/common.py
View file @
889df76e
...
...
@@ -190,3 +190,7 @@ def mosaic(w, imgs):
imgs
=
it
.
chain
([
img0
],
imgs
)
rows
=
grouper
(
w
,
imgs
,
pad
)
return
np
.
vstack
(
map
(
np
.
hstack
,
rows
))
def
getsize
(
img
):
h
,
w
=
img
.
shape
[:
2
]
return
w
,
h
samples/python2/lappyr.py
0 → 100644
View file @
889df76e
''' An example of Laplacian Pyramid construction and merging.
Level : Intermediate
Usage : python lappyr.py [<video source>]
References:
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.54.299
Alexander Mordvintsev 6/10/12
'''
import
numpy
as
np
import
cv2
import
video
from
common
import
nothing
,
getsize
def
build_lappyr
(
img
,
leveln
=
6
,
dtype
=
np
.
int16
):
img
=
dtype
(
img
)
levels
=
[]
for
i
in
xrange
(
leveln
-
1
):
next_img
=
cv2
.
pyrDown
(
img
)
img1
=
cv2
.
pyrUp
(
next_img
,
dstsize
=
getsize
(
img
))
levels
.
append
(
img
-
img1
)
img
=
next_img
levels
.
append
(
img
)
return
levels
def
merge_lappyr
(
levels
):
img
=
levels
[
-
1
]
for
lev_img
in
levels
[
-
2
::
-
1
]:
img
=
cv2
.
pyrUp
(
img
,
dstsize
=
getsize
(
lev_img
))
img
+=
lev_img
return
np
.
uint8
(
np
.
clip
(
img
,
0
,
255
))
if
__name__
==
'__main__'
:
import
sys
print
__doc__
try
:
fn
=
sys
.
argv
[
1
]
except
:
fn
=
0
cap
=
video
.
create_capture
(
fn
)
leveln
=
6
cv2
.
namedWindow
(
'level control'
)
for
i
in
xrange
(
leveln
):
cv2
.
createTrackbar
(
'
%
d'
%
i
,
'level control'
,
5
,
50
,
nothing
)
while
True
:
ret
,
frame
=
cap
.
read
()
pyr
=
build_lappyr
(
frame
,
leveln
)
for
i
in
xrange
(
leveln
):
v
=
cv2
.
getTrackbarPos
(
'
%
d'
%
i
,
'level control'
)
/
5
pyr
[
i
]
*=
v
res
=
merge_lappyr
(
pyr
)
cv2
.
imshow
(
'laplacian pyramid filter'
,
res
)
if
cv2
.
waitKey
(
1
)
==
27
:
break
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