Skip to content
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
15 changes: 8 additions & 7 deletions R/estimateDistortion.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ estimateDistortion <- function(undistort.params, img.size){
# Try different starting parameters
p_start <- list(
rep(0, 5),
c(0.1, NA, NA, NA, NA),
c(0.1, 0.01, NA, NA, NA),
c(0.14, 0.006, 0.002, NA, NA),
c(0.1, 0.01, 1e-5, NA, NA),
c(0.1),
c(0.1, 0.01),
c(0.14, 0.006, 0.002),
c(0.1, 0.01, 1e-5),
#c(0.1, 0.01, 1e-5, -1e-5, -0.1),
c(0.01, -0.001, 1e-5, NA, NA),
c(0.01, 0.1, -1e-5, NA, NA)
c(0.01, -0.001, 1e-5),
c(0.01, 0.1, -1e-5)
)

# Save with each try
Expand Down Expand Up @@ -53,6 +53,7 @@ estimateDistortion <- function(undistort.params, img.size){

# Get parameter from run with the lowest error (including no distortion case)
p <- par[[which.min(objectives)]]
p <- c(p, rep(NA, 7 - length(p)))

# Add names to parameters
names(p) <- c('cx', 'cy', 'k1', 'k2', 'k3', 'p1', 'p2')
Expand All @@ -71,4 +72,4 @@ estimateDistortion <- function(undistort.params, img.size){
#points(u_corners, cex=0.5, col='red')
#points(rd_corners, cex=0.7, col='green')
#dev.off()
}
}
15 changes: 8 additions & 7 deletions R/estimateUndistortion.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ estimateUndistortion <- function(coor.2d, cal.nx, image.size){
# TRY DIFFERENT STARTING PARAMETERS
p_start <- list(
rep(0, 5),
c(0.1, NA, NA, NA, NA),
c(0.1, 0.01, NA, NA, NA),
c(0.14, 0.006, 0.002, NA, NA),
c(0.1, 0.01, 1e-5, NA, NA),
c(0.1),
c(0.1, 0.01),
c(0.14, 0.006, 0.002),
c(0.1, 0.01, 1e-5),
#c(0.1, 0.01, 1e-5, -1e-5, -0.1),
c(0.01, -0.001, 1e-5, NA, NA),
c(0.01, 0.1, -1e-5, NA, NA)
c(0.01, -0.001, 1e-5),
c(0.01, 0.1, -1e-5)
)

# SAVE WITH EACH TRY
Expand Down Expand Up @@ -60,9 +60,10 @@ estimateUndistortion <- function(coor.2d, cal.nx, image.size){

# GET PARAMETERS FROM RUN WITH LOWEST ERROR (INCLUDING NO DISTORTION CASE)
dist_params <- par[[which.min(objectives)]]
dist_params <- c(dist_params, rep(NA, 7 - length(dist_params)))

# ADD NAMES TO PARAMETERS
names(dist_params) <- c('cx', 'cy', 'k1', 'k2', 'k3', 'p1', 'p2')

dist_params
}
}