Commit 3bc4c13c authored by Matt Clarkson's avatar Matt Clarkson

Issue #61: Tidy up, finalise stereo method.

parent 68cb7ed2
......@@ -105,17 +105,24 @@ if(ITK_FOUND)
endif()
list(APPEND CMAKE_PREFIX_PATH /usr/local/lib/cmake/Ceres/)
list(APPEND CMAKE_PREFIX_PATH /Users/mattclarkson/build/CMakeCatchTemplate-SuperBuild-Qt5/gflags/install)
list(APPEND CMAKE_PREFIX_PATH /Users/mattclarkson/build/CMakeCatchTemplate-SuperBuild-Qt5/glog/install)
find_package(Ceres REQUIRED)
include_directories(${CERES_INCLUDE_DIRS})
list(APPEND NIFTYCAL_SRCS Internal/niftkNonLinearCeresStereoOptimiser.cxx)
list(APPEND NIFTYCAL_SRCS Internal/niftkNonLinearCeresMonoOptimiser.cxx)
include_directories(/Users/mattclarkson/install/gsl-2.5/include)
###############################################################################
# Start of Highly Experimental Section: Do not use.
###############################################################################
#list(APPEND CMAKE_PREFIX_PATH /usr/local/lib/cmake/Ceres/)
#list(APPEND CMAKE_PREFIX_PATH /Users/mattclarkson/build/CMakeCatchTemplate-SuperBuild-Qt5/gflags/install)
#list(APPEND CMAKE_PREFIX_PATH /Users/mattclarkson/build/CMakeCatchTemplate-SuperBuild-Qt5/glog/install)
#
#find_package(Ceres REQUIRED)
#include_directories(${CERES_INCLUDE_DIRS})
#
#list(APPEND NIFTYCAL_SRCS Internal/niftkNonLinearCeresStereoOptimiser.cxx)
#list(APPEND NIFTYCAL_SRCS Internal/niftkNonLinearCeresMonoOptimiser.cxx)
#
#include_directories(/Users/mattclarkson/install/gsl-2.5/include)
###############################################################################
# End of Highly Experimental Section: Do not use.
###############################################################################
###############################################################################
# Experimental: Try to calibrate based on rendering the model.
......
......@@ -254,10 +254,10 @@ public:
ry
);
residuals[residualCounter++] = lx - T(static_cast<double>(m_LeftImagePoint(0)));
residuals[residualCounter++] = ly - T(static_cast<double>(m_LeftImagePoint(1)));
residuals[residualCounter++] = rx - T(static_cast<double>(m_RightImagePoint(0)));
residuals[residualCounter++] = ry - T(static_cast<double>(m_RightImagePoint(1)));
residuals[residualCounter++] = (lx - T(static_cast<double>(m_LeftImagePoint(0))));
residuals[residualCounter++] = (ly - T(static_cast<double>(m_LeftImagePoint(1))));
residuals[residualCounter++] = (rx - T(static_cast<double>(m_RightImagePoint(0))));
residuals[residualCounter++] = (ry - T(static_cast<double>(m_RightImagePoint(1))));
/*
residuals[residualCounter++] =
......
......@@ -91,7 +91,7 @@ double NonLinearMonoCameraCalibration3DOptimiser::Optimise(std::vector<cv::Mat>&
optimiser->UseCostFunctionGradientOff(); // use default VNL derivative, not our one.
optimiser->SetCostFunction(m_CostFunction);
optimiser->SetInitialPosition(initialParameters);
optimiser->SetNumberOfIterations(10000);
optimiser->SetNumberOfIterations(100);
optimiser->SetGradientTolerance(0.0000001);
optimiser->SetEpsilonFunction(0.0000001);
optimiser->SetValueTolerance(0.0000001);
......@@ -119,7 +119,7 @@ double NonLinearMonoCameraCalibration3DOptimiser::Optimise(std::vector<cv::Mat>&
niftk::NonLinearMonoCameraCalibration3DCostFunction::MeasureType finalValues = m_CostFunction->GetValue(finalParameters);
double finalRMS = m_CostFunction->GetRMS(finalValues);
/*
for (unsigned int i = 0; i < finalParameters.size(); i++)
{
std::cout << "NonLinearMonoCameraCalibration3DOptimiser: " << initialParameters[i]
......@@ -127,6 +127,7 @@ double NonLinearMonoCameraCalibration3DOptimiser::Optimise(std::vector<cv::Mat>&
<< "\t" << finalParameters[i] - initialParameters[i]
<< std::endl;
}
*/
std::cout << "NonLinearMonoCameraCalibration3DOptimiser: finalRMS=" << finalRMS << ", stopped by " << optimiser->GetStopConditionDescription() << std::endl;
return finalRMS;
......
......@@ -980,8 +980,6 @@ double ComputeRMSReprojectionError(
)
{
double rms = 0;
double rmsLeft = 0;
double rmsRight = 0;
unsigned int pointCounter = 0;
unsigned int pointCounterLeft = 0;
unsigned int pointCounterRight = 0;
......@@ -1038,10 +1036,7 @@ double ComputeRMSReprojectionError(
rms += dx;
rms += dy;
rmsLeft += dx;
rmsLeft += dy;
}
std::cerr << "Matt, left v=" << viewCounter << ", rmsLeft=" << std::sqrt(rmsLeft / (2*numberOfPointsInLeft)) << std::endl;
cv::Matx44d rightExtrinsic = leftToRight * leftExtrinsic;
unsigned int numberOfPointsInRight = niftk::ProjectMatchingPoints(model,
......@@ -1059,10 +1054,7 @@ double ComputeRMSReprojectionError(
double dy = ((observed[i].y - projected[i].y) * (observed[i].y - projected[i].y));
rms += dx;
rms += dy;
rmsRight += dx;
rmsRight += dy;
}
std::cerr << "Matt, right v=" << viewCounter << ", rmsRight=" << std::sqrt(rmsRight / (2 * numberOfPointsInRight)) << std::endl;
pointCounter += (2 * (numberOfPointsInLeft + numberOfPointsInRight));
pointCounterLeft += 2*numberOfPointsInLeft;
......@@ -1073,14 +1065,9 @@ double ComputeRMSReprojectionError(
if (pointCounter != 0)
{
rms /= static_cast<double>(pointCounter);
rmsLeft /= static_cast<double>(pointCounterLeft);
rmsRight /= static_cast<double>(pointCounterRight);
}
rms = sqrt(rms);
rmsLeft = sqrt(rmsLeft);
rmsRight = sqrt(rmsRight);
std::cerr << "Matt, rmsLeft=" << rmsLeft << ", rmsRight=" << rmsRight << std::endl;
return rms;
}
......
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment