Skip to content

Commit

Permalink
interface: make depth import optional in polycam
Browse files Browse the repository at this point in the history
  • Loading branch information
cdcseacave committed Dec 2, 2023
1 parent bc67cf9 commit 186eb29
Showing 1 changed file with 32 additions and 29 deletions.
61 changes: 32 additions & 29 deletions apps/InterfacePolycam/InterfacePolycam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,52 +237,55 @@ bool ParseImage(Scene& scene, const String& imagePath, const String& cameraPath,
}
}
// load and convert depth-map
DepthMap depthMap; {
constexpr double depthScale{1000.0};
const cv::Mat imgDepthMap = cv::imread(depthPath, cv::IMREAD_ANYDEPTH);
if (imgDepthMap.empty())
if (!depthPath.empty()) {
DepthMap depthMap; {
constexpr double depthScale{1000.0};
const cv::Mat imgDepthMap = cv::imread(depthPath, cv::IMREAD_ANYDEPTH);
if (imgDepthMap.empty())
return false;
imgDepthMap.convertTo(depthMap, CV_32FC1, 1.0/depthScale);
}
IIndexArr IDs = {imageData.ID};
IDs.JoinFunctor(imageData.neighbors.size(), [&imageData](IIndex i) {
return imageData.neighbors[i].ID;
});
double dMin, dMax;
cv::minMaxIdx(depthMap, &dMin, &dMax, NULL, NULL, depthMap > 0);
const NormalMap normalMap;
const ConfidenceMap confMap;
const ViewsMap viewsMap;
if (!ExportDepthDataRaw(MAKE_PATH(String::FormatString("depth%04u.dmap", imageData.ID)),
imageData.name, IDs, resolution,
camera.K, pose.R, pose.C,
(float)dMin, (float)dMax,
depthMap, normalMap, confMap, viewsMap))
return false;
imgDepthMap.convertTo(depthMap, CV_32FC1, 1.0/depthScale);
}
IIndexArr IDs = {imageData.ID};
IDs.JoinFunctor(imageData.neighbors.size(), [&imageData](IIndex i) {
return imageData.neighbors[i].ID;
});
double dMin, dMax;
cv::minMaxIdx(depthMap, &dMin, &dMax, NULL, NULL, depthMap > 0);
const NormalMap normalMap;
const ConfidenceMap confMap;
const ViewsMap viewsMap;
if (!ExportDepthDataRaw(MAKE_PATH(String::FormatString("depth%04u.dmap", imageData.ID)),
imageData.name, IDs, resolution,
camera.K, pose.R, pose.C,
(float)dMin, (float)dMax,
depthMap, normalMap, confMap, viewsMap))
return false;
return true;
}

// parse scene stored in Polycam format
bool ParseScene(Scene& scene, const String& scenePath)
{
#if defined(_SUPPORT_CPP17) && (!defined(__GNUC__) || (__GNUC__ > 7))
size_t numCorrectedFolders(0), numFolders(0);
size_t numCorrectedFolders(0), numCorrectedDepthFolders(0), numFolders(0), numDepthFolders(0);
for (const auto& file: std::filesystem::directory_iterator(scenePath.c_str())) {
if (file.path().stem() == "corrected_cameras" ||
file.path().stem() == "corrected_depth" ||
file.path().stem() == "corrected_images")
++numCorrectedFolders;
else
if (file.path().stem() == "cameras" ||
file.path().stem() == "depth" ||
else if (file.path().stem() == "corrected_depth")
++numCorrectedDepthFolders;
else if (file.path().stem() == "cameras" ||
file.path().stem() == "images")
++numFolders;
else if (file.path().stem() == "depth")
++numDepthFolders;
}
if (numFolders != 3) {
if (numFolders != 2) {
VERBOSE("Invalid scene folder");
return false;
}
if (numCorrectedFolders == 3) {
if (numCorrectedFolders == 2) {
// corrected data
CLISTDEFIDX(String, IIndex) imagePaths;
for (const auto& file: std::filesystem::directory_iterator((scenePath + "corrected_images").c_str()))
Expand All @@ -297,7 +300,7 @@ bool ParseScene(Scene& scene, const String& scenePath)
for (const String& imagePath: imagePaths) {
const String imageName = Util::getFileName(imagePath);
const String cameraPath(scenePath + "corrected_cameras" + PATH_SEPARATOR_STR + imageName + JSON_EXT);
const String depthPath(scenePath + "corrected_depth" + PATH_SEPARATOR_STR + imageName + DEPTH_EXT);
const String depthPath(numCorrectedDepthFolders ? scenePath + "corrected_depth" + PATH_SEPARATOR_STR + imageName + DEPTH_EXT : String());
if (!ParseImage(scene, imagePath, cameraPath, depthPath, mapImageName))
return false;
}
Expand All @@ -316,7 +319,7 @@ bool ParseScene(Scene& scene, const String& scenePath)
for (const String& imagePath: imagePaths) {
const String imageName = Util::getFileName(imagePath);
const String cameraPath(scenePath + "cameras" + PATH_SEPARATOR_STR + imageName + JSON_EXT);
const String depthPath(scenePath + "depth" + PATH_SEPARATOR_STR + imageName + DEPTH_EXT);
const String depthPath(numDepthFolders ? scenePath + "depth" + PATH_SEPARATOR_STR + imageName + DEPTH_EXT : String());
if (!ParseImage(scene, imagePath, cameraPath, depthPath, mapImageName))
return false;
}
Expand Down

0 comments on commit 186eb29

Please sign in to comment.