-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrectifyMetric.py
More file actions
53 lines (41 loc) · 1.41 KB
/
rectifyMetric.py
File metadata and controls
53 lines (41 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/anaconda/bin/python
import matplotlib.image as mplimg
import matplotlib.pyplot as plt
from pylab import show, axis, imshow, draw
import os
import sys
from utils import *
# Apply a metric rectification to an image using pairs of perpendicular lines
# ---------- Settings ---------
nLinePairs = 2; # Select this may pairs of perpendicular lines
# -----------------------------
def usage(sname):
print(sname + " <affine-rectified image> <# line pairs (>1)>");
if len(sys.argv) != 2 and len(sys.argv) != 3:
usage(sys.argv[0]);
exit(0);
if len(sys.argv) == 3:
nLinePairs = int(sys.argv[2]);
if nLinePairs < 2:
usage(sys.argv[0]);
print(("Metric rectification using %d perpendicular line pairs" % nLinePairs));
# Read input files
imgPath = sys.argv[1];
fileparts = os.path.splitext(imgPath);
if fileparts[1] == '':
fileparts = (fileparts[0], '.png');
imgPath = fileparts[0] + fileparts[1];
im = mplimg.imread(imgPath);
# Do metric rectification
imRect, HM = rectifyMetricF(im, nLinePairs);
# Show output
imshow(np.concatenate((im,imRect),axis=1),cmap='gray')
axis('image')
plt.suptitle('Original (left), Rectified (right)')
margin = 0.05;
plt.subplots_adjust(left=margin, right=1.0-margin, top=1.0-margin, bottom=margin)
show()
# Save output
imgPathRect = fileparts[0] + "_mrect" + fileparts[1];
print(("Saving output to %s..." % imgPathRect));
mplimg.imsave(imgPathRect,cropOuterRegion(imRect));