|
|
@@ -12,44 +12,44 @@
|
|
|
|
|
|
using namespace osg;
|
|
|
|
|
|
-namespace {
|
|
|
- sp_image create_remap_image(const camera_intrinsic_v0 &info) {
|
|
|
- const auto img_size = cv::Size(info.width, info.height);
|
|
|
- const auto pix_num = img_size.area();
|
|
|
- auto pix_mat = cv::Mat(1, pix_num, CV_32FC2);
|
|
|
- for (auto iy = 0; iy < info.height; ++iy)
|
|
|
- for (auto ix = 0; ix < info.width; ++ix) {
|
|
|
- const auto id = iy * info.width + ix;
|
|
|
- pix_mat.at<cv::Vec2f>(id) = cv::Vec2f(ix, iy);
|
|
|
- }
|
|
|
- auto ret = sp_image::create(CV_32FC2, img_size);
|
|
|
- const auto write_helper = write_access_helper(ret.host());
|
|
|
- auto ret_mat = cv::Mat(1, pix_num, CV_32FC2,
|
|
|
- ret.start_ptr(write_helper.ptr()));
|
|
|
- cv::undistortPoints(pix_mat, ret_mat,
|
|
|
- info.intrinsic_cv_mat(), info.dist_cv_mat());
|
|
|
- return ret;
|
|
|
- }
|
|
|
-
|
|
|
- cv::Rect2d calc_remap_range(const sp_image &remap) {
|
|
|
- assert(CV_MAT_CN(remap.cv_type()) == 2);
|
|
|
- const auto read_helper = read_access_helper(remap.host());
|
|
|
- const auto cv_mat = remap.cv_mat(read_helper.ptr());
|
|
|
- auto cv_xy = std::vector<cv::Mat>();
|
|
|
- cv::split(cv_mat, cv_xy);
|
|
|
- assert(cv_xy.size() == 2);
|
|
|
- double x_min, x_max, y_min, y_max;
|
|
|
- cv::minMaxLoc(cv_xy[0], &x_min, &x_max);
|
|
|
- cv::minMaxLoc(cv_xy[1], &y_min, &y_max);
|
|
|
- return {
|
|
|
- x_min, y_min,
|
|
|
- x_max - x_min, y_max - y_min
|
|
|
- };
|
|
|
- }
|
|
|
-
|
|
|
- constexpr auto max_camera_y_axis_len = 3.f;
|
|
|
- constexpr auto max_camera_x_axis_len = 6.f;
|
|
|
-}
|
|
|
+// namespace {
|
|
|
+// sp_image create_remap_image(const camera_intrinsic_v0 &info) {
|
|
|
+// const auto img_size = cv::Size(info.width, info.height);
|
|
|
+// const auto pix_num = img_size.area();
|
|
|
+// auto pix_mat = cv::Mat(1, pix_num, CV_32FC2);
|
|
|
+// for (auto iy = 0; iy < info.height; ++iy)
|
|
|
+// for (auto ix = 0; ix < info.width; ++ix) {
|
|
|
+// const auto id = iy * info.width + ix;
|
|
|
+// pix_mat.at<cv::Vec2f>(id) = cv::Vec2f(ix, iy);
|
|
|
+// }
|
|
|
+// auto ret = sp_image::create(CV_32FC2, img_size);
|
|
|
+// const auto write_helper = write_access_helper(ret.host());
|
|
|
+// auto ret_mat = cv::Mat(1, pix_num, CV_32FC2,
|
|
|
+// ret.start_ptr(write_helper.ptr()));
|
|
|
+// cv::undistortPoints(pix_mat, ret_mat,
|
|
|
+// info.intrinsic_cv_mat(), info.dist_cv_mat());
|
|
|
+// return ret;
|
|
|
+// }
|
|
|
+//
|
|
|
+// cv::Rect2d calc_remap_range(const sp_image &remap) {
|
|
|
+// assert(CV_MAT_CN(remap.cv_type()) == 2);
|
|
|
+// const auto read_helper = read_access_helper(remap.host());
|
|
|
+// const auto cv_mat = remap.cv_mat(read_helper.ptr());
|
|
|
+// auto cv_xy = std::vector<cv::Mat>();
|
|
|
+// cv::split(cv_mat, cv_xy);
|
|
|
+// assert(cv_xy.size() == 2);
|
|
|
+// double x_min, x_max, y_min, y_max;
|
|
|
+// cv::minMaxLoc(cv_xy[0], &x_min, &x_max);
|
|
|
+// cv::minMaxLoc(cv_xy[1], &y_min, &y_max);
|
|
|
+// return {
|
|
|
+// x_min, y_min,
|
|
|
+// x_max - x_min, y_max - y_min
|
|
|
+// };
|
|
|
+// }
|
|
|
+//
|
|
|
+// constexpr auto max_camera_y_axis_len = 3.f;
|
|
|
+// constexpr auto max_camera_x_axis_len = 6.f;
|
|
|
+// }
|
|
|
|
|
|
struct image_augment::impl {
|
|
|
create_config conf;
|
|
|
@@ -75,42 +75,43 @@ struct image_augment::impl {
|
|
|
ref_ptr<Texture2DSP> out_tex;
|
|
|
|
|
|
void update_remap() {
|
|
|
- const auto info = OBJ_QUERY(camera_intrinsic_v0, conf.cam_info_name);
|
|
|
- const auto info_ts = OBJ_TS(conf.cam_info_name);
|
|
|
- const auto out_size = cv::Size(info.width, info.height);
|
|
|
- const auto remap_np = create_remap_image(info);
|
|
|
- const cv::Rect2f remap_range = calc_remap_range(remap_np);
|
|
|
-
|
|
|
- const auto x_min = remap_range.x, x_max = x_min + remap_range.width;
|
|
|
- const auto y_min = remap_range.y, y_max = y_min + remap_range.height;
|
|
|
- auto x_len = std::max(-x_min, x_max);
|
|
|
- auto y_len = std::max(-y_min, y_max);
|
|
|
- x_len = std::min(x_len, max_camera_x_axis_len);
|
|
|
- y_len = std::min(y_len, max_camera_y_axis_len);
|
|
|
- const auto cam_fov = 2.f * std::atan(y_len);
|
|
|
-
|
|
|
- const auto aspect = x_len / y_len;
|
|
|
- auto aug_size = cv::Size(info.height * aspect, // width
|
|
|
- info.height);
|
|
|
- aug_size *= 2; // double render size
|
|
|
- const auto remap_tex = image_remap_np_to_tex(remap_np, cam_fov, aspect);
|
|
|
-
|
|
|
- MAIN_DETACH([=, this] {
|
|
|
- setupTextureHelper(aug_tex, aug_size);
|
|
|
- aug_cam->setViewport(0, 0, aug_size.width, aug_size.height);
|
|
|
- aug_cam->attach(Camera::COLOR_BUFFER0, aug_tex);
|
|
|
- aug_img_osg->setImageTex(aug_tex);
|
|
|
- aug_img_osg->setRemapImage(remap_tex);
|
|
|
- cam_conf.fov = glm::degrees(cam_fov);
|
|
|
- cam_conf.aspect = aspect;
|
|
|
-
|
|
|
- setupTextureHelper(out_tex, out_size);
|
|
|
- const auto out_cam = viewer->getCamera();
|
|
|
- out_cam->setViewport(0, 0, out_size.width, out_size.height);
|
|
|
- out_cam->attach(Camera::COLOR_BUFFER0, out_tex);
|
|
|
-
|
|
|
- last_update_ts = info_ts;
|
|
|
- });
|
|
|
+ assert(false); // TODO: broken
|
|
|
+ // const auto info = OBJ_QUERY(camera_intrinsic_v0, conf.cam_info_name);
|
|
|
+ // const auto info_ts = OBJ_TS(conf.cam_info_name);
|
|
|
+ // const auto out_size = cv::Size(info.width, info.height);
|
|
|
+ // const auto remap_np = create_remap_image(info);
|
|
|
+ // const cv::Rect2f remap_range = calc_remap_range(remap_np);
|
|
|
+ //
|
|
|
+ // const auto x_min = remap_range.x, x_max = x_min + remap_range.width;
|
|
|
+ // const auto y_min = remap_range.y, y_max = y_min + remap_range.height;
|
|
|
+ // auto x_len = std::max(-x_min, x_max);
|
|
|
+ // auto y_len = std::max(-y_min, y_max);
|
|
|
+ // x_len = std::min(x_len, max_camera_x_axis_len);
|
|
|
+ // y_len = std::min(y_len, max_camera_y_axis_len);
|
|
|
+ // const auto cam_fov = 2.f * std::atan(y_len);
|
|
|
+ //
|
|
|
+ // const auto aspect = x_len / y_len;
|
|
|
+ // auto aug_size = cv::Size(info.height * aspect, // width
|
|
|
+ // info.height);
|
|
|
+ // aug_size *= 2; // double render size
|
|
|
+ // const auto remap_tex = image_remap_np_to_tex(remap_np, cam_fov, aspect);
|
|
|
+ //
|
|
|
+ // MAIN_DETACH([=, this] {
|
|
|
+ // setupTextureHelper(aug_tex, aug_size);
|
|
|
+ // aug_cam->setViewport(0, 0, aug_size.width, aug_size.height);
|
|
|
+ // aug_cam->attach(Camera::COLOR_BUFFER0, aug_tex);
|
|
|
+ // aug_img_osg->setImageTex(aug_tex);
|
|
|
+ // aug_img_osg->setRemapImage(remap_tex);
|
|
|
+ // cam_conf.fov = glm::degrees(cam_fov);
|
|
|
+ // cam_conf.aspect = aspect;
|
|
|
+ //
|
|
|
+ // setupTextureHelper(out_tex, out_size);
|
|
|
+ // const auto out_cam = viewer->getCamera();
|
|
|
+ // out_cam->setViewport(0, 0, out_size.width, out_size.height);
|
|
|
+ // out_cam->attach(Camera::COLOR_BUFFER0, out_tex);
|
|
|
+ //
|
|
|
+ // last_update_ts = info_ts;
|
|
|
+ // });
|
|
|
}
|
|
|
|
|
|
void image_callback_impl() {
|