Learn R Programming

StereoMorph (version 1.6.7)

dltNearestPointOnEpipolar: Returns the closest point on a epipolar line to a point or points

Description

Given the same point in two camera views, this function finds the nearest point on the epipolar line of the point in the first view to a point or points in the second view.

Usage

dltNearestPointOnEpipolar(p1, p2, cal.coeff)

Arguments

p1

vector of x,y pixel coordinates for a point in the camera view corresponding to the first column of cal.coeff. This point will be used to generate an epipolar line in the second view.

p2

an x,y vector or two-column matrix of a point or points in a second camera view, corresponding to the second column of cal.coeff. The nearest point on the epipolar line will be an orthogonal projection from a point in p2.

cal.coeff

a two-column matrix of DLT calibration coefficients, where each column corresponds to the views from which p1 and p2 were taken, respectively.

Value

a list with the following elements:

matching.pt

an x,y vector of the point on the epipolar line of p1 closest to point(s) p2.

min.idx

the index in p2 of the nearest point to the epipolar line of p1. If p2 is a single point (vector), min.idx will be 1.

p2.dist

the epipolar distance between matching.pt and the point in p2 at the min.idx.

Details

In a stereo camera setup, a point in one camera view must fall somewhere along a line in a second camera view. This line is called its epipolar line. Due to error in manually selecting the same point in two camera views and error in the calibration, the epipolar line of the point in the first view will not intersect exactly with the same point in the second view. The nearest point on the epipolar line is a point at a minimum distance from the point in the second view. This is equivalent to the orthogonal projection (orthogonalProjectionToLine) of the point in the second view onto the epipolar line of the point in the first view. The length of this line is the epipolar distance (dltEpipolarDistance).

dltNearestPointOnEpipolar() first finds the epipolar line of p1, a point in the first camera view, and then finds the point on this epipolar line nearest to point(s) p2 in the second camera view. If p2 is a single point, dltNearestPointOnEpipolar() finds the point on the epipolar line closest to p2. If p2 is a matrix of points, the point in p2 closest to the epipolar line is first identified and then the point on the epipolar line closest to this point is determined.

References

For a general overview of DLT: http://kwon3d.com/theory/dlt/dlt.html

See Also

dltCalibrateCameras, dltEpipolarDistance, dltEpipolarLine, dltMatchCurvePoints

Examples

Run this code
# NOT RUN {
## FIND THE FILE DIRECTORY FOR EXTRA R PACKAGE FILES
fdir <- paste0(path.package("StereoMorph"), "/extdata/")

## SET FILE PATH TO CALIBRATION COEFFICIENTS IN TWO CAMERA STEREO SETUP
cc_file <- paste0(fdir, "cal_coeffs.txt")

## LOAD COEFFICIENTS
cal.coeff <- as.matrix(read.table(file=cc_file))

## GET LANDMARKS IN FIRST CAMERA VIEW
lm_files <- paste0(fdir, c("lm_2d_a1_v1.txt", "lm_2d_a1_v2.txt"))

## READ LANDMARKS INTO MATRIX
lm.array <- readLandmarksToArray(file=lm_files, row.names=1)

## FIND THE NEAREST POINT ON THE EPIPOLAR LINE OF P1
dltNearestPointOnEpipolar(p1=lm.array[3, , 1], p2=lm.array[3, , 2], cal.coeff=cal.coeff)

## FIND THE NEAREST POINT ON THE EPIPOLAR LINE OF P1
## THIS TIME USING ALL LANDMARKS IN THAT VIEW
## FUNCTION IDENTIFIES THE CORRECT LANDMARK IN THE SECOND VIEW AS THE SAME LANDMARK
dltNearestPointOnEpipolar(p1=lm.array[3, , 1], p2=lm.array[, , 2], cal.coeff=cal.coeff)

# }

Run the code above in your browser using DataLab