|
|
#include <pybind11/pybind11.h>
|
|
|
#include <pybind11/stl.h> // 用于绑定 std::string 等
|
|
|
#include <pybind11/numpy.h>
|
|
|
#include <pybind11/stl/filesystem.h>
|
|
|
#include "StitchStruct.h" // 包含 API_UnderStitch 的定义
|
|
|
#include "Arith_UnderStitch.h"
|
|
|
#include "Arith_GeoSolver.h"
|
|
|
// 可能还需要包含其他依赖项,如 OpenCV 的绑定头文件
|
|
|
|
|
|
namespace py = pybind11;
|
|
|
|
|
|
// 声明外部的辅助绑定函数
|
|
|
void bind_public_structures(py::module_ &m);
|
|
|
void bind_api_understitch(py::module_ &m);
|
|
|
|
|
|
|
|
|
PYBIND11_MODULE(UStitcher, m) {
|
|
|
|
|
|
m.doc() = "pybind11 bindings for UnderStitcher.";
|
|
|
|
|
|
// 绑定通用数据结构
|
|
|
bind_public_structures(m);
|
|
|
|
|
|
// 绑定下视模块接口
|
|
|
bind_api_understitch(m);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void bind_api_understitch(py::module_& m) {
|
|
|
|
|
|
// UPanConfig
|
|
|
py::class_<UPanConfig>(m, "UPanConfig", "下视拼接参数控制")
|
|
|
.def(py::init<>())
|
|
|
.def_readwrite("bUseBA", &UPanConfig::bUseBA, "开启BA")
|
|
|
.def_readwrite("bOutFrameTile", &UPanConfig::bOutFrameTile, "输出单帧正射图")
|
|
|
.def_readwrite("bOutGoogleTile", &UPanConfig::bOutGoogleTile, "输出谷歌瓦片");
|
|
|
|
|
|
// FrameInfo
|
|
|
py::class_<FrameInfo>(m, "FrameInfo", "帧内外方位元素")
|
|
|
.def(py::init<>())
|
|
|
.def_readwrite("nFrmID", &FrameInfo::nFrmID, "帧编号,唯一ID")
|
|
|
.def_readwrite("craft", &FrameInfo::craft, "载体信息")
|
|
|
.def_readwrite("camInfo", &FrameInfo::camInfo, "相机信息")
|
|
|
.def_readwrite("servoInfo", &FrameInfo::servoInfo, "伺服状态")
|
|
|
.def_readwrite("nEvHeight", &FrameInfo::nEvHeight, "相对高差")
|
|
|
.def_readwrite("nWidth", &FrameInfo::nWidth)
|
|
|
.def_readwrite("nHeight", &FrameInfo::nHeight);
|
|
|
|
|
|
// UPanInfo
|
|
|
py::class_<UPanInfo>(m, "UPanInfo", "下视全景图配置")
|
|
|
.def(py::init<>())
|
|
|
.def_readwrite("m_pan_width", &UPanInfo::m_pan_width)
|
|
|
.def_readwrite("m_pan_height", &UPanInfo::m_pan_height)
|
|
|
.def_readwrite("scale", &UPanInfo::scale, "比例尺")
|
|
|
.def_readwrite("map_shiftX", &UPanInfo::map_shiftX, "平移X")
|
|
|
.def_readwrite("map_shiftY", &UPanInfo::map_shiftY, "平移Y");
|
|
|
// ----------------------------------------------------
|
|
|
// 2. 绑定 API_UnderStitch 类
|
|
|
// ----------------------------------------------------
|
|
|
py::class_<API_UnderStitch>(m, "API_UnderStitch")
|
|
|
// py::init() 是不必要的,因为它是抽象类
|
|
|
|
|
|
|
|
|
// 绑定纯虚函数 (这些函数需要在 C++ 派生类中实现)
|
|
|
.def("Init", &API_UnderStitch::Init,
|
|
|
py::arg("info"), "初始化拼接")
|
|
|
|
|
|
.def("SetOutput", &API_UnderStitch::SetOutput,
|
|
|
py::arg("name"), py::arg("outdir"), "设置输出标识和路径")
|
|
|
|
|
|
.def("Run", &API_UnderStitch::Run,
|
|
|
py::arg("img"), py::arg("para"), "运行拼接流程")
|
|
|
|
|
|
.def("Stop", &API_UnderStitch::Stop,
|
|
|
"中止拼接流程")
|
|
|
|
|
|
.def("SetConfig", &API_UnderStitch::SetConfig,
|
|
|
py::arg("config"), "运行参数配置")
|
|
|
|
|
|
|
|
|
.def("ExportPanAddr", &API_UnderStitch::ExportPanAddr,
|
|
|
py::return_value_policy::reference_internal, // 返回引用,确保 C++ 对象不被析构
|
|
|
"获取全景图")
|
|
|
|
|
|
.def("ExportPanMat", &API_UnderStitch::ExportPanMat,
|
|
|
py::return_value_policy::copy, // 通常 cv::Mat 返回时是深拷贝
|
|
|
"获取全景图cv::Mat")
|
|
|
|
|
|
//getHomography
|
|
|
.def("getHomography", &API_UnderStitch::getHomography,
|
|
|
py::return_value_policy::copy, // 通常 cv::Mat 返回时是深拷贝
|
|
|
"获取H映射矩阵:从像方到物方")
|
|
|
|
|
|
//----------------------------------------------------
|
|
|
//3. 绑定静态工厂方法 (Factory Methods)
|
|
|
//----------------------------------------------------
|
|
|
|
|
|
// 绑定 Create 方法
|
|
|
.def_static("Create", &API_UnderStitch::Create,
|
|
|
py::arg("cachedir") = "./cache",
|
|
|
py::return_value_policy::take_ownership, // 返回指针,需要 Python 管理其生命周期
|
|
|
"创建 API_UnderStitch 实例")
|
|
|
|
|
|
// 绑定 Destroy 方法
|
|
|
// 注意:这里需要 pybind11::arg::none() 来明确指出该函数没有返回值
|
|
|
.def_static("Destroy", &API_UnderStitch::Destroy,
|
|
|
py::arg("obj"),
|
|
|
"销毁 API_UnderStitch 实例")
|
|
|
|
|
|
;
|
|
|
|
|
|
|
|
|
}
|
|
|
|