diff --git a/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/PhotometricStereo.cc.o b/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/PhotometricStereo.cc.o index 0778d839d667e7cf5f5091b1e45de55a6eac8f89..2093a391c910169bfeb9ec48481543c2d3bc26d9 100644 Binary files a/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/PhotometricStereo.cc.o and b/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/PhotometricStereo.cc.o differ diff --git a/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/specular_estimation.cc.o b/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/specular_estimation.cc.o index 75db233ceb7bb72734f3d17a2aa61848997dcd6c..e3a201f56cb04419f5cbeb9867bedb856846b23d 100644 Binary files a/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/specular_estimation.cc.o and b/apps/specular_estimation/CMakeFiles/specular_estimation.dir/src/specular_estimation.cc.o differ diff --git a/apps/specular_estimation/src/Ceres.h b/apps/specular_estimation/src/Ceres.h index 74ce3afda99b2ce5e7625c0cad7c5a00dac81ff5..43788aadacab8c38eec66eeb879262d53b21c70c 100644 --- a/apps/specular_estimation/src/Ceres.h +++ b/apps/specular_estimation/src/Ceres.h @@ -34,10 +34,11 @@ class MyScalarCostFunctor { double sum = 0; for(int i = 0; i < numberOfLights_; i++) { - + std::cout << "Rendering polygons\n"; // Render the polygons renderPolygons(width_, height_, programID_, lightInvDirs_[i], MatrixID_, ModelMatrixID_, ViewMatrixID_, DepthBiasID_, lightInvDirID_, Texture_, TextureID_, depthTexture_, ShadowMapID_, vertexbuffer_, uvbuffer_, normalbuffer_, elementbuffer_, indices_, MVP_, ModelMatrix_, ViewMatrix_, depthBiasMVP_, SpecularIntensityID_, specularIntensity, SpecularPowerID_, specularPower); + std::cout << "Calculating residual\n"; meanSquaredError(i, height_, width_, textureImages_, sum, gain, bias); //structuralSimilarityIndex(i, height_, width_, textureImages_, sum, gain, bias); @@ -118,7 +119,7 @@ void specularMinimisation(double& SpecularIntensity, double& SpecularPower, doub problem.SetParameterUpperBound(&Gain, 0, 2); problem.SetParameterLowerBound(&Bias, 0, -1); problem.SetParameterUpperBound(&Bias, 0, 1); - + // Run the solver! Solver::Options options; options.minimizer_progress_to_stdout = true; diff --git a/apps/specular_estimation/src/OpenGL.h b/apps/specular_estimation/src/OpenGL.h index 4869438cdc251d1bac08ccd0c9a8b672f8be0fc8..fa494cec9ca4576806e613f135ba464157a9ec57 100644 --- a/apps/specular_estimation/src/OpenGL.h +++ b/apps/specular_estimation/src/OpenGL.h @@ -227,13 +227,13 @@ void initialiseOpenGL(cv::Mat cv_depth, cv::Mat cv_normals, cv::Mat cv_texture, // Create and compile the GLSL program from the shaders quad_programID = LoadShaders("/home/thomas/Documents/Minimisation/apps/specular_estimation/src/Passthrough.vertexshader", "/home/thomas/Documents/Minimisation/apps/specular_estimation/src/SimpleTexture.fragmentshader"); - std::cout << "Shaders loaded.\n"; + //std::cout << "Shaders loaded.\n"; GLuint texID = glGetUniformLocation(quad_programID, "texture"); - std::cout << "Uniform Location of texture found.\n"; + //std::cout << "Uniform Location of texture found.\n"; // Create and compile the GLSL program from the shaders programID = LoadShaders("/home/thomas/Documents/Minimisation/apps/specular_estimation/src/ShadowMapping.vertexshader", "/home/thomas/Documents/Minimisation/apps/specular_estimation/src/ShadowMapping.fragmentshader"); - + // Get a handle for the "myTextureSampler" uniform TextureID = glGetUniformLocation(programID, "myTextureSampler"); //SpecularID = glGetUniformLocation(programID, "mySpecularSampler"); @@ -1404,7 +1404,7 @@ void calibrateLights(int& windowWidth, int& windowHeight, cv::Mat cv_texture) { // Get a handle for the "MVP" uniform GLuint depthMatrixID = glGetUniformLocation(depthProgramID, "depthMVP"); - + // Load the texture //GLuint Texture = loadDDS("uvmap.DDS"); GLuint Texture = loadMat(cv_texture); @@ -1494,19 +1494,19 @@ void calibrateLights(int& windowWidth, int& windowHeight, cv::Mat cv_texture) { // Create and compile our GLSL program from the shaders GLuint quad_programID = LoadShaders("/home/thomas/Documents/Minimisation/apps/specular_estimation/src/Passthrough.vertexshader", "/home/thomas/Documents/Minimisation/apps/specular_estimation/src/SimpleTexture.fragmentshader"); - std::cout << "Shaders loaded.\n"; + //std::cout << "Shaders loaded.\n"; GLuint texID = glGetUniformLocation(quad_programID, "texture"); - std::cout << "Uniform Location of texture found.\n"; + //std::cout << "Uniform Location of texture found.\n"; // Create and compile our GLSL program from the shaders GLuint programID = LoadShaders("/home/thomas/Documents/Minimisation/apps/specular_estimation/src/ShadowMapping.vertexshader", "/home/thomas/Documents/Minimisation/apps/specular_estimation/src/ShadowMapping.fragmentshader"); - + // Get a handle for our "myTextureSampler" uniform GLuint TextureID = glGetUniformLocation(programID, "myTextureSampler"); - + GLuint SpecularIntensityID = glGetUniformLocation(programID, "specularIntensity"); GLuint SpecularPowerID = glGetUniformLocation(programID, "specularPower"); - + // Get a handle for our "MVP" uniform GLuint MatrixID = glGetUniformLocation(programID, "MVP"); GLuint ViewMatrixID = glGetUniformLocation(programID, "V"); diff --git a/apps/specular_estimation/src/PhotometricStereo.cc b/apps/specular_estimation/src/PhotometricStereo.cc index 89d0a4ab3cfb6510ede88962c72df0d292f6d1fb..80e475f17f805909a8205597d2050e64059ea13b 100755 --- a/apps/specular_estimation/src/PhotometricStereo.cc +++ b/apps/specular_estimation/src/PhotometricStereo.cc @@ -194,7 +194,7 @@ photometryStero::photometryStero(int imageNumber, std::string modelPath, std::st std::string indexString = stm.str(); std::string imageNameStr = modelPath + indexString + ".png"; - cv::Mat modelImage = cv::imread(modelPath + indexString + ".png", cv::IMREAD_COLOR); + cv::Mat modelImage = cv::imread(imageNameStr, cv::IMREAD_COLOR); if (!modelImage.data) { // Check if any images failed to load std::cout << imageNumber << " model images have been loaded." << std::endl; diff --git a/apps/specular_estimation/src/ShadowMapping.fragmentshader b/apps/specular_estimation/src/ShadowMapping.fragmentshader index 006a36ae9393b66fd18ca5a05c1534dbae033785..02348908da47c760a1911653772307d804dccdef 100644 --- a/apps/specular_estimation/src/ShadowMapping.fragmentshader +++ b/apps/specular_estimation/src/ShadowMapping.fragmentshader @@ -6,7 +6,7 @@ in vec3 Normal_cameraspace; in vec3 EyeDirection_cameraspace; in vec3 LightDirection_cameraspace; in vec4 ShadowCoord; -//in vec3 Position_worldspace; +in vec3 Position_worldspace; // Ouput data layout(location = 0) out vec3 color; @@ -16,7 +16,7 @@ uniform sampler2D myTextureSampler; //uniform sampler2D mySpecularSampler; uniform mat4 MV; uniform sampler2DShadow shadowMap; -//uniform vec3 LightPosition_worldspace; +uniform vec3 LightPosition_worldspace; uniform float specularIntensity; uniform float specularPower; @@ -73,7 +73,7 @@ void main() { //vec3 MaterialSpecularColor = texture( myTextureSampler, UV ).rgb; // Distance to the light - //float distance = length( LightPosition_worldspace - Position_worldspace ); + float distance = length( LightPosition_worldspace - Position_worldspace ); // Normal of the computed fragment, in camera space vec3 n = normalize( Normal_cameraspace ); diff --git a/apps/specular_estimation/src/specular_estimation.cc b/apps/specular_estimation/src/specular_estimation.cc index 2ed7779433cc32eb2e98f868e62c28292be8f262..1d643291e389de177178995235d3262e1cb5647b 100644 --- a/apps/specular_estimation/src/specular_estimation.cc +++ b/apps/specular_estimation/src/specular_estimation.cc @@ -6,8 +6,9 @@ void denseSample(std::string imageName, std::string calibration, double Specular void denseSyntheticSample(std::string imageName, std::string calibration, double SpecularIntensity, double SpecularPower); SpecularEstimation::SpecularEstimation(std::string imageName, std::string calibration, bool denseSample, double SpecularIntensity, double SpecularPower) { - loadTextureImages(); - + modelPath = imagesPath + folderPath + "/" + imageName + "/" + imageName + "."; + calibrationPath = imagesPath + folderPath + "/" + calibration + "/" + calibration + "."; + PhotometricStereo(); cv::cvtColor(albedo, albedo, CV_GRAY2BGR); @@ -26,7 +27,7 @@ SpecularEstimation::SpecularEstimation(std::string imageName, std::string calibr } SpecularEstimation::SpecularEstimation(std::string imageName, std::string calibration, bool denseSample, double SpecularIntensity, double SpecularPower, double SpecularIntensitySynthetic, double SpecularPowerSynthetic) { - albedo = cv::imread(albedoPath); + albedo = cv::imread(albedoPath); heightMap = cv::Mat::zeros(albedo.size(), CV_8U); normalMap = convertImageToNormals(cv::imread(normalPath)); normalMap.convertTo(normalMap, CV_32FC3); @@ -141,7 +142,10 @@ int main(int argc, char** argv) { } }*/ - + if (argc < 2) { + std::cerr << "Enter the name of the object followed by the calibration set to use.\n"; + return -1; + } // Required for the Ceres solver google::InitGoogleLogging(argv[0]); @@ -159,12 +163,15 @@ int main(int argc, char** argv) { // Read the file name from the command line argument and convert it from a char array to a string const char *argument1 = argv[1]; imageName = argument1; - }/* - // Read the name of the calibration folder - if (argc >= 3) { // The specified calibration path will be used, otherwise "chrome" is used + } + /*if (argc >= 3) { // The specified calibration path will be used, otherwise "chrome" is used const char *argument2 = argv[2]; calibration = argument2; - } + }*/ + + /* + // Read the name of the calibration folder + // Read the image scale if (argc >= 4) { // An image scale is provided // Scale down the images for faster processing and rendering @@ -186,18 +193,20 @@ int main(int argc, char** argv) { //specularEstimation(imageName, calibration, imageScale, showTexture); - double SpecularIntensity, SpecularPower; - - const char *argument2 = argv[2], *argument3 = argv[3]; - std::stringstream SpecularIntensityValue, SpecularPowerValue; - SpecularIntensityValue << argument2; - SpecularPowerValue << argument3; - SpecularIntensityValue >> SpecularIntensity; - SpecularPowerValue >> SpecularPower; - + double SpecularIntensity = 0.5, SpecularPower = 2; bool denseSample = false; - if (argc >= 5) { + if (argc >= 4) { + const char *argument2 = argv[2], *argument3 = argv[3]; + std::stringstream SpecularIntensityValue, SpecularPowerValue; + SpecularIntensityValue << argument2; + SpecularPowerValue << argument3; + SpecularIntensityValue >> SpecularIntensity; + SpecularPowerValue >> SpecularPower; + + //specularEstimation(imageName, calibration, SpecularIntensity, SpecularPower); + SpecularEstimation Solver(imageName, calibration, denseSample, SpecularIntensity, SpecularPower); + } else if (argc >= 6) { double SpecularIntensitySynthetic, SpecularPowerSynthetic; const char *argument4 = argv[4], *argument5 = argv[5]; diff --git a/apps/specular_estimation/src/specular_estimation.h b/apps/specular_estimation/src/specular_estimation.h index bda1db80862908e0f87c630317a3346a9287b9c2..46a88b974573d3fb363e86c97bd802a70bb4e109 100644 --- a/apps/specular_estimation/src/specular_estimation.h +++ b/apps/specular_estimation/src/specular_estimation.h @@ -18,10 +18,10 @@ class SpecularEstimation { private: // OpenCV - const std::string imageName, calibration = "chrome", imagesPath = "/home/thomas/Documents/", folderPath = "2018-08-31", modelPath = imagesPath + folderPath + "/" + imageName + "/" + imageName + ".", calibrationPath = imagesPath + folderPath + "/" + calibration + "/" + calibration + ".", calibrationPath2 = imagesPath + "2017-12-04" + "/" + calibration + "/" + calibration + ".", macbethPath = imagesPath + folderPath + "/macbeth/macbeth.", albedoPath = modelPath + "albedo.png", normalPath = modelPath + "normal.png", texturePath = modelPath + "texture.png"; + std::string imageName, modelPath, calibrationPath, calibration = "chrome", imagesPath = "/home/thomas/Documents/", folderPath = "2018-08-31", macbethPath = imagesPath + folderPath + "/macbeth/macbeth.", albedoPath = modelPath + "albedo.png", normalPath = modelPath + "normal.png", texturePath = modelPath + "texture.png"; int width = 1092, height = 728, numberOfLights = 6, lightNumber = 0; double SpecularIntensity, SpecularPower, SpecularIntensitySynthetic, SpecularPowerSynthetic, totalResidual, residualValue, Gain = 1.0, Bias = 0.0; - bool calculateResidual = false, perspectiveProjection, shadowControl; + bool calculateResidual = false, perspectiveProjection = false, shadowControl = false, denseSample = false; std::vector<unsigned int> indices; // ChArUco board diff --git a/bin/specular_estimation b/bin/specular_estimation index 1c26f1af1c26ce644eea645c2ff2c807f2c6da31..e15815e35f95323fa740d985957126e8bfa7eba9 100755 Binary files a/bin/specular_estimation and b/bin/specular_estimation differ