Skip to content

Commit

Permalink
Refactor code for speed and clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
UltralyticsAssistant committed Aug 26, 2024
1 parent 1111329 commit e7beec1
Show file tree
Hide file tree
Showing 6 changed files with 1 addition and 11 deletions.
2 changes: 0 additions & 2 deletions utils/KLT.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 License https://ultralytics.com/license

import cv2

from utils.common import *
from utils.images import boundingRect

Expand Down Expand Up @@ -101,7 +100,6 @@ def KLTmain(im, im0, im0_small, p0):
"""Runs the Kanade-Lucas-Tomasi (KLT) feature tracking algorithm with coarse-to-fine tracking and affine
transformation.
"""

# Parameters for KLT
EPS = cv2.TERM_CRITERIA_EPS
COUNT = cv2.TERM_CRITERIA_COUNT
Expand Down
3 changes: 0 additions & 3 deletions utils/MSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def fcnMSV1_t(K, P, B, vg, ii): # solves for 1 camera translation
"""Solves for 1 camera translation by optimizing translation vectors given camera matrix K, pixel coordinates P,
baseline B, valid mask vg, and image index ii.
"""

# vg = np.isnan(P[0, :, i])==False
nf = ii + 1
ng = vg.sum()
Expand Down Expand Up @@ -52,7 +51,6 @@ def fcnMSV1_t(K, P, B, vg, ii): # solves for 1 camera translation

def fcnMSV2_t(K, P, B, vg, i): # solves for 1 camera translation
"""Solves for 1 camera translation via iterative minimization, returns optimized camera parameters as np.float32."""

# vg = np.isnan(P[0, :, i])==False
nf = i + 1
ng = vg.sum()
Expand Down Expand Up @@ -101,7 +99,6 @@ def fcn2vintercept(A, U):
"""Calculates 3D intercepts of vectors (U) from origins (A) for camera frame combinations, returning nx3 tie point
centers.
"""

# A = nx3 camera origins, ux1 = nxnp x unit vectors
_, nf, nv = U.shape # 3, nframes, npoints
C0 = np.zeros([nv, 3])
Expand Down
2 changes: 0 additions & 2 deletions utils/NLS.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ def estimateWorldCameraPose(K, p, p3, t=np.array([0, 0, 1]), R=np.eye(3), findR=
Args: K (array): camera matrix, p (2D array): image points, p3 (3D array): world points, t (array, optional): initial translation, R (array, optional): initial rotation, findR (bool, optional): if True estimates rotation. Returns: tuple (translation, rotation, residuals, projected points).
"""

# Linear solution
# Re, te = extrinsicsPlanar(p, p3, K)

Expand Down Expand Up @@ -132,7 +131,6 @@ def fcnNLS_t(K, p, pw, x):
# @profile
def fcnNLS_Rt(K, p, pw, x):
"""Estimates camera rotation (R) and translation (t) from world to image points using Non-Linear Least Squares."""

# K = 3x3 intrinsic matrix
# p = nx2 image points
# pw = nx3 world points = pc @ cam2ned().T
Expand Down
1 change: 0 additions & 1 deletion utils/images.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Ultralytics YOLO 🚀, AGPL-3.0 License https://ultralytics.com/license

import cv2

from utils.common import *
from utils.strings import *

Expand Down
1 change: 0 additions & 1 deletion utils/vid2images.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import os

import cv2

import utils.common

PATH = "/Users/glennjocher/Downloads/DATA/VSM/chessboard/IMG_4414.MOV"
Expand Down
3 changes: 1 addition & 2 deletions vidExample.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# Ultralytics YOLO 🚀, AGPL-3.0 License https://ultralytics.com/license

import scipy

import plots
import scipy
from utils.images import *
from utils.KLT import *
from utils.MSV import *
Expand Down

0 comments on commit e7beec1

Please sign in to comment.