diff --git a/CMakeLists.txt b/CMakeLists.txt index 920e4c3..8f11638 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,14 @@ ENDIF() # ${OpenMVS_BINARY_DIR}. PROJECT(OpenMVS) +SET(ENV_PYTHON_PATH "/home/algo/.conda/envs/py310_pyt210/lib/python3.10/site-packages") +SET(ENV_MVS_PATH "/home/algo/Documents/openMVS/openMVS/libs/MVS") + +CONFIGURE_FILE( + "${CMAKE_CURRENT_SOURCE_DIR}/build/Templates/ConfigEnv.h.in" + "${CMAKE_BINARY_DIR}/ConfigEnv.h" +) + SET(OpenMVS_MAJOR_VERSION 2) SET(OpenMVS_MINOR_VERSION 3) SET(OpenMVS_PATCH_VERSION 0) diff --git a/apps/TextureMesh/TextureMesh.cpp b/apps/TextureMesh/TextureMesh.cpp index 9764849..aeeee2c 100644 --- a/apps/TextureMesh/TextureMesh.cpp +++ b/apps/TextureMesh/TextureMesh.cpp @@ -1133,7 +1133,8 @@ int main(int argc, LPCTSTR* argv) TD_TIMER_START(); if (!scene.TextureMesh(OPT::nResolutionLevel, OPT::nMinResolution, OPT::minCommonCameras, OPT::fOutlierThreshold, OPT::fRatioDataSmoothness, OPT::bGlobalSeamLeveling, OPT::bLocalSeamLeveling, OPT::nTextureSizeMultiple, OPT::nRectPackingHeuristic, Pixel8U(OPT::nColEmpty), - OPT::fSharpnessWeight, OPT::nIgnoreMaskLabel, OPT::nMaxTextureSize, views, baseFileName, OPT::bOriginFaceview)) + OPT::fSharpnessWeight, OPT::nIgnoreMaskLabel, OPT::nMaxTextureSize, views, baseFileName, OPT::bOriginFaceview, + OPT::strInputFileName, OPT::strMeshFileName)) return EXIT_FAILURE; VERBOSE("Mesh texturing completed: %u vertices, %u faces (%s)", scene.mesh.vertices.GetSize(), scene.mesh.faces.GetSize(), TD_TIMER_GET_FMT().c_str()); diff --git a/build/Templates/ConfigEnv.h.in b/build/Templates/ConfigEnv.h.in new file mode 100644 index 0000000..ff757be --- /dev/null +++ b/build/Templates/ConfigEnv.h.in @@ -0,0 +1,7 @@ +#pragma once + +#include + +// 从环境变量获取的路径 +const std::string PYTHON_PATH = "@ENV_PYTHON_PATH@"; +const std::string MVS_PATH = "@ENV_MVS_PATH@"; \ No newline at end of file diff --git a/build/Templates/ConfigLocal.h.in b/build/Templates/ConfigLocal.h.in index 39ac292..5d7b2b5 100644 --- a/build/Templates/ConfigLocal.h.in +++ b/build/Templates/ConfigLocal.h.in @@ -1,3 +1,5 @@ +#include + // OpenMVS version #define OpenMVS_MAJOR_VERSION ${OpenMVS_MAJOR_VERSION} #define OpenMVS_MINOR_VERSION ${OpenMVS_MINOR_VERSION} @@ -64,3 +66,4 @@ // SSE support #cmakedefine _USE_SSE + diff --git a/libs/MVS/Scene.h b/libs/MVS/Scene.h index f66a1fe..d669eb4 100644 --- a/libs/MVS/Scene.h +++ b/libs/MVS/Scene.h @@ -168,7 +168,8 @@ public: // Mesh texturing bool TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsigned minCommonCameras=0, float fOutlierThreshold=0.f, float fRatioDataSmoothness=0.3f, bool bGlobalSeamLeveling=true, bool bLocalSeamLeveling=true, unsigned nTextureSizeMultiple=0, unsigned nRectPackingHeuristic=3, Pixel8U colEmpty=Pixel8U(255,127,39), - float fSharpnessWeight=0.5f, int ignoreMaskLabel=-1, int maxTextureSize=0, const IIndexArr& views=IIndexArr(), const SEACAVE::String& basename = "", bool bOriginFaceview = false); + float fSharpnessWeight=0.5f, int ignoreMaskLabel=-1, int maxTextureSize=0, const IIndexArr& views=IIndexArr(), const SEACAVE::String& basename = "", bool bOriginFaceview = false, + const std::string& inputFileName = "", const std::string& meshFileName = ""); bool is_face_visible(const std::string& image_name, int face_index); bool is_face_visible_relative(int face_index); diff --git a/libs/MVS/SceneTexture.cpp b/libs/MVS/SceneTexture.cpp index 2953b52..195531f 100644 --- a/libs/MVS/SceneTexture.cpp +++ b/libs/MVS/SceneTexture.cpp @@ -39,6 +39,8 @@ #include #include +#include "ConfigEnv.h" + namespace py = pybind11; using namespace MVS; @@ -8598,7 +8600,8 @@ bool Scene::LoadVisibleFacesData(std::map>& // - nIgnoreMaskLabel: label value to ignore in the image mask, stored in the MVS scene or next to each image with '.mask.png' extension (-1 - auto estimate mask for lens distortion, -2 - disabled) bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsigned minCommonCameras, float fOutlierThreshold, float fRatioDataSmoothness, bool bGlobalSeamLeveling, bool bLocalSeamLeveling, unsigned nTextureSizeMultiple, unsigned nRectPackingHeuristic, Pixel8U colEmpty, float fSharpnessWeight, - int nIgnoreMaskLabel, int maxTextureSize, const IIndexArr& views, const SEACAVE::String& baseFileName, bool bOriginFaceview) + int nIgnoreMaskLabel, int maxTextureSize, const IIndexArr& views, const SEACAVE::String& baseFileName, bool bOriginFaceview, + const std::string& inputFileName, const std::string& meshFileName) { if (!bOriginFaceview) { @@ -8624,7 +8627,7 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi MeshTexture texture(*this, nResolutionLevel, nMinResolution); - printf("baseFileName=%s\n", baseFileName.c_str()); + // printf("baseFileName=%s\n", baseFileName.c_str()); /* std::filesystem::path path(baseFileName.c_str()); @@ -8668,6 +8671,39 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi #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(inputFileName)); + argv.append("--mesh_path"); + argv.append(static_cast(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(); + + 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); @@ -8693,13 +8729,22 @@ bool Scene::TextureMesh(unsigned nResolutionLevel, unsigned nMinResolution, unsi argv.append("--id"); // argv.append("274658"); // 274658 7613212046 argv.append(id); - // argv.append("--mask_image"); - // argv.append("63_2"); + 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版本 - 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"); + + 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"); diff --git a/libs/MVS/__pycache__/mask_face_occlusion.cpython-310.pyc b/libs/MVS/__pycache__/mask_face_occlusion.cpython-310.pyc index 7e82d04..608882b 100644 Binary files a/libs/MVS/__pycache__/mask_face_occlusion.cpython-310.pyc and b/libs/MVS/__pycache__/mask_face_occlusion.cpython-310.pyc differ diff --git a/libs/MVS/mask_face_occlusion.py b/libs/MVS/mask_face_occlusion.py index a2bc440..c2aa3f0 100755 --- a/libs/MVS/mask_face_occlusion.py +++ b/libs/MVS/mask_face_occlusion.py @@ -21,27 +21,45 @@ class ModelProcessor: required=True, ) - # parser.add_argument( - # "--mask_image", - # type=str, - # default="74_8" # 74_8 123_8 75_8 72_8 44_8 104_8 96_8 - # ) + #""" + parser.add_argument( + "--base_path", + type=str, + required=True, + ) + parser.add_argument( + "--mesh_path", + type=str, + required=True, + ) + + parser.add_argument( + "--sparse_dir", + type=str, + required=True, + ) + #""" + + # print("ModelProcessor Init", args.input_file, self.pose_path) args = parser.parse_args() self.id = args.id - # self.mask_image = args.mask_image - self.mesh = None - self.asset_dir = f"/home/algo/Documents/openMVS/data/{self.id}" - - self.pose_path = f"{self.asset_dir}/sparse/" + # self.asset_dir = f"/home/algo/Documents/openMVS/data/{self.id}" + self.asset_dir = args.base_path + self.mesh_path = args.mesh_path + # self.pose_path = f"{self.asset_dir}/sparse/" + self.pose_path = args.sparse_dir if not os.path.exists(self.pose_path): raise FileNotFoundError(f"Camera data not found: {self.pose_path}") + + self.mesh = None def load_model(self): """加载并初始化3D模型""" - model_path = f"{self.asset_dir}/repair.ply" + # model_path = f"{self.asset_dir}/repair.ply" + model_path = self.mesh_path if not os.path.exists(model_path): raise FileNotFoundError(f"Model file not found: {model_path}")