This commit is contained in:
Kevin Monpara
2019-04-21 16:04:35 -04:00
4 changed files with 130 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
.idea/
**/__pycache__/

28
src/Sift_Distance.py Normal file
View File

@@ -0,0 +1,28 @@
import numpy as np
import cv2
def sift_distance():
sift = cv2.xfeatures2d.SIFT_create()
original_kp, original_des = sift.detectAndCompute(left,None)
new_kp, new_des = sift.detectAndCompute(right,None)
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])
# 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)

80
src/file_data.py Normal file
View File

@@ -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

20
src/main.py Normal file
View File

@@ -0,0 +1,20 @@
#############################################################
# EECS 442: Computer Vision - W19 #
#############################################################
# Authors: Sravan Balaji & Kevin Monpara #
# Filename: main.py #
# Description: #
# #
#############################################################
import file_data
def main():
specimen, load_disp_data = file_data.read_file("../Section001_Data.txt")
print("Done")
if __name__ == "__main__":
main()