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 225b08de91ea9c80d27684c24a9f8f2f84aa0862..94e3e42d05db5105d0bf70818665db1fa0af5506 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 83fa06c5d01d43e347783e2015730253a3a014f9..73708a97bb466b8c4ced3031c620868728dc74bf 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/OpenGL.h b/apps/specular_estimation/src/OpenGL.h index 6a9fb74400c45fceb64c7477d12da5b16adc0fc6..8b9f8f5686bbc5a6f4e91b399fd4f48f49608115 100644 --- a/apps/specular_estimation/src/OpenGL.h +++ b/apps/specular_estimation/src/OpenGL.h @@ -510,6 +510,8 @@ void computeResidual(int imageNumber, int windowHeight, int windowWidth, std::st // Square each element multiply(residual, residual, sumOfSquaredDifferences); + + cv::cvtColor(residual, residual, CV_BGR2GRAY); std::ostringstream stm; stm << imageNumber; @@ -711,7 +713,7 @@ void viewModel(cv::Vec3d& residual, std::vector< cv::Vec3d >& residuals, double& if (calculateResidual) { computeResidual(lightNumber, height, width, modelPath, textureImages, residualImage, residual, totalResidual, SpecularIntensity, SpecularPower); //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, modelPath); - std::cout << "Average residual = " << totalResidual << ", specular intensity = " << SpecularIntensity << ", specular power = " << SpecularPower << std::endl; + std::cout << "Light number : " << lightNumber << ", per-pixel residual = " << totalResidual << ", specular intensity = " << SpecularIntensity << ", specular power = " << SpecularPower << std::endl; } diff --git a/apps/specular_estimation/src/PhotometricStereo.cc b/apps/specular_estimation/src/PhotometricStereo.cc index 5d3c8eb052e8b632784cb71f7666ae421602643d..4d4f53c1f171a75a07436ce0b8863ee1eb09ddc2 100755 --- a/apps/specular_estimation/src/PhotometricStereo.cc +++ b/apps/specular_estimation/src/PhotometricStereo.cc @@ -378,7 +378,7 @@ void photometryStero::getLightInformation(const int metalIndex, const int lambIn } } -void photometryStero::getLightInformation(const int metalIndex, cv::Rect boundingBox, std::vector<double> macbethIntensity) { +void photometryStero::getLightInformation(const int metalIndex) { /* // get the metal circle cv::threshold(mp2Mask[metalIndex], mp2Mask[metalIndex], 255 / 2, 255, cv::THRESH_BINARY); @@ -394,7 +394,7 @@ void photometryStero::getLightInformation(const int metalIndex, cv::Rect boundin } } m_metalSphere = getCircle(metalContour[mostPointIdx]);*/ - m_metalSphere = phoSte::circle(boundingBox.x + (boundingBox.width/2), boundingBox.y + (boundingBox.height/2), (boundingBox.width/2)); + //m_metalSphere = phoSte::circle(boundingBox.x + (boundingBox.width/2), boundingBox.y + (boundingBox.height/2), (boundingBox.width/2)); m_light.push_back(phoSte::light(0.447712, 0.138562, 0.883377)); m_light.push_back(phoSte::light(0.228758, -0.106536, 0.967636)); @@ -478,7 +478,7 @@ void photometryStero::getPixelNormAndAlbedo(const int objectIndex, cv::Mat light } } - //std::cout << "Store all pixel values in a vector\n"; + //std::cout << "Stored all pixel values in a vector\n"; // threshold for every image; std::vector<double> allThreshold; @@ -549,30 +549,26 @@ void photometryStero::getPixelNormAndAlbedo(const int objectIndex, cv::Mat light break; } } - //std::cout << "3\n"; if(inValidNum == 0) { - //std::cout << "4.0 inValidNum == 0\n"; - mN.col(i) = LPseudoInvert * I.col(i); //std::cout << "4.1\n"; - double nx = mN.col(i).at<double>(0, 0); //std::cout << "4.2\n"; - double ny = mN.col(i).at<double>(1, 0); //std::cout << "4.3\n"; - double nz = mN.col(i).at<double>(2, 0); //std::cout << "4.4\n"; - mAlbedo.at<double>(0, i) = sqrt(nx * nx + ny * ny + nz * nz); //std::cout << "4.5\n"; + mN.col(i) = LPseudoInvert * I.col(i); + double nx = mN.col(i).at<double>(0, 0); + double ny = mN.col(i).at<double>(1, 0); + double nz = mN.col(i).at<double>(2, 0); + mAlbedo.at<double>(0, i) = sqrt(nx * nx + ny * ny + nz * nz); } else if(imageNum - inValidNum >= 3) { - //std::cout << "5.0 imageNum - inValidNum >= 3\n"; - cv::Mat specificLPseudoInvert; //std::cout << "5.1\n"; - cv::invert(specificL, specificLPseudoInvert, cv::DECOMP_SVD); //std::cout << "5.2\n"; - mN.col(i) = specificLPseudoInvert * I.col(i); //std::cout << "5.2\n"; - double nx = mN.col(i).at<double>(0, 0); //std::cout << "5.3\n"; - double ny = mN.col(i).at<double>(1, 0); //std::cout << "5.4\n"; - double nz = mN.col(i).at<double>(2, 0); //std::cout << "5.5\n"; - mAlbedo.at<double>(0, i) = sqrt(nx * nx + ny * ny + nz * nz); //std::cout << "5.6\n"; + cv::Mat specificLPseudoInvert; + cv::invert(specificL, specificLPseudoInvert, cv::DECOMP_SVD); + mN.col(i) = specificLPseudoInvert * I.col(i); + double nx = mN.col(i).at<double>(0, 0); + double ny = mN.col(i).at<double>(1, 0); + double nz = mN.col(i).at<double>(2, 0); + mAlbedo.at<double>(0, i) = sqrt(nx * nx + ny * ny + nz * nz); } else { - //std::cout << "6.0 else\n"; - mN.at<double>(0, i) = 0; //std::cout << "6.1\n"; - mN.at<double>(1, i) = 0; //std::cout << "6.2\n"; - mN.at<double>(2, i) = 0; //std::cout << "6.3\n"; - mAlbedo.at<double>(0, i) = 0; //std::cout << "6.4\n"; - mInvalidIndex.push_back(i); //std::cout << "6.5\n"; + mN.at<double>(0, i) = 0; + mN.at<double>(1, i) = 0; + mN.at<double>(2, i) = 0; + mAlbedo.at<double>(0, i) = 0; + mInvalidIndex.push_back(i); } } } diff --git a/apps/specular_estimation/src/PhotometricStereo.h b/apps/specular_estimation/src/PhotometricStereo.h index 65158231a54a99b053a26cc6255ec0973fc79bd7..11558d19377a6a7cd7392d87a7df0c25c37cb300 100755 --- a/apps/specular_estimation/src/PhotometricStereo.h +++ b/apps/specular_estimation/src/PhotometricStereo.h @@ -53,7 +53,7 @@ class photometryStero { bool readImage(); // read the images and masks according to the ImageNames bool readImage(std::string modelPath, std::string calibrationPath, std::string macbethPath); void getLightInformation(const int metalIndex, const int lambIndex); - void getLightInformation(const int metalIndex, cv::Rect boundingBox, std::vector<double> macbethIntensity); + void getLightInformation(const int metalIndex); void getPixelNormAndAlbedo(const int objectIndex); void getPixelNormAndAlbedo(const int objectIndex, cv::Mat lightDirections); cv::Mat outputNormalImage(int objectIndex); diff --git a/apps/specular_estimation/src/specular_estimation.cc b/apps/specular_estimation/src/specular_estimation.cc index 9497f3af9dde90517d281868151bba3ebfc894db..f846f225e493b40448f537f584832d7654fc17c5 100644 --- a/apps/specular_estimation/src/specular_estimation.cc +++ b/apps/specular_estimation/src/specular_estimation.cc @@ -55,6 +55,7 @@ int main(int argc, char** argv) { const std::string macbethPath = imagesPath + folderPath + "/macbeth/macbeth."; const std::string texturePath = modelPath + "texture.png"; + /* std::vector<double> macbethIntensity; for (int i = 0; i < 6; i++) { @@ -107,31 +108,43 @@ int main(int argc, char** argv) { photometricStereo(imageName, calibration, modelPath, imageScale, heightMap, normalMap, texture, lightDirections, lightDirectionsPerspective, textureImages, modelImages, calibrationImages, calibrationBoundingBox, width, height, rvecs, tvecs); - + */ //phoSte::photometryStero B(21, 2, 22, "/home/thomas/Documents/Photometric-Stereo/Assignment_1/Apple/", "mask_dir_1.png", "mask_dir_2.png", "mask_I.png", "applemask.png"); //B.readImage(); const std::string calibrationPath2 = imagesPath + folderPath + "/" + calibration + "/" + calibration + "."; + int numberOfLights = 6, width = 1092, height = 728; + + std::vector<cv::Mat> textureImages; + for (int i = 0; i < numberOfLights; i++) { + std::ostringstream stm; + stm << i; + std::string indexString = stm.str(); + + cv::Mat model = cv::imread(modelPath + indexString + ".png"); + textureImages.push_back(model); + } phoSte::photometryStero A(numberOfLights, modelPath, calibrationPath2, macbethPath, imageName, calibration, 0); A.readImage(modelPath, calibrationPath2, macbethPath); - cv::Mat calibrationMask = loadCalibrationMask(calibrationPath2, height, width); - calibrationBoundingBox = getBoundingBox(calibrationMask); - A.getLightInformation(0, calibrationBoundingBox, macbethIntensity); + //cv::Mat calibrationMask = loadCalibrationMask(calibrationPath2, height, width); + //calibrationBoundingBox = getBoundingBox(calibrationMask); + A.getLightInformation(0); std::cout << "Got light information\n"; A.getPixelNormAndAlbedo(1); std::cout << "Got Normal and Albedo\n"; - normalMap = A.outputNormalImage(1); + cv::Mat normalMap = A.outputNormalImage(1); cv::imshow("Normal Map", normalMap); - texture = A.outputAlbedoImage(1); + cv::Mat texture = A.outputAlbedoImage(1); cv::imshow("Albedo", texture); cv::Mat normalAlbedo = A.outputNormalWithAlbedo(1); cv::imshow("Normal with Albedo", normalAlbedo); - //heightMap = A.getHeightMap(2, -0.1); + //cv::Mat heightMap = A.getHeightMap(2, -0.1); //cv::imshow("Height Map", heightMap); //cv::imwrite(modelPath + "normal", result); + cv::Mat heightMap = cv::Mat::zeros(texture.size(), CV_8U); cv::waitKey(0); //normalMap.convertTo(normalMap, CV_8UC1); @@ -201,9 +214,9 @@ int main(int argc, char** argv) { double totalResidual, residualValue, SpecularIntensity = 0.5, SpecularPower = 2.0; cv::Mat residualImage; - cv::Mat lightDirectionsInverted; - //lightDirections = (cv::Mat_<double>(6,3) << 0.447712, 0.883377, 0.138562, 0.228758, 0.967636, -0.106536, 0.1, 0.99248, 0.0705882, 0.000653595, 0.997412, -0.0718954, -0.139216, 0.982279, -0.12549, -0.494771, 0.861376, 0.115033); - cv::invert(lightDirections, lightDirectionsInverted, cv::DECOMP_SVD); + //cv::Mat lightDirectionsInverted; + cv::Mat lightDirections = (cv::Mat_<float>(6,3) << 0.447712, 0.138562, 0.883377, 0.228758, -0.106536, 0.967636, 0.1, 0.0705882, 0.99248, 0.000653595, -0.0718954, 0.997412, -0.139216, -0.12549, 0.982279, -0.494771, 0.115033, 0.861376); + //cv::invert(lightDirections, lightDirectionsInverted, cv::DECOMP_SVD); /* std::vector<glm::vec3> lightInvDirs; diff --git a/bin/specular_estimation b/bin/specular_estimation index ee2df2d4eb34c1c2f4ec9ca556084b32da22576e..411199f6cc00d89ac570e2beefe30927d76eb0cf 100755 Binary files a/bin/specular_estimation and b/bin/specular_estimation differ