Skip to content

Commit

Permalink
Merge branch 'master' of github.com:amrut-prabhu/table-tennis-ball-tr…
Browse files Browse the repository at this point in the history
…ajectory
  • Loading branch information
RonakLakhotia committed Nov 16, 2018
2 parents d02e3ad + 21d685a commit 70f0c50
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 120 deletions.
Binary file removed Project_Instructions.pdf
Binary file not shown.
31 changes: 0 additions & 31 deletions ball_tracking.m~

This file was deleted.

57 changes: 57 additions & 0 deletions clean_annotation_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from os import listdir, rename
from os.path import isfile, join
import pandas as pd
import os
from shutil import copy2

#mypath = 'C:/Users/cksas/Desktop/Annotation'
mypath = os.getcwd()
mypath = join(mypath, 'Actual')
resultsPath = os.getcwd()
resultsPath = join(resultsPath, 'CleanData')
folders = ['CAM1', 'CAM2', 'CAM3']
fl = pd.read_csv((join(mypath, 'FileList.csv')), names = folders)

for folder in folders:
for i in range(10):
name = fl[folder][i].split('.')[0]
name = name + '.csv'
newname = folder + '-' + str(i) + '_cleaned.csv'
print (name)
print (join(resultsPath, newname))
copy2(join(mypath, folder, name), join(resultsPath, newname))

# Clean the data files
n1 = 'CAM1-'
n2 = 'CAM2-'
n3 = 'CAM3-'

for i in range(10):
fnames = [n1 + str(i) + '_cleaned.csv', n2 + str(i) + '_cleaned.csv', n3 + str(i) + '_cleaned.csv']
df1 = pd.read_csv(join(resultsPath, fnames[0]))
df1 = df1.dropna()
df2 = pd.read_csv(join(resultsPath, fnames[1]))
df2 = df2.dropna()
df3 = pd.read_csv(join(resultsPath, fnames[2]))
df3 = df3.dropna()

f2 = df2['frame']
f3 = df3['frame']
commonFrames = []

for index, row in df1.iterrows():
frameNum = row['frame']
if frameNum in f2 and frameNum in f3:
commonFrames.append(frameNum)

print (len(commonFrames))

df1 = df1.query('frame in @commonFrames')
df2 = df2.query('frame in @commonFrames')
df3 = df3.query('frame in @commonFrames')

df1.to_csv(join(resultsPath, fnames[0].split('.')[0] + '.csv'))
df2.to_csv(join(resultsPath, fnames[1].split('.')[0] + '.csv'))
df3.to_csv(join(resultsPath, fnames[2].split('.')[0] + '.csv'))


29 changes: 0 additions & 29 deletions clean_data.py

This file was deleted.

5 changes: 3 additions & 2 deletions plotErrorVisualization.m
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function plotErrorVisualization(i, res, results_path)
hold on;

% Plot points
scatter3(res(:, 1), res(:, 2), res(:, 3), 'MarkerEdgeColor', [0 0 0.5]);
plot3(res(:, 1), res(:, 2), res(:, 3), 'MarkerEdgeColor', [0 0 0.5]);
hold on;

% Plot smooth curve for data points
Expand All @@ -111,7 +111,8 @@ function plotErrorVisualization(i, res, results_path)
ylim([-2.5 2.5])
zlim([-0.5 1.5])

title('Trajectory');
legend('Actual Data', 'Smooth Data')
title('Error Analysis');

% Save figure as .jpg
p = fullfile(results_path, strcat('error_visualization_', num2str(i), '.jpg'));
Expand Down
7 changes: 7 additions & 0 deletions remove_tracking_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

removedCsvCount = 0;
removedPngCount = 0;
removedAviCount = 0;

# Remove all the files generated by the MATLAB code for tracking the table tennis ball
for camNum in [1, 2, 3]:
Expand All @@ -19,5 +20,11 @@
os.remove(pathToResult)
removedPngCount += 1

if file.endswith(".avi"):
# Remove the png file containing the averaged background of a video
os.remove(pathToResult)
removedAviCount += 1

print("Removed ", removedCsvCount, " csv files");
print("Removed ", removedPngCount, " png files");
print("Removed ", removedAviCount, " avi files");
51 changes: 0 additions & 51 deletions rename_files.py

This file was deleted.

17 changes: 13 additions & 4 deletions showTrackedBall.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ function showTrackedBall(pathToFile, xPositions, yPositions)
videoObj = VideoReader(pathToFile);
NUM_FRAMES = videoObj.NumberOfFrames;
fig = figure;
baseName = pathToFile(1:find(pathToFile=='.')-1);

% Read coordinates from csv file, if exists
csvFile = strcat(pathToFile, '.csv');
csvFile = strcat(baseName, '.csv');
if exist(csvFile, 'file')
trackedCsv = csvread(csvFile,1,0);
xPositions = trackedCsv(:, 2);
yPositions = trackedCsv(:, 3);
end

numTracked = size(xPositions);
numTracked = numTracked(1);

workingDir = tempname;
mkdir(workingDir)
mkdir(workingDir,'images')

for frameNum = 1 : size(trackedCsv)
for frameNum = 1 : NUM_FRAMES
% Do not show warnings
MSGID = 'images:initSize:adjustingMag';
warning('off', MSGID);
Expand All @@ -24,8 +28,13 @@ function showTrackedBall(pathToFile, xPositions, yPositions)
vidFrame = read(videoObj, frameNum);
imshow(vidFrame);

x = xPositions(frameNum);
y = yPositions(frameNum);
if frameNum <= numTracked
x = xPositions(frameNum);
y = yPositions(frameNum);
else
x = -1;
y = -1;
end

frameWithMarker = vidFrame;
if x > 0 && y > 0
Expand Down
3 changes: 1 addition & 2 deletions tracking_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ def calculate_tracking_error(truthFile, resultFile, videoId):


numProcessedFiles = 0;
truthDir = os.path.join('.', 'Actual');

<<<<<<< HEAD
for camNum in [2]:
Expand All @@ -43,7 +42,7 @@ def calculate_tracking_error(truthFile, resultFile, videoId):
pathToResultFile = os.path.join(resultDir, file);

videoId = file.split(".")[0];
pathToTruthFile = os.path.join(truthDir, videoId + ".csv");
pathToTruthFile = os.path.join('.', 'Actual', 'CAM' + str(camNum), videoId + ".csv");

calculate_tracking_error(pathToTruthFile, pathToResultFile, videoId);
numProcessedFiles += 1;
Expand Down
2 changes: 1 addition & 1 deletion triangulate_positions.m
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
ylim([-2.5 2.5])
zlim([-0.5 1.5])

title('Trajectory');
title('Trajectory of ball');

figName = strcat('Trajectory of Ball for Sequence: ', num2str(i));
set(figH, 'NumberTitle', 'off', 'Name', figName);
Expand Down

0 comments on commit 70f0c50

Please sign in to comment.