satdump/tools/proj_test/main.cpp

152 lines
5.6 KiB
C++
Raw Permalink Normal View History

2025-05-04 12:48:02 +02:00
int main(int /*argc*/, char *argv[]) {}
2025-03-24 17:59:58 +01:00
#if 0
2025-05-04 12:48:02 +02:00
#include "common/geodetic/vincentys_calculations.h"
#include "image/io.h"
2022-05-31 23:40:59 +02:00
#include "common/map/map_drawer.h"
#include "common/projection/gcp_compute/gcp_compute.h"
#include "common/projection/projs/equirectangular.h"
2025-05-04 12:48:02 +02:00
#include "common/projection/warp/warp.h"
#include "common/utils.h"
2025-05-04 12:48:02 +02:00
#include "core/config.h"
2023-01-09 21:44:00 +01:00
#include "init.h"
2025-05-04 12:48:02 +02:00
#include "logger.h"
#include "nlohmann/json_utils.h"
#include "products/image_products.h"
#include "core/resources.h"
#include "common/projection/warp/warp_bkd.h"
geodetic::geodetic_coords_t calculate_center_of_points(std::vector<geodetic::geodetic_coords_t> points)
{
double x_total = 0;
double y_total = 0;
double z_total = 0;
for (auto &pt : points)
{
pt.toRads();
x_total += cos(pt.lat) * cos(pt.lon);
y_total += cos(pt.lat) * sin(pt.lon);
z_total += sin(pt.lat);
}
x_total /= points.size();
y_total /= points.size();
z_total /= points.size();
double lon = atan2(y_total, x_total);
double hyp = sqrt(x_total * x_total + y_total * y_total);
double lat = atan2(z_total, hyp);
return geodetic::geodetic_coords_t(lat, lon, 0, true).toDegs();
}
2022-05-31 23:40:59 +02:00
2022-09-14 17:47:15 +02:00
int main(int /*argc*/, char *argv[])
2022-05-31 23:40:59 +02:00
{
initLogger();
2023-01-09 21:44:00 +01:00
// std::string user_path = std::string(getenv("HOME")) + "/.config/satdump";
// satdump::config::loadConfig("satdump_cfg.json", user_path);
2023-10-01 00:25:51 +02:00
// initFileSink();
2023-01-09 21:44:00 +01:00
// We don't wanna spam with init this time around
2023-02-26 01:12:02 +00:00
logger->set_level(slog::LOG_OFF);
2023-01-09 21:44:00 +01:00
satdump::initSatdump();
completeLoggerInit();
2023-02-26 01:12:02 +00:00
logger->set_level(slog::LOG_TRACE);
2022-05-31 23:40:59 +02:00
satdump::ImageProducts img_pro;
img_pro.load(argv[1]);
2023-10-01 21:55:17 +02:00
printf("\n%s\n", img_pro.contents.dump(4).c_str());
2022-05-31 23:40:59 +02:00
satdump::ImageCompositeCfg rgb_cfg;
2025-03-14 14:39:05 +01:00
rgb_cfg.expression = "ch3,ch2,ch1"; //"(ch7421+ch7422+ch7423+ch7242)/4";
// rgb_cfg.expression = "1-ch37";
// rgb_cfg.expression = "1-ch33,1-ch34,1-ch35"; //"(ch3 * 0.4 + ch2 * 0.6) * 2.2 - 0.15, ch2 * 2.2 - 0.15, ch1 * 2.2 - 0.15";
rgb_cfg.equalize = true;
2023-10-29 22:19:19 +01:00
// rgb_cfg.white_balance = true;
2023-10-12 17:17:04 +02:00
// rgb_cfg.normalize = true;
// rgb_cfg.apply_lut = true;
2022-05-31 23:40:59 +02:00
// img_pro.images[0].image.equalize();
// img_pro.images[0].image.to_rgb();
2022-09-19 14:21:45 +02:00
// filter_timestamps_simple(img_pro.get_timestamps(0), 1e4, 10));
satdump::warp::WarpOperation operation_t;
2022-12-25 22:22:45 +01:00
std::vector<double> final_tt;
2023-10-01 00:25:51 +02:00
nlohmann::json final_mtd;
2024-11-18 16:40:57 -05:00
image::Image input_image = satdump::make_composite_from_product(img_pro, rgb_cfg, nullptr, &final_tt, &final_mtd);
input_image = input_image.to16bits();
operation_t.input_image = &input_image;
// operation_t.input_image.median_blur();
2024-10-08 08:10:13 +02:00
nlohmann::json proj_cfg = img_pro.get_proj_cfg(); // loadJsonFile(argv[2]);
proj_cfg["metadata"] = final_mtd;
proj_cfg["metadata"]["tle"] = img_pro.get_tle();
proj_cfg["metadata"]["timestamps"] = final_tt;
2023-10-12 17:17:04 +02:00
printf("%s\n", final_mtd.dump(4).c_str());
2023-09-29 23:21:43 +02:00
operation_t.ground_control_points = satdump::gcp_compute::compute_gcps(proj_cfg,
2024-11-18 16:40:57 -05:00
operation_t.input_image->width(),
operation_t.input_image->height());
operation_t.output_width = 2048 * 2; // 10;
operation_t.output_height = 1024 * 2; // 10;
operation_t.output_rgba = true;
#if 0
2023-09-28 23:25:18 +02:00
auto warp_result = satdump::warp::performSmartWarp(operation_t);
#else
satdump::warp::ImageWarper warper;
warper.op = operation_t;
warper.update();
auto warp_result = warper.warp();
#endif
2023-09-28 23:25:18 +02:00
2024-03-20 19:46:09 +01:00
logger->info("Wrapped!");
2023-09-28 23:25:18 +02:00
geodetic::projection::EquirectangularProjection projector_final;
projector_final.init(warp_result.output_image.width(), warp_result.output_image.height(), warp_result.top_left.lon, warp_result.top_left.lat, warp_result.bottom_right.lon, warp_result.bottom_right.lat);
2024-03-20 19:46:09 +01:00
logger->info("Map overlay!");
2024-05-12 17:23:42 +02:00
std::vector<double> color = {0, 1, 0, 1};
2023-09-28 23:25:18 +02:00
map::drawProjectedMapShapefile({resources::getResourcePath("maps/ne_10m_admin_0_countries.shp")},
warp_result.output_image,
color,
[&projector_final](float lat, float lon, int, int) -> std::pair<int, int>
{
int x, y;
projector_final.forward(lon, lat, x, y);
return {x, y};
});
2023-10-16 00:46:04 +02:00
{
2024-05-12 17:23:42 +02:00
std::vector<double> color = {1, 1, 0, 1};
map::drawProjectedMapShapefile(
2024-03-20 19:46:09 +01:00
{resources::getResourcePath("maps/ne_10m_admin_0_countries.shp")},
warp_result.output_image,
color,
[&projector_final](float lat, float lon, int, int) -> std::pair<int, int>
{
int x, y;
projector_final.forward(lon, lat, x, y);
return {x, y};
2023-10-17 18:34:35 +02:00
});
2023-10-16 00:46:04 +02:00
}
2024-09-17 19:56:29 +02:00
#if 1
2023-10-14 22:25:43 +02:00
{
2024-09-17 19:56:29 +02:00
std::vector<double> color = {0, 0, 1, 1};
2023-10-14 22:25:43 +02:00
map::drawProjectedMapLatLonGrid(warp_result.output_image,
color,
[&projector_final](float lat, float lon, int, int) -> std::pair<int, int>
{
int x, y;
projector_final.forward(lon, lat, x, y);
return {x, y};
});
}
2023-10-15 12:05:41 +02:00
#endif
2023-09-28 23:25:18 +02:00
2024-05-12 17:23:42 +02:00
image::save_img(warp_result.output_image, "test");
2022-05-31 23:40:59 +02:00
}
2025-03-24 17:59:58 +01:00
#endif // TODOREWORK