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)
{
// 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<openMVG::features::SIFT_Anatomy_Image_describer::Regions_type> 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<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;

View File

@ -17,6 +17,13 @@
#include <openMVG/sfm/sfm_view.hpp>
#include <openMVG/system/timer.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
#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/SfmSceneInitializerStellar.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
#include "./base.hpp"

View File

@ -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();
}