|
|
|
|
@ -37,12 +37,13 @@
@@ -37,12 +37,13 @@
|
|
|
|
|
#include <boost/graph/connected_components.hpp> |
|
|
|
|
#include <opencv2/ximgproc.hpp> |
|
|
|
|
|
|
|
|
|
#include <pybind11/embed.h> |
|
|
|
|
#include <pybind11/stl.h> |
|
|
|
|
// #include <pybind11/embed.h>
|
|
|
|
|
// #include <pybind11/stl.h>
|
|
|
|
|
#include "ConfigEnv.h" |
|
|
|
|
#include "cuda/MeshTextureCUDA.h" |
|
|
|
|
#include <sstream> |
|
|
|
|
|
|
|
|
|
namespace py = pybind11; |
|
|
|
|
// namespace py = pybind11;
|
|
|
|
|
|
|
|
|
|
using namespace MVS; |
|
|
|
|
|
|
|
|
|
@ -72,8 +73,6 @@ using namespace MVS;
@@ -72,8 +73,6 @@ using namespace MVS;
|
|
|
|
|
#define TEXOPT_INFERENCE_TRWS 2 |
|
|
|
|
#define TEXOPT_INFERENCE TEXOPT_INFERENCE_LBP |
|
|
|
|
#define MASK_FACE_OCCLUSION |
|
|
|
|
// #define DISPLAY_DEMO
|
|
|
|
|
#define CACHE_MASK |
|
|
|
|
#define USE_CUDA |
|
|
|
|
|
|
|
|
|
// inference algorithm
|
|
|
|
|
@ -9590,40 +9589,6 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi
@@ -9590,40 +9589,6 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi
|
|
|
|
|
printf("id=%s\n", id.c_str()); |
|
|
|
|
|
|
|
|
|
#ifdef MASK_FACE_OCCLUSION |
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
// 创建遮挡数据
|
|
|
|
|
std::cout << "inputFileName: " << inputFileName << std::endl; |
|
|
|
|
std::cout << "meshFileName: " << meshFileName << std::endl; |
|
|
|
|
try { |
|
|
|
|
py::scoped_interpreter guard{}; // 自动管理解释器生命周期
|
|
|
|
|
py::module_ sys = py::module_::import("sys"); |
|
|
|
|
// 设置命令行参数(模拟Python的argparse)
|
|
|
|
|
py::list argv; |
|
|
|
|
argv.append("program_name"); |
|
|
|
|
argv.append("--sparse_dir"); |
|
|
|
|
argv.append(static_cast<std::string>(inputFileName)); |
|
|
|
|
argv.append("--mesh_path"); |
|
|
|
|
argv.append(static_cast<std::string>(meshFileName)); |
|
|
|
|
// argv.append("--mask_image");
|
|
|
|
|
// argv.append("63_2");
|
|
|
|
|
sys.attr("argv") = argv; |
|
|
|
|
|
|
|
|
|
py::print(sys.attr("version")); // 打印Python版本
|
|
|
|
|
sys.attr("path").attr("append")("/root/miniconda3/lib/python3.10/site-packages"); |
|
|
|
|
sys.attr("path").attr("append")("/root/code/openMVS/libs/MVS"); |
|
|
|
|
// 调用自定义函数
|
|
|
|
|
py::module_ mymodule = py::module_::import("mask_face_occlusion"); |
|
|
|
|
|
|
|
|
|
// 获取ModelProcessor类
|
|
|
|
|
py::object ModelProcessor = mymodule.attr("ModelProcessor"); |
|
|
|
|
|
|
|
|
|
py::object processor = ModelProcessor(); |
|
|
|
|
py::dict result = processor.attr("process")().cast<py::dict>(); |
|
|
|
|
|
|
|
|
|
printf("result size=%d\n", result.size()); |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
std::string basePath = ""; |
|
|
|
|
size_t lastSlash = baseFileName.find_last_of('/'); |
|
|
|
|
size_t secondLastSlash = baseFileName.find_last_of('/', lastSlash - 1); |
|
|
|
|
@ -9633,118 +9598,10 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi
@@ -9633,118 +9598,10 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi
|
|
|
|
|
|
|
|
|
|
// printf("basePath=%s\n", basePath.c_str());
|
|
|
|
|
|
|
|
|
|
#ifdef CACHE_MASK |
|
|
|
|
if (!LoadVisibleFacesData(visible_faces_map, face_visible_relative, edge_faces_map, delete_edge_faces_map, basePath)) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
{ |
|
|
|
|
// 创建遮挡数据
|
|
|
|
|
try { |
|
|
|
|
py::scoped_interpreter guard{}; // 自动管理解释器生命周期
|
|
|
|
|
py::module_ sys = py::module_::import("sys"); |
|
|
|
|
|
|
|
|
|
// 设置命令行参数(模拟Python的argparse)
|
|
|
|
|
py::list argv; |
|
|
|
|
argv.append("program_name"); |
|
|
|
|
argv.append("--id"); |
|
|
|
|
// argv.append("274658"); // 274658 7613212046
|
|
|
|
|
argv.append(id); |
|
|
|
|
argv.append("--base_path"); |
|
|
|
|
argv.append(basePath.c_str()); |
|
|
|
|
argv.append("--mesh_path"); |
|
|
|
|
argv.append(meshFileName.c_str()); |
|
|
|
|
argv.append("--sparse_dir"); |
|
|
|
|
argv.append(inputFileName.c_str()); |
|
|
|
|
sys.attr("argv") = argv; |
|
|
|
|
|
|
|
|
|
py::print(sys.attr("version")); // 打印Python版本
|
|
|
|
|
|
|
|
|
|
printf("PYTHON_PATH=%s\n", PYTHON_PATH.c_str()); |
|
|
|
|
printf("MVS_PATH=%s\n", MVS_PATH.c_str()); |
|
|
|
|
// sys.attr("path").attr("append")("/home/algo/.conda/envs/py310_pyt210/lib/python3.10/site-packages");
|
|
|
|
|
// sys.attr("path").attr("append")("/home/algo/Documents/openMVS/openMVS/libs/MVS");
|
|
|
|
|
sys.attr("path").attr("append")(PYTHON_PATH.c_str()); |
|
|
|
|
sys.attr("path").attr("append")(MVS_PATH.c_str()); |
|
|
|
|
// 调用自定义函数
|
|
|
|
|
py::module_ mymodule = py::module_::import("mask_face_occlusion"); |
|
|
|
|
|
|
|
|
|
// 获取ModelProcessor类
|
|
|
|
|
py::object ModelProcessor = mymodule.attr("ModelProcessor"); |
|
|
|
|
|
|
|
|
|
py::object processor = ModelProcessor(); |
|
|
|
|
py::dict result = processor.attr("process")().cast<py::dict>(); |
|
|
|
|
|
|
|
|
|
py::dict dict1; |
|
|
|
|
py::dict dict2; |
|
|
|
|
if (result.contains("result1") && result.contains("result2")) { |
|
|
|
|
dict1 = result["result1"].cast<py::dict>(); |
|
|
|
|
dict2 = result["result2"].cast<py::dict>(); |
|
|
|
|
} |
|
|
|
|
py::dict dict3; |
|
|
|
|
if (result.contains("result3")) { |
|
|
|
|
dict3 = result["result3"].cast<py::dict>(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// printf("dict1 size=%d, dict2 size=%d, dict3 size=%d\n", dict1.size(), dict2.size(), dict3.size());
|
|
|
|
|
|
|
|
|
|
// 处理返回的可见面字典
|
|
|
|
|
for (auto item : dict1) { |
|
|
|
|
std::string image_name = item.first.cast<std::string>(); |
|
|
|
|
// printf("dict1 mask image name=%s\n", image_name.c_str());
|
|
|
|
|
py::list visible_faces = item.second.cast<py::list>(); |
|
|
|
|
|
|
|
|
|
std::unordered_set<int> face_set; |
|
|
|
|
for (auto face : visible_faces) { |
|
|
|
|
face_set.insert(face.cast<int>()); |
|
|
|
|
} |
|
|
|
|
visible_faces_map[image_name] = face_set; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (const auto& entry : visible_faces_map) |
|
|
|
|
{ |
|
|
|
|
face_visible_relative.insert(entry.second.begin(), entry.second.end()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (auto item : dict2) { |
|
|
|
|
std::string image_name = item.first.cast<std::string>(); |
|
|
|
|
// printf("dict2 mask image name=%s\n", image_name.c_str());
|
|
|
|
|
py::list edge_faces = item.second.cast<py::list>(); |
|
|
|
|
|
|
|
|
|
std::unordered_set<int> face_set; |
|
|
|
|
for (auto face : edge_faces) { |
|
|
|
|
face_set.insert(face.cast<int>()); |
|
|
|
|
} |
|
|
|
|
edge_faces_map[image_name] = face_set; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
for (auto item : dict3) { |
|
|
|
|
std::string image_name = item.first.cast<std::string>(); |
|
|
|
|
// printf("dict3 mask image name=%s\n", image_name.c_str());
|
|
|
|
|
py::list delete_edge_faces = item.second.cast<py::list>(); |
|
|
|
|
|
|
|
|
|
std::unordered_set<int> face_set; |
|
|
|
|
for (auto face : delete_edge_faces) { |
|
|
|
|
face_set.insert(face.cast<int>()); |
|
|
|
|
} |
|
|
|
|
delete_edge_faces_map[image_name] = face_set; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#ifdef CACHE_MASK |
|
|
|
|
SaveVisibleFacesData(visible_faces_map, face_visible_relative, edge_faces_map, delete_edge_faces_map, basePath); |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
catch (const py::error_already_set &e) { |
|
|
|
|
std::cerr << "Python error: " << e.what() << std::endl; |
|
|
|
|
// 获取详细的Python错误信息
|
|
|
|
|
PyErr_Print(); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
catch (const std::exception &e) { |
|
|
|
|
std::cerr << "C++ error: " << e.what() << std::endl; |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
printf("LoadVisibleFacesData error\n"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// assign the best view to each face
|
|
|
|
|
@ -9811,52 +9668,23 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi
@@ -9811,52 +9668,23 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi
|
|
|
|
|
TD_TIMER_STARTD(); |
|
|
|
|
texture.GenerateTexture(bGlobalSeamLeveling, bLocalSeamLeveling, nTextureSizeMultiple, nRectPackingHeuristic, colEmpty, fSharpnessWeight, maxTextureSize, baseFileName, bOriginFaceview); |
|
|
|
|
DEBUG_EXTRA("Generating texture atlas and image completed: %u patches, %u image size, %u textures (%s)", texture.texturePatches.size(), mesh.texturesDiffuse[0].width(), mesh.texturesDiffuse.size(), TD_TIMER_GET_FMT().c_str()); |
|
|
|
|
} |
|
|
|
|
#ifdef DISPLAY_DEMO |
|
|
|
|
try { |
|
|
|
|
py::scoped_interpreter guard{}; // 自动管理解释器生命周期
|
|
|
|
|
py::module_ sys = py::module_::import("sys"); |
|
|
|
|
|
|
|
|
|
// 设置命令行参数(模拟Python的argparse)
|
|
|
|
|
py::list argv; |
|
|
|
|
argv.append("program_name"); |
|
|
|
|
argv.append("--id"); |
|
|
|
|
argv.append(id); |
|
|
|
|
argv.append("--mask"); |
|
|
|
|
#ifdef MASK_FACE_OCCLUSION |
|
|
|
|
argv.append(1); |
|
|
|
|
#else |
|
|
|
|
argv.append(0); |
|
|
|
|
#endif |
|
|
|
|
sys.attr("argv") = argv; |
|
|
|
|
|
|
|
|
|
py::print(sys.attr("version")); // 打印Python版本
|
|
|
|
|
sys.attr("path").attr("append")("/home/algo/.conda/envs/py310_pyt210/lib/python3.10/site-packages"); |
|
|
|
|
sys.attr("path").attr("append")("/home/algo/Documents/openMVS/openMVS/libs/MVS"); |
|
|
|
|
// 调用自定义函数
|
|
|
|
|
py::module_ mymodule = py::module_::import("display_demo"); |
|
|
|
|
|
|
|
|
|
// 获取ModelProcessor类
|
|
|
|
|
py::object DisplayProcessor = mymodule.attr("DisplayProcessor"); |
|
|
|
|
|
|
|
|
|
py::object processor = DisplayProcessor(); |
|
|
|
|
processor.attr("load_and_show")(); |
|
|
|
|
} |
|
|
|
|
catch (const py::error_already_set &e) { |
|
|
|
|
std::cerr << "Python error: " << e.what() << std::endl; |
|
|
|
|
// 获取详细的Python错误信息
|
|
|
|
|
PyErr_Print(); |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
catch (const std::exception &e) { |
|
|
|
|
std::cerr << "C++ error: " << e.what() << std::endl; |
|
|
|
|
return 1; |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
|
} // TextureMesh
|
|
|
|
|
|
|
|
|
|
std::string Scene::runPython(const std::string& command) { |
|
|
|
|
std::array<char, 128> buffer{}; |
|
|
|
|
std::string result; |
|
|
|
|
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(command.c_str(), "r"), pclose); |
|
|
|
|
if (!pipe) throw std::runtime_error("popen() failed!"); |
|
|
|
|
|
|
|
|
|
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) { |
|
|
|
|
result += buffer.data(); |
|
|
|
|
} |
|
|
|
|
return result; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool Scene::is_face_visible(const std::string& image_name, int face_index) { |
|
|
|
|
|
|
|
|
|
#ifndef MASK_FACE_OCCLUSION |
|
|
|
|
|