Push za mene

main
Gasper Spagnolo 2022-12-10 07:14:44 -05:00
parent dd0541c35e
commit bae4983ce1
23 changed files with 1754 additions and 0 deletions

29
assignment5/a5_utils.py Normal file
View File

@ -0,0 +1,29 @@
import numpy as np
import cv2
from matplotlib import pyplot as plt
def normalize_points(P):
# P must be a Nx2 vector of points
# first coordinate is x, second is y
# returns: normalized points in homogeneous coordinates and 3x3 transformation matrix
mu = np.mean(P, axis=0) # mean
scale = np.sqrt(2) / np.mean(np.sqrt(np.sum((P-mu)**2,axis=1))) # scale
T = np.array([[scale, 0, -mu[0]*scale],[0, scale, -mu[1]*scale],[0,0,1]]) # transformation matrix
P = np.hstack((P,np.ones((P.shape[0],1)))) # homogeneous coordinates
res = np.dot(T,P.T).T
return res, T
def draw_epiline(l,h,w):
# l: line equation (vector of size 3)
# h: image height
# w: image width
x0, y0 = map(int, [0, -l[2]/l[1]])
x1, y1 = map(int, [w-1, -(l[2]+l[0]*w)/l[1]])
plt.plot([x0,x1],[y0,y1],'r')
plt.ylim([0,h])
plt.gca().invert_yaxis()

Binary file not shown.

After

Width:  |  Height:  |  Size: 378 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 382 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 384 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 348 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 127 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 89 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -0,0 +1,3 @@
1.6108033e+001 1.3704159e+001 -6.7351564e+001 -1.8838024e+002
8.2886212e-001 -6.1257005e+001 -2.7985739e+001 -7.4190016e+000
1.6739784e-001 -4.5720139e-002 -8.4811075e-002 5.6548906e-001

Binary file not shown.

After

Width:  |  Height:  |  Size: 36 KiB

View File

@ -0,0 +1,3 @@
1.0571624e+001 4.0812730e+000 -2.2538413e+001 -5.9593366e+001
3.1827253e-001 -2.1616617e+001 -9.8820962e+000 -2.7146868e+000
6.1142503e-002 -2.0656640e-002 -2.0701037e-002 2.5211789e-001

View File

@ -0,0 +1,3 @@
-0.000000885211824 -0.000005615918803 0.001943109518320
0.000009392818702 0.000000616883199 -0.012006630150442
-0.001203084137613 0.011037006977740 -0.085317335867129

View File

@ -0,0 +1,168 @@
1.7918200e+002 1.4480400e+002 1.9506100e+002 2.0622700e+002
6.1975500e+001 2.5237200e+002 3.8994100e+001 2.3608350e+002
3.6931350e+001 1.7577400e+002 4.9915800e+001 1.6315300e+002
2.5288250e+002 1.7216700e+002 2.2016750e+002 1.7711100e+002
3.2102350e+002 1.4967350e+002 3.0108200e+002 1.5957050e+002
2.3981000e+002 2.3064950e+002 2.1114250e+002 2.3486800e+002
2.8553800e+002 1.8735650e+002 2.4999600e+002 1.9598200e+002
2.8752550e+002 2.1648500e+002 1.7304900e+002 2.4019300e+002
8.3516000e+001 1.8413600e+002 8.7022000e+001 1.7447850e+002
2.4626850e+002 1.1257100e+002 2.1107700e+002 1.1559400e+002
2.8051150e+002 2.2442250e+002 2.4488300e+002 2.3413700e+002
2.9222950e+002 1.8776050e+002 2.6047650e+002 1.9700200e+002
8.0361000e+001 2.3195900e+002 4.4816200e+001 1.5298600e+002
1.3405950e+002 2.1506400e+002 1.1857700e+002 2.0863650e+002
1.0150850e+002 1.1811850e+002 1.1154700e+002 1.1312950e+002
1.1176850e+002 1.9390400e+002 1.0818650e+002 1.8639750e+002
3.1303750e+002 6.3000500e+001 2.8886000e+002 6.6640500e+001
3.2170900e+001 2.6592200e+002 1.2461050e+001 2.4410900e+002
3.1583150e+002 1.3711850e+002 2.9242350e+002 1.4630450e+002
1.2255200e+002 1.5963750e+002 1.2642000e+002 1.5459400e+002
2.3903100e+002 1.1067800e+002 2.2058950e+002 1.1328800e+002
2.8752550e+002 2.1648500e+002 2.5551700e+002 2.2603200e+002
3.1789700e+002 1.2829450e+002 2.9548050e+002 1.3657600e+002
6.8518500e+001 1.9854650e+002 6.8640000e+001 1.8656350e+002
3.0756150e+002 2.5994000e+002 2.6963400e+002 2.7415950e+002
3.0108400e+002 1.7968850e+002 2.7227750e+002 1.9002000e+002
2.6805100e+002 2.3139700e+002 1.2610700e+002 1.2922500e+002
3.4756300e+002 1.7979550e+002 1.8291800e+002 1.8259850e+002
2.8527600e+002 2.1764500e+002 2.5241150e+002 2.2791300e+002
3.5513400e+002 1.6721850e+002 3.6814550e+002 1.8297050e+002
1.8066250e+002 2.2892400e+002 7.1144500e+001 1.4490950e+002
1.8062300e+002 1.9588000e+002 1.6667450e+002 1.9453550e+002
2.1837400e+002 2.0376550e+002 1.6342400e+002 1.5180550e+002
1.5030000e+002 2.0854100e+002 1.8265850e+002 1.7396650e+002
3.2523350e+002 1.4903450e+002 3.0816400e+002 1.6008600e+002
2.8740050e+002 2.1190450e+002 2.2859100e+002 1.2327800e+002
1.8387500e+002 8.6641500e+001 1.8093250e+002 8.6214500e+001
2.4990350e+002 1.1365050e+002 1.2886550e+002 1.3049800e+002
1.0095700e+002 1.3465200e+002 1.1176400e+002 1.2888750e+002
5.6088000e+001 1.5065400e+002 2.1351100e+002 1.8796300e+002
4.2722000e+001 1.7362150e+002 5.5217000e+001 1.6155800e+002
2.4575550e+002 1.7222450e+002 1.4366850e+002 6.6007500e+001
3.6407250e+002 1.9206950e+002 3.6692550e+002 2.1063000e+002
4.1618200e+001 1.7130050e+002 5.5475000e+001 1.5961500e+002
2.6041450e+002 2.1894350e+002 2.2666700e+002 2.2586250e+002
1.4998800e+002 1.0798350e+002 1.4855600e+002 1.0600400e+002
2.0334150e+002 5.3067500e+001 2.0399900e+002 5.3458000e+001
9.4893500e+001 1.2663100e+002 1.0741250e+002 1.2088600e+002
1.5687100e+002 2.4257150e+002 1.2788050e+002 2.3708150e+002
6.1975500e+001 2.5237200e+002 1.0978200e+002 1.0504350e+002
2.4169600e+002 1.1238700e+002 2.2238100e+002 1.1529450e+002
1.5687100e+002 2.4257150e+002 2.2003500e+002 1.8108050e+002
2.8553800e+002 1.8735650e+002 1.6053100e+002 2.2765300e+002
2.6596500e+002 2.4005550e+002 2.3147100e+002 2.4844750e+002
2.4990350e+002 1.1365050e+002 2.2924850e+002 1.1702150e+002
1.6087250e+002 1.4599600e+002 1.5155750e+002 1.4373600e+002
2.4626850e+002 1.1257100e+002 2.2645100e+002 1.1562050e+002
1.5455250e+002 2.1040350e+002 1.8288300e+002 1.8439900e+002
1.0137850e+002 1.3591000e+002 1.8241150e+002 1.5931950e+002
1.4433350e+002 2.0504300e+002 1.3153400e+002 1.9987250e+002
2.1356300e+002 2.1005050e+002 8.1403000e+001 1.4930350e+002
3.0690550e+002 1.3915100e+002 1.6471200e+002 1.4424850e+002
1.7242650e+002 2.2057000e+002 1.5083300e+002 2.1785750e+002
2.5155300e+002 2.1905500e+002 2.1929050e+002 2.2458700e+002
3.4451900e+001 2.2563950e+002 2.8594550e+001 2.0850100e+002
1.5030000e+002 2.0854100e+002 1.3601750e+002 2.0423250e+002
1.8066250e+002 2.2892400e+002 1.5533050e+002 2.2653700e+002
2.3232950e+002 1.1404500e+002 2.1404300e+002 1.1640950e+002
2.1356300e+002 2.1005050e+002 1.9165250e+002 2.1161750e+002
3.2473050e+002 2.4401900e+002 2.9429500e+002 2.6040700e+002
1.5455250e+002 2.1040350e+002 1.3849450e+002 2.0611350e+002
2.5407600e+002 2.3183650e+002 2.2241750e+002 2.3866850e+002
1.7747850e+002 1.5331750e+002 1.0307000e+002 1.8974250e+002
1.1764400e+002 1.3685650e+002 1.2326950e+002 1.3158800e+002
3.0529400e+002 1.9526650e+002 1.5803850e+002 2.2521350e+002
3.2523350e+002 1.4903450e+002 1.8651150e+002 4.4059250e+001
2.9683100e+002 2.0801450e+002 2.6987100e+002 2.1891300e+002
6.2727000e+001 1.6241450e+002 7.7038000e+001 1.5270200e+002
9.4893500e+001 1.2663100e+002 2.2716350e+002 1.9914500e+002
6.2285000e+001 1.8180850e+002 6.9213000e+001 1.7063550e+002
3.0235850e+002 1.5133850e+002 2.7282300e+002 1.6042950e+002
2.3903100e+002 1.1067800e+002 7.9453000e+001 1.7107700e+002
3.4732250e+002 1.8414400e+002 3.5243400e+002 2.0054950e+002
2.1410550e+002 2.0812100e+002 1.9209200e+002 2.1014500e+002
2.9651650e+002 1.7797850e+002 2.6587100e+002 1.8715900e+002
3.0690550e+002 1.3915100e+002 2.7905500e+002 1.4664550e+002
3.0755450e+002 1.5028450e+002 2.8154800e+002 1.5912800e+002
7.6427500e+001 1.8039550e+002 8.2665500e+001 1.7071850e+002
2.3471950e+002 1.1491450e+002 2.1604250e+002 1.1743850e+002
2.4169600e+002 1.1238700e+002 6.7750500e+001 1.9952400e+002
3.0755450e+002 1.5028450e+002 2.3814250e+002 2.5626200e+002
3.1365900e+002 2.0281000e+002 2.9498900e+002 2.1596750e+002
2.1411400e+002 1.9151850e+002 1.9161650e+002 1.9293450e+002
2.8811050e+002 1.9081650e+002 2.5483200e+002 1.9954550e+002
1.2948250e+002 2.2789950e+002 1.0891000e+002 2.2010300e+002
8.3516000e+001 1.8413600e+002 1.9472300e+002 1.9885950e+002
7.8119000e+001 1.7241850e+002 8.7477000e+001 1.6300700e+002
2.9651650e+002 1.7797850e+002 1.8210000e+002 4.8681700e+001
1.2255200e+002 1.5963750e+002 1.1189250e+002 1.3000250e+002
3.5513400e+002 1.6721850e+002 2.3805150e+002 1.2053600e+002
3.2596550e+002 1.5994300e+002 3.1038750e+002 1.7185400e+002
1.0853300e+002 1.6344500e+002 1.1633200e+002 1.5656000e+002
3.6180050e+002 2.0686900e+002 7.2610500e+001 1.5987150e+002
2.0012100e+002 4.5417000e+001 2.0097650e+002 4.5859950e+001
1.8665100e+002 7.6156000e+001 1.8557650e+002 7.6297500e+001
3.0668800e+002 1.5394750e+002 2.7869700e+002 1.6339550e+002
3.3010150e+002 1.5469900e+002 3.1804750e+002 1.6654000e+002
3.2102350e+002 1.4967350e+002 1.5227100e+002 1.8614150e+002
2.8384950e+001 1.8400600e+002 3.9704350e+001 1.7010550e+002
2.9683100e+002 2.0801450e+002 2.2525600e+002 1.9041800e+002
6.2074500e+001 2.3851850e+002 4.5835800e+001 2.2259600e+002
1.5179600e+002 1.6906650e+002 1.8530350e+002 1.6236650e+002
3.3010150e+002 1.5469900e+002 7.0637500e+001 1.5868400e+002
1.9101900e+002 2.0624350e+002 1.7409600e+002 2.0558000e+002
1.4433350e+002 2.0504300e+002 8.5874500e+001 1.5348500e+002
3.2180250e+002 1.3722050e+002 3.0240700e+002 1.4650100e+002
3.6793900e+002 2.2950150e+002 3.5223750e+002 2.5125600e+002
3.5791800e+002 1.9988800e+002 3.5591800e+002 2.1845550e+002
1.9674400e+002 2.0645350e+002 1.7915100e+002 2.0655600e+002
3.1816550e+002 1.1693600e+002 2.9533550e+002 1.2460750e+002
3.2399950e+002 1.8537150e+002 3.1067200e+002 1.9826250e+002
1.1153800e+001 1.5971450e+002 1.7628550e+002 1.6593900e+002
3.3210650e+002 1.4851150e+002 3.1965600e+002 1.5978300e+002
2.7584500e+002 8.8974500e+001 2.7500850e+002 9.3037500e+001
4.1915300e+001 1.8043400e+002 4.3957650e+001 1.6738150e+002
3.2624500e+002 1.3943600e+002 3.1023500e+002 1.4940550e+002
3.1224400e+002 1.3321800e+002 2.8568650e+002 1.4196700e+002
2.9726900e+002 1.9775700e+002 2.6840300e+002 2.0876500e+002
5.6088000e+001 1.5065400e+002 7.6481000e+001 1.4130750e+002
1.9101900e+002 2.0624350e+002 1.0835400e+002 1.7635550e+002
3.0365650e+002 1.5001600e+002 2.7446550e+002 1.5841800e+002
1.7912700e+002 1.5299450e+002 2.3346650e+002 1.4753300e+002
2.9222950e+002 1.8776050e+002 5.8090000e+001 1.6222400e+002
3.2479850e+002 1.3931850e+002 3.0716100e+002 1.4911300e+002
1.3144600e+002 6.8035000e+001 3.5574450e+002 2.1173050e+002
3.1789700e+002 1.2829450e+002 2.1445850e+002 1.7648300e+002
8.0361000e+001 2.3195900e+002 6.4276000e+001 2.1868200e+002
3.6180050e+002 2.0686900e+002 3.5478100e+002 2.2578000e+002
9.6984500e+001 1.3567950e+002 1.0974850e+002 1.2934550e+002
3.4747600e+002 2.2390200e+002 3.3133850e+002 2.4183450e+002
1.1153800e+001 1.5971450e+002 3.5802700e+001 1.4647600e+002
2.7404450e+002 2.4653600e+002 1.6532900e+002 1.5169450e+002
3.0529400e+002 1.9526650e+002 2.8159550e+002 2.0687550e+002
5.7455500e+001 1.6895950e+002 2.1473250e+002 1.0983800e+002
1.2769600e+002 1.9505900e+002 1.2123950e+002 1.8901250e+002
2.6053200e+001 1.6551050e+002 1.9648950e+002 2.0448800e+002
2.8740050e+002 2.1190450e+002 2.5464750e+002 2.2193400e+002
2.5593700e+002 2.2407050e+002 2.2306950e+002 2.3054600e+002
2.3471950e+002 1.1491450e+002 2.1934950e+002 2.0089500e+002
3.1959300e+002 1.5739450e+002 3.0088450e+002 1.6808900e+002
1.9238350e+002 1.6535150e+002 1.0695850e+002 1.1564550e+002
2.4247550e+002 2.3166200e+002 2.1305000e+002 2.3636450e+002
3.0218800e+002 1.7132600e+002 2.7425350e+002 1.8068600e+002
1.7601850e+002 1.4352700e+002 1.6290100e+002 1.4236350e+002
3.0855650e+002 1.4262350e+002 2.8091400e+002 1.5121450e+002
3.1638550e+002 1.5340300e+002 2.9527450e+002 1.6362750e+002
2.5261200e+002 1.2029950e+002 2.3018150e+002 1.2391750e+002
1.7568950e+002 2.2714250e+002 1.5119350e+002 2.2430800e+002
1.5179600e+002 1.6906650e+002 1.4629400e+002 1.6549950e+002
1.9238350e+002 1.6535150e+002 1.7466150e+002 1.6517000e+002
3.1037750e+002 2.5751600e+002 5.8449500e+001 1.5756250e+002
2.6087750e+002 1.9306100e+002 1.2478950e+002 1.3764900e+002
7.3081000e+001 1.6900550e+002 8.4426500e+001 1.5967050e+002
2.8041600e+002 2.0380450e+002 2.4273700e+002 2.1295550e+002
3.4756300e+002 1.7979550e+002 3.5326600e+002 1.9526800e+002
2.5652100e+002 1.7681900e+002 2.2275200e+002 1.8204100e+002
3.1037750e+002 2.5751600e+002 2.7346600e+002 2.7244450e+002
2.6805100e+002 2.3139700e+002 2.3297150e+002 2.3981050e+002

View File

@ -0,0 +1,10 @@
1.9220093e+002 4.4911215e+001 1.9011120e+002 4.6260498e+001
3.2319159e+002 6.4051402e+001 2.9641291e+002 6.8954121e+001
1.3238785e+002 6.8836449e+001 1.4352955e+002 6.7162519e+001
3.1302336e+002 1.1250000e+002 2.8566330e+002 1.2031337e+002
1.0367757e+002 1.1010748e+002 1.1187792e+002 1.0478616e+002
2.7713551e+002 1.7051869e+002 2.3848445e+002 1.7645023e+002
8.7528037e+001 1.5317290e+002 1.0232271e+002 1.4479860e+002
2.7593925e+002 2.4588318e+002 2.3967885e+002 2.5647512e+002
3.2139720e+002 2.0999533e+002 3.1134292e+002 2.2542068e+002
2.8132243e+002 1.9264953e+002 2.4385925e+002 1.9974106e+002

Binary file not shown.

67
assignment5/solution.py Normal file
View File

@ -0,0 +1,67 @@
import numpy as np
import numpy.typing as npt
from matplotlib import pyplot as plt
import cv2
import uz_framework.image as uz_image
import uz_framework.text as uz_text
import os
##############################################
# EXCERCISE 1: Exercise 1: Image derivatives #
##############################################
def ex1():
one_b()
def one_a() -> None:
"""
d = (f * px)/pz + f(T - px)/pz => d = (f * T) / pz
"""
def one_b() -> None:
"""
Write a script that computes the disparity for a range of values of pz. Plot the values
to a figure and set the appropriate units to axes. Use the following parameters of
the system: focal length is f = 2.5mm and stereo system baseline is T = 12cm
"""
pz_values = np.arange(0.001, 0.1, 0.001)
f = 0.0025
T = 0.12
d = (f * T) / pz_values
plt.plot(pz_values, d)
plt.xlabel('pz [m]')
plt.ylabel('d [m]')
plt.title('Disparity for a range of values of pz')
plt.show()
def one_c() -> None:
"""
In order to get a better grasp on the idea of distance and disparity, you will calculate
the numbers for a specific case. We will take the parameters from a specification of
a commercial stereo camera Bumblebee2 manufactured by the company PointGray:
f = 2.5mm, T = 12cm, whose image sensor has a resolution of 648×488 pixels that
are square and the width of a pixel is 7.4µm. We assume that there is no empty
space between pixels and that both cameras are completely parallel and equal. Lets
say that we use this system to observe a (point) object that is detected at pixel 550
in x axis in the left camera and at the pixel 300 in the right camera. How far is the
object (in meters) in this case? How far is the object if the object is detected at
pixel 540 in the right camera? Solve this task analytically and bring your solution
to the presentation of the exercise.
"""
# ######## #
# SOLUTION #
# ######## #
def main():
ex1()
#ex2()
#ex3()
if __name__ == '__main__':
main()

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,9 @@
import numpy as np
def read_data(filename: str):
# reads a numpy array from a text file
with open(filename) as f:
s = f.read()
return np.fromstring(s, sep=' ')