Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Progressbar #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
.idea
.DS_Store
.idea

*venv/
*.pkl
*.avi
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ osqp==0.6.1
cvxpy==1.2.1
matplotlib==3.5.3
numpy==1.23.3
opencv-contrib-python==4.6.0.66
opencv-contrib-python==4.6.0.66
progressbar>=2.3
3 changes: 2 additions & 1 deletion script.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/env bash
echo "Preprocessing"
python3 src/preproc.py $1

echo "Optimizing trajectory"
python3 src/stabilize.py $2

echo "Generating output"
python3 src/generate.py $1 $2
python3 src/generate.py $1 $2
32 changes: 19 additions & 13 deletions src/preproc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
import numpy as np
import pickle
import sys
from progressbar import ProgressBar, Percentage, Bar, ETA

sift = cv2.xfeatures2d.SIFT_create(200)
pbar = ProgressBar(widgets=[Percentage(), Bar(), ETA()])


def getAffMat(I1, I2):
I1 = cv2.cvtColor(I1, cv2.COLOR_BGR2GRAY)
Expand All @@ -16,32 +19,35 @@ def getAffMat(I1, I2):
# Finding good matches using ratio testing
bf = cv2.BFMatcher()
matches = bf.knnMatch(desc1, desc2, k=2)

good = []
for m,n in matches:
for m, n in matches:
if m.distance < 0.7*n.distance:
good.append(m)

pts_src = []
pts_dst = []
for i in range(len(good)):
pts_src.append([kp1[good[i].queryIdx].pt[0], kp1[good[i].queryIdx].pt[1]])
pts_dst.append([kp2[good[i].trainIdx].pt[0], kp2[good[i].trainIdx].pt[1]])
pts_src.append([kp1[good[i].queryIdx].pt[0], kp1[good[i].queryIdx].pt[1]])
pts_dst.append([kp2[good[i].trainIdx].pt[0], kp2[good[i].trainIdx].pt[1]])

pts_src = np.array(pts_src).astype(np.float32)
pts_dst = np.array(pts_dst).astype(np.float32)

# Computing affine matrix using the best matches
return cv2.estimateAffinePartial2D(pts_src, pts_dst)[0]


v = cv2.VideoCapture(sys.argv[1])
n_frames = int(v.get(cv2.CAP_PROP_FRAME_COUNT))
pbar.maxval = n_frames
pbar.start()

# Generating the Xdata and Ydata
transforms = [[], [], [], []]
count = 0
while v.isOpened():

ret, frame = v.read()

if ret == True:
Expand All @@ -54,19 +60,19 @@ def getAffMat(I1, I2):
transforms[2].append(np.arctan2(transMat[1][0], transMat[0][0]))
transforms[3].append(np.sqrt(transMat[1][0]**2 + transMat[0][0]**2))
except:
transforms[0].append(0)
transforms[1].append(0)
transforms[2].append(0)
transforms[3].append(1)
transforms[0].append(0)
transforms[1].append(0)
transforms[2].append(0)
transforms[3].append(1)

count += 1
prev = frame
print( str((count/n_frames)*100) + "% completed")
pbar.update(count)
else:
break
break

v.release()

# Storing the data
with open('transforms.pkl', 'wb') as f:
pickle.dump(transforms, f)
pickle.dump(transforms, f)