mirror of https://github.com/opencv/opencv.git
Open Source Computer Vision Library
https://opencv.org/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
75 lines
1.6 KiB
75 lines
1.6 KiB
12 years ago
|
#!/usr/bin/env python
|
||
12 years ago
|
|
||
12 years ago
|
''' 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
|
||
|
'''
|
||
|
|
||
9 years ago
|
# Python 2/3 compatibility
|
||
|
from __future__ import print_function
|
||
|
import sys
|
||
|
PY3 = sys.version_info[0] == 3
|
||
|
|
||
|
if PY3:
|
||
|
xrange = range
|
||
|
|
||
12 years ago
|
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
|
||
9 years ago
|
print(__doc__)
|
||
12 years ago
|
|
||
12 years ago
|
try:
|
||
|
fn = sys.argv[1]
|
||
|
except:
|
||
|
fn = 0
|
||
12 years ago
|
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):
|
||
9 years ago
|
v = int(cv2.getTrackbarPos('%d'%i, 'level control') / 5)
|
||
12 years ago
|
pyr[i] *= v
|
||
|
res = merge_lappyr(pyr)
|
||
|
|
||
|
cv2.imshow('laplacian pyramid filter', res)
|
||
|
|
||
10 years ago
|
if cv2.waitKey(1) & 0xFF == 27:
|
||
12 years ago
|
break
|