Skip to content
Snippets Groups Projects
Commit eeef7a34 authored by tw00275's avatar tw00275
Browse files

computeResiduals() returns the residuals of each colour channel of each light direction

parent 9dc8191e
No related branches found
No related tags found
No related merge requests found
No preview for this file type
...@@ -21,7 +21,14 @@ struct CostFunctor { ...@@ -21,7 +21,14 @@ struct CostFunctor {
return true; return true;
} }
}; };
/*
struct CostFunctor {
template <typename T> bool operator()(const T* const SpecularIntensity, const T* const SpecularPower, T* residual) const {
residual[0] = returnResidual(lightNumber, height, width, textureImages, residualImage, residuals, SpecularIntensity, SpecularPower);
return true;
}
};
*/
void specularMinimisation(float& SpecularIntensity, float& SpecularPower, double& residual) { void specularMinimisation(float& SpecularIntensity, float& SpecularPower, double& residual) {
// The variable to solve for with its initial value. It will be mutated in place by the solver. // The variable to solve for with its initial value. It will be mutated in place by the solver.
......
...@@ -45,10 +45,10 @@ void photometricStereo(std::string imageName, std::string calibration, std::stri ...@@ -45,10 +45,10 @@ void photometricStereo(std::string imageName, std::string calibration, std::stri
texture = createTexture(modelPath, imageScale, textureImages, width, height); texture = createTexture(modelPath, imageScale, textureImages, width, height);
//loadSurfaceNormals(lightDirections, width, height, imageScale, modelPath, normals, Z, modelImages); loadSurfaceNormals(lightDirections, width, height, imageScale, modelPath, normals, Z, modelImages);
normals = cv::Mat(height, width, CV_32FC3, cv::Scalar(0,0,1)); //normals = cv::Mat(height, width, CV_32FC3, cv::Scalar(0,0,1));
Z = cv::Mat(height, width, CV_32FC2, cv::Scalar::all(0)); //Z = cv::Mat(height, width, CV_32FC2, cv::Scalar::all(0));
cv::GaussianBlur(Z, Z, cv::Size(3, 3), 0, 0); cv::GaussianBlur(Z, Z, cv::Size(3, 3), 0, 0);
//cv::resize(Z, Z, cv::Size(), 0.5, 0.5, cv::INTER_LINEAR); //cv::resize(Z, Z, cv::Size(), 0.5, 0.5, cv::INTER_LINEAR);
...@@ -136,6 +136,7 @@ void loadSurfaceNormals(cv::Mat lightDirections, int width, int height, int imag ...@@ -136,6 +136,7 @@ void loadSurfaceNormals(cv::Mat lightDirections, int width, int height, int imag
if (!normals.data) { if (!normals.data) {
normals = cv::Mat(height, width, CV_32FC3, cv::Scalar::all(0)); normals = cv::Mat(height, width, CV_32FC3, cv::Scalar::all(0));
//normals = cv::Mat(height, width, CV_32FC3, cv::Scalar(0,0,1));
// Estimate the surface normals and p, q gradients // Estimate the surface normals and p, q gradients
getSurfaceNormals(normals, pGradients, qGradients, lightDirectionsInverted, modelImages); getSurfaceNormals(normals, pGradients, qGradients, lightDirectionsInverted, modelImages);
std::cout << "Surface normals have been estimated.\n\n"; std::cout << "Surface normals have been estimated.\n\n";
......
This diff is collapsed.
...@@ -105,42 +105,44 @@ int main(int argc, char** argv) { ...@@ -105,42 +105,44 @@ int main(int argc, char** argv) {
float horizontalAngle, verticalAngle, FoV, SpecularIntensity = 0.5f, SpecularPower = 2.0f; float horizontalAngle, verticalAngle, FoV, SpecularIntensity = 0.5f, SpecularPower = 2.0f;
GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID; GLuint programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularPowerID;
std::vector<unsigned int> indices; std::vector<unsigned int> indices;
cv::Vec3d residual;
std::vector< cv::Vec3d > residuals;
int lightNumber = 0; int lightNumber = 0;
double residual;
bool calculateResidual = false; bool calculateResidual = false;
double totalResidual;
cv::Mat residualImage;
initialiseOpenGL(heightMap, normalMap, texture, textureImages, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower); initialiseOpenGL(heightMap, normalMap, texture, textureImages, lightDirections, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
//initialiseOpenGL(heightMap, normalMap, texture, textureImages, lightDirectionsPerspective, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower); //initialiseOpenGL(heightMap, normalMap, texture, textureImages, lightDirectionsPerspective, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
//initialiseOpenGL(heightMap, normalMap, texture, charucoImages, lightDirectionsPerspective, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower); //initialiseOpenGL(heightMap, normalMap, texture, charucoImages, lightDirectionsPerspective, width, height, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower);
/*
glm::mat4 ModelMatrix = glm::mat4(1.0);
glm::mat4 MVP, ViewMatrix, depthBiasMVP, ProjectionMatrix = glm::ortho(-0.5f * float(windowWidth) / float(windowHeight), 0.5f * float(windowWidth) / float(windowHeight), -0.5f, 0.5f, 0.0f, 10.0f);
bool perspectiveProjection, shadowControl;
computeResiduals(windowWidth, windowHeight, position, horizontalAngle, verticalAngle, FoV, ProjectionMatrix, ViewMatrix, lightInvDir, depthProjectionMatrix, depthViewMatrix, perspectiveProjection = false, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensity, SpecularPower);
*/
do {
openGL(lightNumber, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, residual, calculateResidual);
//openGL(lightNumber, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirectionsPerspective, textureImages, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, residual, calculateResidual);
//openGL(lightNumber, depthProjectionMatrix, depthViewMatrix, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirectionsPerspective, charucoImages, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, residual, calculateResidual);
// TODO: Check if the viewpoint has been changed
if (calculateResidual) {
specularMinimisation(SpecularIntensity, SpecularPower, residual);
//openGL(lightNumber, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, programID, MatrixID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, depthProgramID, quad_programID, FramebufferName, quad_vertexbuffer, VertexArrayID, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, residual, calculateResidual);
calculateResidual = false;
}
} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS && glfwWindowShouldClose(window) == 0); // Check if the ESC key was pressed or the window was closed
// The variable to solve for with its initial value. It will be mutated in place by the solver.
double x = SpecularIntensity;
const double initial_x = x;
// Build the problem.
Problem problem;
computeResiduals(residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID);
/*
// Run the solver!
Solver::Options options;
options.minimizer_progress_to_stdout = true;
Solver::Summary summary;
Solve(options, &problem, &summary);
std::cout << summary.BriefReport() << "\n";
std::cout << "Specular Intensity: " << initial_x << " -> " << x << "\n";
*/
viewModel(residual, residuals, totalResidual, residualImage, calculateResidual, depthProjectionMatrix, depthViewMatrix, width, height, position, horizontalAngle, verticalAngle, FoV, lightInvDir, lightDirections, textureImages, lightNumber, numberOfLights, SpecularIntensityID, SpecularIntensity, SpecularPowerID, SpecularPower, programID, ModelMatrixID, ViewMatrixID, DepthBiasID, lightInvDirID, Texture, TextureID, depthTexture, ShadowMapID, vertexbuffer, uvbuffer, normalbuffer, elementbuffer, indices, MatrixID);
terminateOpenGL(vertexbuffer, uvbuffer, normalbuffer, elementbuffer, programID, depthProgramID, quad_programID, Texture, FramebufferName, depthTexture, quad_vertexbuffer, VertexArrayID); terminateOpenGL(vertexbuffer, uvbuffer, normalbuffer, elementbuffer, programID, depthProgramID, quad_programID, Texture, FramebufferName, depthTexture, quad_vertexbuffer, VertexArrayID);
return 0; return 0;
} }
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment