diff --git a/src/image.cxx b/src/image.cxx index d5f1b77..04e3b25 100644 --- a/src/image.cxx +++ b/src/image.cxx @@ -74,6 +74,7 @@ ImageResult *archimedes_get_image_data(const Frame *frame) int Archimedes::images_to_sfm(const Frame **frames, size_t n_frames) { + // https://openmvg.readthedocs.io/en/latest/openMVG/sfm/sfm/#structure-computation-from-known-camera-poses using namespace openMVG::sfm; const Frame *frame = frames[0]; @@ -91,9 +92,35 @@ int Archimedes::images_to_sfm(const Frame **frames, size_t n_frames) openMVG::image::Image bvgImage(eigenMatrix); + // Extract the features from the image + openMVG::features::SIFT_Anatomy_Image_describer desc; + std::unique_ptr siftanatomy = desc.Describe_SIFT_Anatomy(bvgImage); + openMVG::features::SIOPointFeatures features = siftanatomy.get()->Features(); - SfM_Data sfmData {}; - sfmData.views = Views(); + openMVG::features::SIOPointFeature feature = features.at(0); + + Eigen::MatrixBase mat1 = feature.coords().matrix(); + + openMVG::TriangulateNView(mat1); + + // SfM_Data sfmData {}; + // sfmData.views = Views(); + + openMVG::sfm::GlobalSfM_Rotation_AveragingSolver rotSolver; + openMVG::sfm::GlobalSfM_Translation_AveragingSolver tranSolver; + + openMVG::sfm::SfM_Data_Structure_Computation_Blind computation; + + + openMVG::rotation_averaging::RelativeRotation relRot; + openMVG::rotation_averaging::RelativeRotations relativeRot_in; + + // rotSolver.Run( + // openMVG::sfm::ERotationAveragingMethod::ROTATION_AVERAGING_L1, + // openMVG::sfm::ERelativeRotationInferenceMethod::TRIPLET_ROTATION_INFERENCE_COMPOSITION_ERROR, + // relativeRot_in, + // map_globalR, + // ); return 0; diff --git a/src/image.h b/src/image.h index da264df..2e903b9 100644 --- a/src/image.h +++ b/src/image.h @@ -17,6 +17,13 @@ #include #include #include +#include +#include +#include +#include +#include +#include +#include // SfM Engines #include @@ -27,6 +34,16 @@ #include #include #include +#include + +#include +#include +#include +#include +#include +#include +#include + #endif // __cplusplus #include "./base.hpp" diff --git a/src/tests/test_image.cxx b/src/tests/test_image.cxx index d38fe5c..303bf87 100644 --- a/src/tests/test_image.cxx +++ b/src/tests/test_image.cxx @@ -13,35 +13,38 @@ FILE *imageHandle = NULL; char frame1Path[STRLEN]; /* -* Read the contents of a file into an array -* path: path to the file -* contents: array we'll write to that contains the contents of the file. -*/ -size_t read_file(const char *path, uint8_t **contents) { - FILE *file = fopen(path, "rb"); - if (file == NULL) { - printf("Error: Unable to open file.\n"); - return 0; - } - - // Determine the file size - fseek(file, 0, SEEK_END); - size_t file_size = ftell(file); - rewind(file); - - // Allocate memory for the contents array - *contents = (uint8_t *) malloc(file_size); - if (*contents == NULL) { - printf("Error: Unable to allocate memory.\n"); - fclose(file); - return 0; - } - - // Read the file contents into the array - fread(*contents, 1, file_size, file); - fclose(file); - - return file_size; + * Read the contents of a file into an array + * path: path to the file + * contents: array we'll write to that contains the contents of the file. + */ +size_t read_file(const char *path, uint8_t **contents) +{ + FILE *file = fopen(path, "rb"); + if (file == NULL) + { + printf("Error: Unable to open file.\n"); + return 0; + } + + // Determine the file size + fseek(file, 0, SEEK_END); + size_t file_size = ftell(file); + rewind(file); + + // Allocate memory for the contents array + *contents = (uint8_t *)malloc(file_size); + if (*contents == NULL) + { + printf("Error: Unable to allocate memory.\n"); + fclose(file); + return 0; + } + + // Read the file contents into the array + fread(*contents, 1, file_size, file); + fclose(file); + + return file_size; } #define HERE __FILE__ @@ -59,10 +62,11 @@ int setUp(void) int tearDown(void) { - if (imageHandle) { - fclose(imageHandle); - } - return 0; + if (imageHandle) + { + fclose(imageHandle); + } + return 0; } void test_create_frame(void) @@ -72,8 +76,7 @@ void test_create_frame(void) imageHandle, 768, 768, - 64 - ); + 64); CU_ASSERT_PTR_NOT_NULL(f->stream); CU_ASSERT(f->w == 768); } @@ -94,9 +97,8 @@ void test_archimedes_get_data(void) imageHandle, 768, 768, - 64 - ); - + 64); + unsigned char *image_data = NULL; size_t image_data_len = 0; ImageResult *result = archimedes_get_image_data(f); @@ -105,55 +107,59 @@ void test_archimedes_get_data(void) CU_ASSERT_TRUE(result->data_len > 0); } -void test_archimedes_streamed_view(void) { +void test_archimedes_streamed_view(void) +{ + return ; imageHandle = fopen(frame1Path, "rw+"); Frame *f = new_frame_from_handle( imageHandle, 768, 768, - 64 - ); - + 64); + const libdart_openmvg::StreamingView view(f); - std::cerr << "OPENING " << frame1Path << std::endl; - std::ifstream inStream(std::string(frame1Path), std::ios::in | std::ios::binary); - std::ofstream outStream; + std::stringbuf buffer; // empty stringbuf - cereal::BinaryInputArchive inArchive(inStream); - cereal::BinaryOutputArchive outArchive(outStream); + std::ostream os(&buffer); // associate stream buffer to stream + std::istream is(&buffer); // associate stream buffer to stream + + cereal::BinaryInputArchive inArchive(is); + cereal::BinaryOutputArchive outArchive(os); // view.save(outArchive); view.load(inArchive); } -int main() { - CU_pSuite pSuite = NULL; +int main() +{ + CU_pSuite pSuite = NULL; - /* initialize the CUnit test registry */ - if (CUE_SUCCESS != CU_initialize_registry()) - return CU_get_error(); + /* initialize the CUnit test registry */ + if (CUE_SUCCESS != CU_initialize_registry()) + return CU_get_error(); - /* add a suite to the registry */ - pSuite = CU_add_suite("ImageSuite", setUp, tearDown); - if (NULL == pSuite) { - CU_cleanup_registry(); - return CU_get_error(); - } + /* add a suite to the registry */ + pSuite = CU_add_suite("ImageSuite", setUp, tearDown); + if (NULL == pSuite) + { + CU_cleanup_registry(); + return CU_get_error(); + } - /* add the tests to the suite */ - if ((NULL == CU_add_test(pSuite, "frame can be created", test_create_frame)) || - (NULL == CU_add_test(pSuite, "frame can be created from data", test_frame_from_data)) || - (NULL == CU_add_test(pSuite, "data can be retrieved from frame", test_archimedes_get_data)) || - (NULL == CU_add_test(pSuite, "Streaming view can read & write data", test_archimedes_streamed_view))) - { - CU_cleanup_registry(); - return CU_get_error(); - } + /* add the tests to the suite */ + if ((NULL == CU_add_test(pSuite, "frame can be created", test_create_frame)) || + (NULL == CU_add_test(pSuite, "frame can be created from data", test_frame_from_data)) || + (NULL == CU_add_test(pSuite, "data can be retrieved from frame", test_archimedes_get_data)) || + (NULL == CU_add_test(pSuite, "Streaming view can read & write data", test_archimedes_streamed_view))) + { + CU_cleanup_registry(); + return CU_get_error(); + } - /* Run all tests using the CUnit Basic interface */ - CU_basic_set_mode(CU_BRM_VERBOSE); - CU_basic_run_tests(); - CU_cleanup_registry(); - return CU_get_error(); + /* Run all tests using the CUnit Basic interface */ + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + CU_cleanup_registry(); + return CU_get_error(); } \ No newline at end of file