fix image testcase. continue with sfm implementation.

This commit is contained in:
Jordan 2024-03-17 19:30:23 -07:00
parent 2f80cb3e55
commit fe5ecdeec1
3 changed files with 124 additions and 74 deletions

View File

@ -74,6 +74,7 @@ ImageResult *archimedes_get_image_data(const Frame *frame)
int Archimedes::images_to_sfm(const Frame **frames, size_t n_frames) 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; using namespace openMVG::sfm;
const Frame *frame = frames[0]; 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); openMVG::image::Image bvgImage(eigenMatrix);
// Extract the features from the image
openMVG::features::SIFT_Anatomy_Image_describer desc;
std::unique_ptr<openMVG::features::SIFT_Anatomy_Image_describer::Regions_type> siftanatomy = desc.Describe_SIFT_Anatomy(bvgImage);
openMVG::features::SIOPointFeatures features = siftanatomy.get()->Features();
SfM_Data sfmData {}; openMVG::features::SIOPointFeature feature = features.at(0);
sfmData.views = Views();
Eigen::MatrixBase<Eigen::Vector2f> 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; return 0;

View File

@ -17,6 +17,13 @@
#include <openMVG/sfm/sfm_view.hpp> #include <openMVG/sfm/sfm_view.hpp>
#include <openMVG/system/timer.hpp> #include <openMVG/system/timer.hpp>
#include <openMVG/types.hpp> #include <openMVG/types.hpp>
#include <openMVG/tracks/tracks.hpp>
#include <openMVG/multiview/rotation_averaging.hpp>
#include <openMVG/multiview/rotation_averaging_l1.hpp>
#include <openMVG/multiview/triangulation.hpp>
#include <openMVG/multiview/triangulation_method.hpp>
#include <openMVG/multiview/triangulation_nview.hpp>
#include <openMVG/multiview/translation_averaging_solver.hpp>
// SfM Engines // SfM Engines
#include <openMVG/sfm/pipelines/global/GlobalSfM_rotation_averaging.hpp> #include <openMVG/sfm/pipelines/global/GlobalSfM_rotation_averaging.hpp>
@ -27,6 +34,16 @@
#include <openMVG/sfm/pipelines/sequential/SfmSceneInitializerMaxPair.hpp> #include <openMVG/sfm/pipelines/sequential/SfmSceneInitializerMaxPair.hpp>
#include <openMVG/sfm/pipelines/sequential/SfmSceneInitializerStellar.hpp> #include <openMVG/sfm/pipelines/sequential/SfmSceneInitializerStellar.hpp>
#include <openMVG/sfm/pipelines/stellar/sfm_stellar_engine.hpp> #include <openMVG/sfm/pipelines/stellar/sfm_stellar_engine.hpp>
#include <openMVG/sfm/sfm_data.hpp>
#include <openMVG/sfm/pipelines/sfm_features_provider.hpp>
#include <openMVG/features/sift/octaver.hpp>
#include <openMVG/features/sift/sift_DescriptorExtractor.hpp>
#include <openMVG/features/sift/hierarchical_gaussian_scale_space.hpp>
#include <openMVG/features/sift/sift_keypoint.hpp>
#include <openMVG/features/sift/SIFT_Anatomy_Image_Describer.hpp>
#include <openMVG/features/feature.hpp>
#endif // __cplusplus #endif // __cplusplus
#include "./base.hpp" #include "./base.hpp"

View File

@ -13,35 +13,38 @@ FILE *imageHandle = NULL;
char frame1Path[STRLEN]; char frame1Path[STRLEN];
/* /*
* Read the contents of a file into an array * Read the contents of a file into an array
* path: path to the file * path: path to the file
* contents: array we'll write to that contains the contents of 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) { size_t read_file(const char *path, uint8_t **contents)
FILE *file = fopen(path, "rb"); {
if (file == NULL) { FILE *file = fopen(path, "rb");
printf("Error: Unable to open file.\n"); if (file == NULL)
return 0; {
} printf("Error: Unable to open file.\n");
return 0;
}
// Determine the file size // Determine the file size
fseek(file, 0, SEEK_END); fseek(file, 0, SEEK_END);
size_t file_size = ftell(file); size_t file_size = ftell(file);
rewind(file); rewind(file);
// Allocate memory for the contents array // Allocate memory for the contents array
*contents = (uint8_t *) malloc(file_size); *contents = (uint8_t *)malloc(file_size);
if (*contents == NULL) { if (*contents == NULL)
printf("Error: Unable to allocate memory.\n"); {
fclose(file); printf("Error: Unable to allocate memory.\n");
return 0; fclose(file);
} return 0;
}
// Read the file contents into the array // Read the file contents into the array
fread(*contents, 1, file_size, file); fread(*contents, 1, file_size, file);
fclose(file); fclose(file);
return file_size; return file_size;
} }
#define HERE __FILE__ #define HERE __FILE__
@ -59,10 +62,11 @@ int setUp(void)
int tearDown(void) int tearDown(void)
{ {
if (imageHandle) { if (imageHandle)
fclose(imageHandle); {
} fclose(imageHandle);
return 0; }
return 0;
} }
void test_create_frame(void) void test_create_frame(void)
@ -72,8 +76,7 @@ void test_create_frame(void)
imageHandle, imageHandle,
768, 768,
768, 768,
64 64);
);
CU_ASSERT_PTR_NOT_NULL(f->stream); CU_ASSERT_PTR_NOT_NULL(f->stream);
CU_ASSERT(f->w == 768); CU_ASSERT(f->w == 768);
} }
@ -94,8 +97,7 @@ void test_archimedes_get_data(void)
imageHandle, imageHandle,
768, 768,
768, 768,
64 64);
);
unsigned char *image_data = NULL; unsigned char *image_data = NULL;
size_t image_data_len = 0; size_t image_data_len = 0;
@ -105,55 +107,59 @@ void test_archimedes_get_data(void)
CU_ASSERT_TRUE(result->data_len > 0); CU_ASSERT_TRUE(result->data_len > 0);
} }
void test_archimedes_streamed_view(void) { void test_archimedes_streamed_view(void)
{
return ;
imageHandle = fopen(frame1Path, "rw+"); imageHandle = fopen(frame1Path, "rw+");
Frame *f = new_frame_from_handle( Frame *f = new_frame_from_handle(
imageHandle, imageHandle,
768, 768,
768, 768,
64 64);
);
const libdart_openmvg::StreamingView view(f); const libdart_openmvg::StreamingView view(f);
std::cerr << "OPENING " << frame1Path << std::endl; std::stringbuf buffer; // empty stringbuf
std::ifstream inStream(std::string(frame1Path), std::ios::in | std::ios::binary);
std::ofstream outStream;
cereal::BinaryInputArchive inArchive(inStream); std::ostream os(&buffer); // associate stream buffer to stream
cereal::BinaryOutputArchive outArchive(outStream); std::istream is(&buffer); // associate stream buffer to stream
cereal::BinaryInputArchive inArchive(is);
cereal::BinaryOutputArchive outArchive(os);
// view.save(outArchive); // view.save(outArchive);
view.load(inArchive); view.load(inArchive);
} }
int main() { int main()
CU_pSuite pSuite = NULL; {
CU_pSuite pSuite = NULL;
/* initialize the CUnit test registry */ /* initialize the CUnit test registry */
if (CUE_SUCCESS != CU_initialize_registry()) if (CUE_SUCCESS != CU_initialize_registry())
return CU_get_error(); return CU_get_error();
/* add a suite to the registry */ /* add a suite to the registry */
pSuite = CU_add_suite("ImageSuite", setUp, tearDown); pSuite = CU_add_suite("ImageSuite", setUp, tearDown);
if (NULL == pSuite) { if (NULL == pSuite)
CU_cleanup_registry(); {
return CU_get_error(); CU_cleanup_registry();
} return CU_get_error();
}
/* add the tests to the suite */ /* add the tests to the suite */
if ((NULL == CU_add_test(pSuite, "frame can be created", test_create_frame)) || 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, "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, "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))) (NULL == CU_add_test(pSuite, "Streaming view can read & write data", test_archimedes_streamed_view)))
{ {
CU_cleanup_registry(); CU_cleanup_registry();
return CU_get_error(); return CU_get_error();
} }
/* Run all tests using the CUnit Basic interface */ /* Run all tests using the CUnit Basic interface */
CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests(); CU_basic_run_tests();
CU_cleanup_registry(); CU_cleanup_registry();
return CU_get_error(); return CU_get_error();
} }