Spacing and Tab Fixes in __main__.py

Renamed functions to use underscores and lowercase rather than camel case.
Made minor spacing changes.
This commit is contained in:
Sravan Balaji
2019-04-22 22:59:51 -04:00
parent 51781fb3d2
commit 01ac896a5c

View File

@@ -4,20 +4,20 @@ from matplotlib import pyplot as plt
import os import os
import file_data import file_data
def main(): def main():
# Read in all images
images = read_images()
#Read in all images # Read in data from Section001_Data.txt
images = readImages()
#Read in data from Section001_Data.txt
specimen, load_disp_data = file_data.read_file("../Section001_Data.txt") specimen, load_disp_data = file_data.read_file("../Section001_Data.txt")
#Keep track of Stress and Strains # Keep track of Stress and Strains
stresses = [] stresses = []
strains = [] strains = []
#Get distances using sift # Get distances using sift
distances = getSiftDistance(images[0], images[1]) distances = get_sift_distance(images[8], images[9])
# These distances are coming out as zero for some reason. # These distances are coming out as zero for some reason.
# Still trying to figure out if it's a bug in the code I # Still trying to figure out if it's a bug in the code I
@@ -29,7 +29,7 @@ def main():
print("MIN DISTANCE:") print("MIN DISTANCE:")
print(min(distances)) print(min(distances))
#Eventually we'll find the distances, stress, strain for all images # Eventually we'll find the distances, stress, strain for all images
""" """
for idx in range(0, len(images)-1): for idx in range(0, len(images)-1):
distances = getSiftDistance(images[idx], images[idx+1]) distances = getSiftDistance(images[idx], images[idx+1])
@@ -39,28 +39,32 @@ def main():
""" """
def readImages(): def read_images():
image_dir = '../images/' image_dir = '../Images/'
filenames = os.listdir(image_dir) filenames = os.listdir(image_dir)
images = [] images = []
for file in filenames: for file in filenames:
images.append(cv2.imread(os.path.join(image_dir,file))) images.append(cv2.imread(os.path.join(image_dir, file)))
return images return images
def getStrain(length, displacement):
def get_strain(length, displacement):
return displacement / length return displacement / length
def getYoungsModulus(strain, stress):
return strain / stress
def getSiftDistance(img1, img2): def get_youngs_modulus(strain, stress):
return stress / strain
def get_sift_distance(img1, img2):
""" Gets distance between matching pts in """ Gets distance between matching pts in
img1 and img2. img1 and img2.
""" """
sift = cv2.xfeatures2d.SIFT_create() sift = cv2.xfeatures2d.SIFT_create()
original_kp, original_des = sift.detectAndCompute(img1,None) original_kp, original_des = sift.detectAndCompute(img1, None)
new_kp, new_des = sift.detectAndCompute(img2,None) new_kp, new_des = sift.detectAndCompute(img2, None)
bf = cv2.BFMatcher() bf = cv2.BFMatcher()
matches = bf.knnMatch(original_des, new_des, k=2) matches = bf.knnMatch(original_des, new_des, k=2)
@@ -69,10 +73,10 @@ def getSiftDistance(img1, img2):
good = [] good = []
for m, n in matches: for m, n in matches:
if m.distance < 0.3 * n.distance: if m.distance < 0.3 * n.distance:
good.append(m) good.append(m)
# Draw matches # Draw matches
""" """
# Uncomment to print matches between img1 and img2. # Uncomment to print matches between img1 and img2.
# SIFT may not be the best method based off the matched # SIFT may not be the best method based off the matched
@@ -86,7 +90,7 @@ def getSiftDistance(img1, img2):
pts1 = np.float32([original_kp[m.queryIdx].pt for m in good]) pts1 = np.float32([original_kp[m.queryIdx].pt for m in good])
pts2 = np.float32([new_kp[m.trainIdx].pt for m in good]) pts2 = np.float32([new_kp[m.trainIdx].pt for m in good])
#convert to complex number # convert to complex number
z1 = np.array([[complex(c[0],c[1]) for c in pts1]]) z1 = np.array([[complex(c[0],c[1]) for c in pts1]])
z2 = np.array([[complex(c[0],c[1]) for c in pts2]]) z2 = np.array([[complex(c[0],c[1]) for c in pts2]])
@@ -96,7 +100,5 @@ def getSiftDistance(img1, img2):
return distances return distances
if __name__ == '__main__': if __name__ == '__main__':
main() main()