From a062863b1e319272dd0ac92175a143ac0ab09295 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Mon, 25 Mar 2019 16:44:00 -0400 Subject: [PATCH 1/6] Add main.py Created main.py with a function to read in the provided text file. Gets specimen dimensions, frame number, load, and displacement data into dictionary of FrameData classes. --- .gitignore | 1 + src/main.py | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100644 .gitignore create mode 100644 src/main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f11b75 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea/ diff --git a/src/main.py b/src/main.py new file mode 100644 index 0000000..26f1e0f --- /dev/null +++ b/src/main.py @@ -0,0 +1,72 @@ +############################################# +# EECS 442: Computer Vision - W19 # +############################################# +# Authors: Sravan Balaji & Kevin Monpara # +# Filename: main.py # +# Description: # +############################################# + +import numpy as np + + +class FrameData: + load = 0 # Load in N + disp = 0 # Displacement in mm + + def __init__(self, load, disp): + self.load = load + self.disp = disp + + +def calc_stress(): + file = open("../Section001_Data.txt", "r") + + w = 0 # Specimen Width in mm + t = 0 # Specimen Thickness in mm + gl = 0 # Specimen Gauge Length in mm + ol = 0 # Specimen Overall Length in mm + + load_disp_data = dict() + + data_start = -1 + in_frame_data = False + + for line in file: + if "Width" in line: + index = line.find("\t") + w = float(line[index + 1:]) + + if "Thickness" in line: + index = line.find("\t") + t = float(line[index + 1:]) + + if "Gauge Length" in line: + index = line.find("\t") + gl = float(line[index + 1:]) + + if "Overall Length" in line: + index = line.find("\t") + ol = float(line[index + 1:]) + + if "Frame #" in line: + data_start = 2 + + if data_start != -1: + data_start -= 1 + + if data_start == 0: + in_frame_data = True + + if in_frame_data: + if line != '\t\t\n': + frame_num_str, load_str, disp_str = line.split("\t") + frame_num = int(frame_num_str) + load = float(load_str) + disp = float(disp_str) + load_disp_data[frame_num] = FrameData(load, disp) + + print("Done") + + +if __name__ == "__main__": + calc_stress() From 8b163631cad0a77ccf24adb71b0749f86d346e17 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Mon, 15 Apr 2019 19:40:58 -0400 Subject: [PATCH 2/6] Modify main.py * Add new class SpecimenDimensions to hold dimensional information. * Add stress variable to FrameData class. * rename calc_stress function to read_file * Add data filepath as input to read_file function * read_file function now calculates stress from cross-sectional area of specimen and load from each frame. * read_file function now returns dictionary (indexed by frame number) of FrameData objects that have load, displacement, and stress data. Also returns SpecimenDimensions object that holds width, thickness, gauge length, and overall length. --- src/main.py | 52 ++++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/main.py b/src/main.py index 26f1e0f..4a306fc 100644 --- a/src/main.py +++ b/src/main.py @@ -1,31 +1,37 @@ -############################################# -# EECS 442: Computer Vision - W19 # -############################################# -# Authors: Sravan Balaji & Kevin Monpara # -# Filename: main.py # -# Description: # -############################################# - -import numpy as np +############################################################# +# EECS 442: Computer Vision - W19 # +############################################################# +# Authors: Sravan Balaji & Kevin Monpara # +# Filename: main.py # +# Description: # +# Read data file to get specimen dimensions. # +# Read in load and displacement data for each frame. # +# Calculate stress from load and cross-sectional area. # +############################################################# class FrameData: load = 0 # Load in N disp = 0 # Displacement in mm + stress = 0 # Stress in MPa - def __init__(self, load, disp): + def __init__(self, load, disp, stress): self.load = load self.disp = disp + self.stress = stress -def calc_stress(): - file = open("../Section001_Data.txt", "r") - +class SpecimenDimensions: w = 0 # Specimen Width in mm t = 0 # Specimen Thickness in mm gl = 0 # Specimen Gauge Length in mm ol = 0 # Specimen Overall Length in mm + +def read_file(filepath): + file = open(filepath, "r") + + specimen = SpecimenDimensions() load_disp_data = dict() data_start = -1 @@ -34,19 +40,19 @@ def calc_stress(): for line in file: if "Width" in line: index = line.find("\t") - w = float(line[index + 1:]) + specimen.w = float(line[index + 1:]) if "Thickness" in line: index = line.find("\t") - t = float(line[index + 1:]) + specimen.t = float(line[index + 1:]) if "Gauge Length" in line: index = line.find("\t") - gl = float(line[index + 1:]) + specimen.gl = float(line[index + 1:]) if "Overall Length" in line: index = line.find("\t") - ol = float(line[index + 1:]) + specimen.ol = float(line[index + 1:]) if "Frame #" in line: data_start = 2 @@ -60,13 +66,19 @@ def calc_stress(): if in_frame_data: if line != '\t\t\n': frame_num_str, load_str, disp_str = line.split("\t") + frame_num = int(frame_num_str) + load = float(load_str) disp = float(disp_str) - load_disp_data[frame_num] = FrameData(load, disp) + stress = load / (specimen.w * specimen.t) - print("Done") + load_disp_data[frame_num] = FrameData(load, disp, stress) + + file.close() + + return specimen, load_disp_data if __name__ == "__main__": - calc_stress() + specimen, load_disp_data = read_file("../Section001_Data.txt") From 2a00d65e9f6aaba9be534b7165c6e1c308984f85 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Mon, 15 Apr 2019 20:01:06 -0400 Subject: [PATCH 3/6] Rename main.py to file_data.py and add new main.py * Rename old main.py to file_data.py * Add main.py that calls read_file function in file_data.py --- src/file_data.py | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ src/main.py | 78 +++++----------------------------------------- 2 files changed, 87 insertions(+), 71 deletions(-) create mode 100644 src/file_data.py diff --git a/src/file_data.py b/src/file_data.py new file mode 100644 index 0000000..5fb3bbf --- /dev/null +++ b/src/file_data.py @@ -0,0 +1,80 @@ +############################################################# +# EECS 442: Computer Vision - W19 # +############################################################# +# Authors: Sravan Balaji & Kevin Monpara # +# Filename: file_data.py # +# Description: # +# Read data file to get specimen dimensions. # +# Read in load and displacement data for each frame. # +# Calculate stress from load and cross-sectional area. # +############################################################# + + +class FrameData: + load = 0 # Load in N + disp = 0 # Displacement in mm + stress = 0 # Stress in MPa + + def __init__(self, load, disp, stress): + self.load = load + self.disp = disp + self.stress = stress + + +class SpecimenDimensions: + w = 0 # Specimen Width in mm + t = 0 # Specimen Thickness in mm + gl = 0 # Specimen Gauge Length in mm + ol = 0 # Specimen Overall Length in mm + + +def read_file(filepath): + file = open(filepath, "r") + + specimen = SpecimenDimensions() + load_disp_data = dict() + + data_start = -1 + in_frame_data = False + + for line in file: + if "Width" in line: + index = line.find("\t") + specimen.w = float(line[index + 1:]) + + if "Thickness" in line: + index = line.find("\t") + specimen.t = float(line[index + 1:]) + + if "Gauge Length" in line: + index = line.find("\t") + specimen.gl = float(line[index + 1:]) + + if "Overall Length" in line: + index = line.find("\t") + specimen.ol = float(line[index + 1:]) + + if "Frame #" in line: + data_start = 2 + + if data_start != -1: + data_start -= 1 + + if data_start == 0: + in_frame_data = True + + if in_frame_data: + if line != '\t\t\n': + frame_num_str, load_str, disp_str = line.split("\t") + + frame_num = int(frame_num_str) + + load = float(load_str) + disp = float(disp_str) + stress = load / (specimen.w * specimen.t) + + load_disp_data[frame_num] = FrameData(load, disp, stress) + + file.close() + + return specimen, load_disp_data diff --git a/src/main.py b/src/main.py index 4a306fc..d0034f2 100644 --- a/src/main.py +++ b/src/main.py @@ -1,84 +1,20 @@ ############################################################# -# EECS 442: Computer Vision - W19 # +# EECS 442: Computer Vision - W19 # ############################################################# # Authors: Sravan Balaji & Kevin Monpara # # Filename: main.py # # Description: # -# Read data file to get specimen dimensions. # -# Read in load and displacement data for each frame. # -# Calculate stress from load and cross-sectional area. # +# # ############################################################# - -class FrameData: - load = 0 # Load in N - disp = 0 # Displacement in mm - stress = 0 # Stress in MPa - - def __init__(self, load, disp, stress): - self.load = load - self.disp = disp - self.stress = stress +import file_data -class SpecimenDimensions: - w = 0 # Specimen Width in mm - t = 0 # Specimen Thickness in mm - gl = 0 # Specimen Gauge Length in mm - ol = 0 # Specimen Overall Length in mm +def main(): + specimen, load_disp_data = file_data.read_file("../Section001_Data.txt") - -def read_file(filepath): - file = open(filepath, "r") - - specimen = SpecimenDimensions() - load_disp_data = dict() - - data_start = -1 - in_frame_data = False - - for line in file: - if "Width" in line: - index = line.find("\t") - specimen.w = float(line[index + 1:]) - - if "Thickness" in line: - index = line.find("\t") - specimen.t = float(line[index + 1:]) - - if "Gauge Length" in line: - index = line.find("\t") - specimen.gl = float(line[index + 1:]) - - if "Overall Length" in line: - index = line.find("\t") - specimen.ol = float(line[index + 1:]) - - if "Frame #" in line: - data_start = 2 - - if data_start != -1: - data_start -= 1 - - if data_start == 0: - in_frame_data = True - - if in_frame_data: - if line != '\t\t\n': - frame_num_str, load_str, disp_str = line.split("\t") - - frame_num = int(frame_num_str) - - load = float(load_str) - disp = float(disp_str) - stress = load / (specimen.w * specimen.t) - - load_disp_data[frame_num] = FrameData(load, disp, stress) - - file.close() - - return specimen, load_disp_data + print("Done") if __name__ == "__main__": - specimen, load_disp_data = read_file("../Section001_Data.txt") + main() From b4245b6e3348900a032abd361831e9750280f79f Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Mon, 15 Apr 2019 20:01:54 -0400 Subject: [PATCH 4/6] Move Sift_Distance.py to src folder * Move Sift_Distance.py to src folder --- Sift_Distance.py => src/Sift_Distance.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename Sift_Distance.py => src/Sift_Distance.py (100%) diff --git a/Sift_Distance.py b/src/Sift_Distance.py similarity index 100% rename from Sift_Distance.py rename to src/Sift_Distance.py From 6ba776c8f08018b9b79bfee2b17c7cf03a6d9871 Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Mon, 15 Apr 2019 20:05:04 -0400 Subject: [PATCH 5/6] Reorganize Sift_Distance.py * Put Shift_Distance code into sift_distance function * Add import statements for numpy and opencv --- src/Sift_Distance.py | 40 ++++++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Sift_Distance.py b/src/Sift_Distance.py index dad454b..908de09 100644 --- a/src/Sift_Distance.py +++ b/src/Sift_Distance.py @@ -1,24 +1,28 @@ -sift = cv.xfeatures2d.SIFT_create() -original_kp, original_des = sift.detectAndCompute(left,None) -new_kp, new_des = sift.detectAndCompute(right,None) +import numpy as np +import cv2 -bf = cv2.BFMatcher() -matches = bf.knnMatch(original_des, new_des, k=2) -# Apply ratio test -good = [] -for m, n in matches: - if m.distance < 0.3 * n.distance: - good.append([m]) +def sift_distance(): + sift = cv2.xfeatures2d.SIFT_create() + original_kp, original_des = sift.detectAndCompute(left,None) + new_kp, new_des = sift.detectAndCompute(right,None) -# Featured matched keypoints from images 1 and 2 -pts1 = np.float32([original_kp[m.queryIdx].pt for m in good]) -pts2 = np.float32([new_kp[m.trainIdx].pt for m in good]) + bf = cv2.BFMatcher() + matches = bf.knnMatch(original_des, new_des, k=2) -#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]]) + # Apply ratio test + good = [] + for m, n in matches: + if m.distance < 0.3 * n.distance: + good.append([m]) -# Distance between featured matched keypoints -FM_dist = abs(z2 - z1) + # Featured matched keypoints from images 1 and 2 + 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 + z1 = np.array([[complex(c[0],c[1]) for c in pts1]]) + z2 = np.array([[complex(c[0],c[1]) for c in pts2]]) + + # Distance between featured matched keypoints + FM_dist = abs(z2 - z1) From ef445f5617182e41d9b29b7359fb542105e988ea Mon Sep 17 00:00:00 2001 From: Sravan Balaji Date: Mon, 15 Apr 2019 20:06:45 -0400 Subject: [PATCH 6/6] Update .gitignore * Add pycache files to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 9f11b75..68cd751 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/ +**/__pycache__/