-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathrectifyAffine.py
More file actions
51 lines (40 loc) · 1.32 KB
/
Copy pathrectifyAffine.py
File metadata and controls
51 lines (40 loc) · 1.32 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
#!/anaconda/bin/python
import matplotlib.image as mplimg
import os
import sys
from utils import *
# Apply affine rectification to an image using pairs of parallel lines
# ---------- Settings ---------
nLinePairs = 2; # Select this may pairs of perpendicular lines
# -----------------------------
def usage(sname):
print(sname + " <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(f"Affine rectification via the vanishing line using {d} parallel 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 affine rectification
imA, HA = rectifyAffineF(im, nLinePairs)
plt.close('all')
# Show output
imshow(np.concatenate((im,imA),axis=1))
axis('off')
plt.suptitle('Original (left), Affine 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] + "_arect" + fileparts[1];
print(("Saving output to %s..." % imgPathRect))
mplimg.imsave(imgPathRect,cropOuterRegion(imA))