add 200 frames.

This commit is contained in:
Jordan
2024-03-27 11:05:48 -07:00
parent 3022adcbb7
commit 301fc2ca75
202 changed files with 86 additions and 46 deletions

View File

@ -1,5 +1,7 @@
#include "frame.h"
#include <iostream>
#include <stdexcept>
#include <stdlib.h>
FILE *make_buffer(const uint8_t *data, const size_t data_len)
{
@ -105,6 +107,13 @@ DartOpenMvg::Frames::Frames(openMVG::sfm::Bundle_Adjustment_Ceres::BA_Ceres_opti
mAdjustment = openMVG::sfm::Bundle_Adjustment_Ceres(options);
}
void DartOpenMvg::Frames::add_frame(FILE *handle, int w, int h, int depth) {
CFrame *f = new_frame_from_handle(handle, w, h, depth);
mFrames.push_back(
Frame(f)
);
}
void DartOpenMvg::Frames::computeMatches()
{
#ifdef OPENMVG_USE_OPENMP
@ -123,6 +132,15 @@ void DartOpenMvg::Frames::computeMatches()
const Frame &frame2 = mFrames[i+1];
auto *regions1 = frame1.mRegions.get();
auto *regions2 = frame2.mRegions.get();
if (!regions1) {
std::string msg = std::string("Did you remember to calculate regions for frame ") + std::to_string(i) + "?";
throw std::out_of_range(msg);
}
regions1->Load();
std::cerr << "Loading " << std::to_string(regions1->RegionCount()) << " regions" << endl;
auto is_binary = regions1->IsBinary();
// Initialize the matching interface
const std::unique_ptr<openMVG::matching::RegionsMatcher> matcher =

View File

@ -72,11 +72,12 @@ namespace DartOpenMvg
const CFrame *cFrame;
// TODO make this private
std::unique_ptr<openMVG::features::Regions> mRegions;
Frame(const _Frame *f) : mW(f->w), mH(f->h), mDepth(f->depth)
Frame(const CFrame *f) : mW(f->w), mH(f->h), mDepth(f->depth)
{
cFrame = f;
uint8_t *buffer_data = NULL;
size_t len = 0;
rewind(f->stream);
read_buffer(f->stream, &buffer_data, &len);
mStream = std::stringstream(std::string((char *)buffer_data));
}
@ -92,17 +93,17 @@ namespace DartOpenMvg
{
protected:
public:
// TODO: make private with accessors
openMVG::matching::PairWiseMatches mFeatureMap;
openMVG::tracks::STLMAPTracks mTracks;
openMVG::sfm::SfM_Data mSfmData;
openMVG::sfm::Bundle_Adjustment_Ceres mAdjustment;
public:
// TODO: make private with accessors
std::vector<Frame> mFrames;
Frames(openMVG::sfm::Bundle_Adjustment_Ceres::BA_Ceres_options &);
void add_frame(FILE *, int, int, int);
void computeMatches();
void buildTracks();
void adjust();

View File

@ -1,5 +1,8 @@
#include <sys/stat.h>
#include <archives/binary.hpp>
#include <CUnit/Basic.h>
#include <errno.h>
#include <ios>
#include "../image.h"
#include "../streamingview.hpp"
#include "../util.h"
@ -9,12 +12,11 @@
#endif // __cplusplus
#define STRLEN 2048
#define FRAME_COUNT 200
typedef Frame CFrame;
FILE *imageHandle = NULL;
char frame1Path[STRLEN];
char frame2Path[STRLEN];
char *framePaths[FRAME_COUNT];
#define HERE __FILE__
@ -22,60 +24,78 @@ int setUp(void)
{
char framesDir[STRLEN];
size_t length;
char framePathTpl[STRLEN];
cwk_path_get_dirname(HERE, &length); // archimedes_mobile_lib/src/tests
cwk_path_join(HERE, "../../../assets/test/frames", framesDir, STRLEN);
cwk_path_join(framesDir, "0001.png", frame1Path, STRLEN);
cwk_path_join(framesDir, "0002.png", frame2Path, STRLEN);
printf("Opening file %s\n", frame1Path);
return 0;
}
CFrame *get_first_frame() {
imageHandle = fopen(frame1Path, "rw+");
CFrame *f = new_frame_from_handle(
imageHandle,
768,
768,
64);
return f;
}
CFrame *get_second_frame() {
imageHandle = fopen(frame2Path, "rw+");
CFrame *f = new_frame_from_handle(
imageHandle,
768,
768,
64);
return f;
}
int tearDown(void)
{
if (imageHandle)
cwk_path_join(framesDir, "%04d.png", framePathTpl, STRLEN);
// Set the length to be the length of the "template" plus enough room
// for the sequence number.
size_t pathLen = strlen(framePathTpl) + 5;
for (size_t i = 0; i < FRAME_COUNT; ++i)
{
fclose(imageHandle);
framePaths[i] = (char *)calloc(pathLen, sizeof(char *));
snprintf(framePaths[i], pathLen, framePathTpl, i+1, 4);
printf("Load frame %s\n", framePaths[i]);
}
return 0;
}
void test_calculate_fetures(void) {
Frame *f = get_first_frame();
CFrame *get_nth_frame(size_t frame_num)
{
struct stat statbuf;
if (stat(framePaths[frame_num], &statbuf) < 0)
{
// std::cerr << "ERROR reading \"" << framePaths << "\"" << std::endl;
std::cerr << std::string("Reading \"") << std::string(framePaths[frame_num]) << std::string("\"") << std::endl;
throw new std::ios_base::failure(std::string(strerror(errno)));
}
FILE *handle = fopen(framePaths[frame_num], "r");
CFrame *f = new_frame_from_handle(
handle,
768,
768,
64);
return f;
}
int tearDown(void)
{
for (int i = 0; i < FRAME_COUNT; ++i)
{
free(framePaths[i]);
}
return 0;
}
void test_calculate_fetures(void)
{
Frame *f = get_nth_frame(0);
DartOpenMvg::Frame frame(f);
frame.calculateFeatures();
CU_ASSERT_TRUE(frame.mRegions.get()->RegionCount() > 0);
}
void test_compute_matches(void) {
Frame *f1 = get_first_frame();
Frame *f2 = get_second_frame();
const DartOpenMvg::Frame frame1(f1), frame2(f2);
void test_compute_matches(void)
{
Frame *f1 = get_nth_frame(0);
Frame *f2 = get_nth_frame(1);
DartOpenMvg::Frame frame1(f1), frame2(f2);
openMVG::sfm::Bundle_Adjustment_Ceres::BA_Ceres_options opts;
DartOpenMvg::Frames frames(opts);
frame1.calculateFeatures();
frame2.calculateFeatures();
frames.mFrames.push_back(frame1);
frames.mFrames.push_back(frame2);
CU_ASSERT_EQUAL(frames.mFeatureMap.size(), 0)
frames.computeMatches();
CU_ASSERT_TRUE(frames.mFeatureMap.size() > 0);
}
int main()
@ -95,7 +115,8 @@ int main()
}
/* add the tests to the suite */
if ((NULL == CU_add_test(pSuite, "frame features can be calculated", test_calculate_fetures)))
if ((NULL == CU_add_test(pSuite, "frame features can be calculated", test_calculate_fetures)) ||
(NULL == CU_add_test(pSuite, "matches can be computed", test_compute_matches)))
{
CU_cleanup_registry();
return CU_get_error();