mirror of
https://github.com/opencv/opencv.git
synced 2025-01-18 06:03:15 +08:00
python helper routines (common.py) added
This commit is contained in:
parent
d22b94757c
commit
194506397e
@ -26,8 +26,7 @@ if __name__ == '__main__':
|
|||||||
try: img_mask = img_mask[0]
|
try: img_mask = img_mask[0]
|
||||||
except: img_mask = '../cpp/left*.jpg'
|
except: img_mask = '../cpp/left*.jpg'
|
||||||
img_names = glob(img_mask)
|
img_names = glob(img_mask)
|
||||||
try: debug_dir = args['--debug']
|
debug_dir = args.get('--debug')
|
||||||
except: debug_dir = None
|
|
||||||
|
|
||||||
pattern_size = (9, 6)
|
pattern_size = (9, 6)
|
||||||
pattern_points = np.zeros( (np.prod(pattern_size), 3), np.float32 )
|
pattern_points = np.zeros( (np.prod(pattern_size), 3), np.float32 )
|
||||||
|
72
samples/python2/common.py
Normal file
72
samples/python2/common.py
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
import numpy as np
|
||||||
|
import cv2
|
||||||
|
|
||||||
|
def to_list(a):
|
||||||
|
return [tuple(p) for p in a]
|
||||||
|
|
||||||
|
def anorm2(a):
|
||||||
|
return (a*a).sum(-1)
|
||||||
|
def anorm(a):
|
||||||
|
return np.sqrt( anorm2(a) )
|
||||||
|
|
||||||
|
def homotrans(H, x, y):
|
||||||
|
xs = H[0, 0]*x + H[0, 1]*y + H[0, 2]
|
||||||
|
ys = H[1, 0]*x + H[1, 1]*y + H[1, 2]
|
||||||
|
s = H[2, 0]*x + H[2, 1]*y + H[2, 2]
|
||||||
|
return xs/s, ys/s
|
||||||
|
|
||||||
|
def to_rect(a):
|
||||||
|
a = np.ravel(a)
|
||||||
|
if len(a) == 2:
|
||||||
|
a = (0, 0, a[0], a[1])
|
||||||
|
return np.array(a, np.float64).reshape(2, 2)
|
||||||
|
|
||||||
|
def rect2rect_mtx(src, dst):
|
||||||
|
src, dst = to_rect(src), to_rect(dst)
|
||||||
|
cx, cy = (dst[1] - dst[0]) / (src[1] - src[0])
|
||||||
|
tx, ty = dst[0] - src[0] * (cx, cy)
|
||||||
|
M = np.float64([[ cx, 0, tx],
|
||||||
|
[ 0, cy, ty],
|
||||||
|
[ 0, 0, 1]])
|
||||||
|
return M
|
||||||
|
|
||||||
|
|
||||||
|
def lookat(eye, target, up = (0, 0, 1)):
|
||||||
|
fwd = np.asarray(target, np.float64) - eye
|
||||||
|
fwd /= anorm(fwd)
|
||||||
|
right = np.cross(fwd, up)
|
||||||
|
right /= anorm(right)
|
||||||
|
down = np.cross(fwd, right)
|
||||||
|
Rt = np.zeros((3, 4))
|
||||||
|
Rt[:,:3] = [right, down, fwd]
|
||||||
|
Rt[:,3] = -np.dot(Rt[:,:3], eye)
|
||||||
|
return Rt
|
||||||
|
|
||||||
|
def mtx2rvec(R):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
import cv2
|
||||||
|
from time import clock
|
||||||
|
|
||||||
|
'''
|
||||||
|
w, h = 640, 480
|
||||||
|
while True:
|
||||||
|
img = np.zeros((h, w, 3), np.uint8)
|
||||||
|
t = clock()
|
||||||
|
eye = [5*cos(t), 5*sin(t), 3]
|
||||||
|
Rt = lookat(eye, [0, 0, 0])
|
||||||
|
'''
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
eye = [1, -4, 3]
|
||||||
|
target = [0, 0, 0]
|
||||||
|
Rt = lookat(eye, [0, 0, 0])
|
||||||
|
print Rt
|
||||||
|
p = [0, 0, 0]
|
||||||
|
print cv2.transform(np.float64([[p]]), Rt)
|
||||||
|
|
||||||
|
print cv2.SVDecomp(Rt[:,:3])
|
||||||
|
|
@ -64,6 +64,7 @@ def create_capture(source):
|
|||||||
|
|
||||||
|
|
||||||
presets = dict(
|
presets = dict(
|
||||||
|
empty = 'synth:',
|
||||||
lena = 'synth:bg=../cpp/lena.jpg:noise=0.1'
|
lena = 'synth:bg=../cpp/lena.jpg:noise=0.1'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user