mirror of
https://github.com/balajsra/EECS-442-WN19-DIC-Project.git
synced 2025-09-02 17:03:15 +00:00
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:
@@ -4,20 +4,20 @@ from matplotlib import pyplot as plt
|
||||
import os
|
||||
import file_data
|
||||
|
||||
|
||||
def main():
|
||||
# Read in all images
|
||||
images = read_images()
|
||||
|
||||
#Read in all images
|
||||
images = readImages()
|
||||
|
||||
#Read in data from Section001_Data.txt
|
||||
# Read in data from 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 = []
|
||||
strains = []
|
||||
|
||||
#Get distances using sift
|
||||
distances = getSiftDistance(images[0], images[1])
|
||||
# Get distances using sift
|
||||
distances = get_sift_distance(images[8], images[9])
|
||||
|
||||
# These distances are coming out as zero for some reason.
|
||||
# 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(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):
|
||||
distances = getSiftDistance(images[idx], images[idx+1])
|
||||
@@ -39,28 +39,32 @@ def main():
|
||||
"""
|
||||
|
||||
|
||||
def readImages():
|
||||
image_dir = '../images/'
|
||||
def read_images():
|
||||
image_dir = '../Images/'
|
||||
filenames = os.listdir(image_dir)
|
||||
|
||||
images = []
|
||||
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
|
||||
|
||||
def getStrain(length, displacement):
|
||||
|
||||
def get_strain(length, displacement):
|
||||
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
|
||||
img1 and img2.
|
||||
"""
|
||||
sift = cv2.xfeatures2d.SIFT_create()
|
||||
original_kp, original_des = sift.detectAndCompute(img1,None)
|
||||
new_kp, new_des = sift.detectAndCompute(img2,None)
|
||||
original_kp, original_des = sift.detectAndCompute(img1, None)
|
||||
new_kp, new_des = sift.detectAndCompute(img2, None)
|
||||
|
||||
bf = cv2.BFMatcher()
|
||||
matches = bf.knnMatch(original_des, new_des, k=2)
|
||||
@@ -69,10 +73,10 @@ def getSiftDistance(img1, img2):
|
||||
good = []
|
||||
|
||||
for m, n in matches:
|
||||
if m.distance < 0.3 * n.distance:
|
||||
good.append(m)
|
||||
if m.distance < 0.3 * n.distance:
|
||||
good.append(m)
|
||||
|
||||
# Draw matches
|
||||
# Draw matches
|
||||
"""
|
||||
# Uncomment to print matches between img1 and img2.
|
||||
# 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])
|
||||
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]])
|
||||
z2 = np.array([[complex(c[0],c[1]) for c in pts2]])
|
||||
|
||||
@@ -96,7 +100,5 @@ def getSiftDistance(img1, img2):
|
||||
return distances
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
main()
|
||||
|
Reference in New Issue
Block a user