1 |
|
2 | import cv2
|
3 | import cv2.cv as cv
|
4 | import numpy as np
|
5 | import random
|
6 |
|
7 | def wrap_rectify_uncalibrated(x1, x2, F, imsize, threshold):
|
8 | |
9 | rectifyUncalibrated"""
|
10 |
|
11 | x1_1d = np.empty((2*x1.shape[1],), dtype=float)
|
12 | x1_1d[0::2] = x1[0,:]
|
13 | x1_1d[1::2] = x1[1,:]
|
14 |
|
15 | x2_1d = np.empty((2*x2.shape[1],), dtype=float)
|
16 | x2_1d[0::2] = x2[0,:]
|
17 | x2_1d[1::2] = x2[1,:]
|
18 |
|
19 | return cv2.stereoRectifyUncalibrated(x1_1d, x2_1d, F, imsize,
|
20 | threshold=threshold)
|
21 |
|
22 |
|
23 | F = np.array([[-0.000005, 0.00007 , 0.001381],
|
24 | [ 0.000138, -0.000006, -0.187487],
|
25 | [-0.009234, 0.160388, 1. ]])
|
26 |
|
27 | x1 = np.array([[119.61484528, 129.7978363 , 120.65196991, 114.99479675,
|
28 | 59.63290787, 53.01756287, 117.4389801 , 159.73094177,
|
29 | 145.67852783, 19.50421524],
|
30 | [61.97002411, 66.56116486, 64.01503754, 85.84388733,
|
31 | 14.17597294, 111.90859985, 53.89838409, 79.10702515,
|
32 | 86.399086 , 133.72361755]])
|
33 |
|
34 | x2 = np.array([[ 121., 130., 122., 117., 128., 63., 118., 161., 146.,
|
35 | 21.],
|
36 | [ 62., 67., 65., 84., 16., 106., 55., 81., 87.,
|
37 | 122.]])
|
38 |
|
39 | imsize = (266, 200)
|
40 |
|
41 | threshold = 3
|
42 |
|
43 | outliers1 = np.array([[1, 10, 50, 100],
|
44 | [1, 30, 60, 90]], dtype=float)
|
45 | outliers2 = np.array([[200, 250, 300, 340],
|
46 | [100, 110, 110, 110]], dtype=float)
|
47 |
|
48 |
|
49 | lines1 = np.zeros((3, outliers1.shape[1]), dtype=float)
|
50 | lines2 = np.zeros((3, outliers2.shape[1]), dtype=float)
|
51 |
|
52 | cv.ComputeCorrespondEpilines(cv.fromarray(outliers1), 1, cv.fromarray(F),
|
53 | cv.fromarray(lines1))
|
54 | cv.ComputeCorrespondEpilines(cv.fromarray(outliers2), 1, cv.fromarray(F.T.copy()),
|
55 | cv.fromarray(lines2))
|
56 | for i in xrange(outliers1.shape[1]):
|
57 | assert abs(outliers1[0,i]*lines2[0,i] +
|
58 | outliers1[1,i]*lines2[1,i] + lines2[2,i]) > threshold
|
59 | assert abs(outliers2[0,i]*lines1[0,i] +
|
60 | outliers2[1,i]*lines1[1,i] + lines1[2,i]) > threshold
|
61 |
|
62 |
|
63 | success, H1, H2 = wrap_rectify_uncalibrated(x1, x2, F, imsize, threshold)
|
64 |
|
65 |
|
66 | ox1 = np.c_[outliers1, x1]
|
67 | ox2 = np.c_[outliers2, x2]
|
68 |
|
69 | success, oH1, oH2 = wrap_rectify_uncalibrated(ox1, ox2, F, imsize, threshold)
|
70 |
|
71 | assert np.allclose(oH1, H1)
|
72 | assert np.allclose(oH2, H2)
|
73 |
|