From 2e304394e5cad49e9e527d77430ad1b85fc12475 Mon Sep 17 00:00:00 2001 From: Jordan Hewitt Date: Fri, 22 Mar 2024 17:27:54 -0700 Subject: [PATCH] add workflow cpp. --- scripts/runtests.sh | 2 +- scripts/watch_tests.sh | 2 +- src/CMakeLists.txt | 11 ++++++---- src/extlib/openMVG | 2 +- src/frame.cxx | 5 +++++ src/frame.h | 4 ++-- src/tests/test_frame.cxx | 44 +++++++++++++++++++++++++++++++--------- util.cpp => src/util.cpp | 2 ++ src/util.h | 4 ++++ src/workflow.h | 14 +++++++++++++ 10 files changed, 71 insertions(+), 19 deletions(-) rename util.cpp => src/util.cpp (96%) create mode 100644 src/workflow.h diff --git a/scripts/runtests.sh b/scripts/runtests.sh index e579cdf..d9eadae 100755 --- a/scripts/runtests.sh +++ b/scripts/runtests.sh @@ -11,4 +11,4 @@ DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd) BUILD_DIR=$(realpath ${DIR}/../build) printf '\033c' -${BUILD_DIR}/test_image \ No newline at end of file +${BUILD_DIR}/test_frame \ No newline at end of file diff --git a/scripts/watch_tests.sh b/scripts/watch_tests.sh index 9065e61..4f83b85 100755 --- a/scripts/watch_tests.sh +++ b/scripts/watch_tests.sh @@ -10,4 +10,4 @@ DIR=$(cd -P "$(dirname "$SOURCE")" >/dev/null 2>&1 && pwd) BUILD_DIR=$(realpath ${DIR}/../build) -echo ${BUILD_DIR}/test_image | entr -r ${DIR}/runtests.sh \ No newline at end of file +echo ${BUILD_DIR}/test_frame | entr -r ${DIR}/runtests.sh \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7e7a92a..c65a8c0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -100,11 +100,13 @@ target_link_options(${LIBDART_OPENMVG} PRIVATE "-Wl,-Bdynamic") add_executable( test_image ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_image.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/util.cpp ) add_executable( test_frame - ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_image.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_frame.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/util.cpp ) target_link_libraries( @@ -151,9 +153,10 @@ target_include_directories( ${CEREAL_INCLUDE_DIR} ) -set_target_properties(test_image -PROPERTIES -LINKER_LANGUAGE CXX +set_target_properties( + test_image + PROPERTIES + LINKER_LANGUAGE CXX ) add_test ( diff --git a/src/extlib/openMVG b/src/extlib/openMVG index aff37dd..7fd19fc 160000 --- a/src/extlib/openMVG +++ b/src/extlib/openMVG @@ -1 +1 @@ -Subproject commit aff37dd005f85b3589aa50caca13b74ca7bd57e4 +Subproject commit 7fd19fc22419a35481d39d2946f77e1dc00df37c diff --git a/src/frame.cxx b/src/frame.cxx index 2d727a5..cc82a3e 100644 --- a/src/frame.cxx +++ b/src/frame.cxx @@ -70,6 +70,11 @@ Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth) return f; } +void clean_frame(Frame *f) { + fclose(f->stream); + free(f); +} + #ifdef __cplusplus openMVG::image::Image DartOpenMvg::imageFromFrame(const CFrame *frame) diff --git a/src/frame.h b/src/frame.h index 3224081..c878670 100644 --- a/src/frame.h +++ b/src/frame.h @@ -87,7 +87,7 @@ namespace DartOpenMvg typedef std::pair FrameMatchKey; typedef std::map, openMVG::matching::IndMatches> FrameFeatureMatch; - class Frames : protected std::vector + class Frames : protected std::vector { protected: @@ -112,6 +112,6 @@ Frame *new_frame_from_handle(FILE *, int, int, int); _FFI_PLUGIN Frame *new_frame_from_data(const uint8_t *, const size_t, int, int, int); -void frame_cleanup(Frame **); +void frame_cleanup(Frame *); #endif // __FRAME_H \ No newline at end of file diff --git a/src/tests/test_frame.cxx b/src/tests/test_frame.cxx index f575ac0..2c50cca 100644 --- a/src/tests/test_frame.cxx +++ b/src/tests/test_frame.cxx @@ -10,8 +10,11 @@ #define STRLEN 2048 +typedef Frame CFrame; + FILE *imageHandle = NULL; char frame1Path[STRLEN]; +char frame2Path[STRLEN]; #define HERE __FILE__ @@ -22,13 +25,14 @@ int setUp(void) 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; } -Frame *get_frame() { +CFrame *get_first_frame() { imageHandle = fopen(frame1Path, "rw+"); - Frame *f = new_frame_from_handle( + CFrame *f = new_frame_from_handle( imageHandle, 768, 768, @@ -36,10 +40,17 @@ Frame *get_frame() { return f; } -void destroy_frame() { - frame_ +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) @@ -49,7 +60,23 @@ int tearDown(void) return 0; } -void test_calculate_fetures +void test_calculate_fetures(void) { + Frame *f = get_first_frame(); + 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(); + DartOpenMvg::Frame frame1(f1), frame2(f2); + openMVG::sfm::Bundle_Adjustment_Ceres::BA_Ceres_options opts; + DartOpenMvg::Frames frames(opts); + frames.insert(frame1); + frames.insert(frame2); +} int main() { @@ -60,7 +87,7 @@ int main() return CU_get_error(); /* add a suite to the registry */ - pSuite = CU_add_suite("ImageSuite", setUp, tearDown); + pSuite = CU_add_suite("FrameSuite", setUp, tearDown); if (NULL == pSuite) { CU_cleanup_registry(); @@ -68,10 +95,7 @@ int main() } /* 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))) + if ((NULL == CU_add_test(pSuite, "frame features can be calculated", test_calculate_fetures))) { CU_cleanup_registry(); return CU_get_error(); diff --git a/util.cpp b/src/util.cpp similarity index 96% rename from util.cpp rename to src/util.cpp index c9bdea9..bc0e8de 100644 --- a/util.cpp +++ b/src/util.cpp @@ -1,3 +1,5 @@ +#include "./util.h" + size_t read_file(const char *path, uint8_t **contents) { FILE *file = fopen(path, "rb"); diff --git a/src/util.h b/src/util.h index 047d00d..709ea48 100644 --- a/src/util.h +++ b/src/util.h @@ -1,3 +1,7 @@ +#include +#include +#include + /* * Read the contents of a file into an array * path: path to the file diff --git a/src/workflow.h b/src/workflow.h new file mode 100644 index 0000000..96d4c9f --- /dev/null +++ b/src/workflow.h @@ -0,0 +1,14 @@ +#include + +#ifndef __WORKFLOW_H +#define __WORKFLOW_H + +#ifdef __cplusplus +namespace DartOpenmvg { + class MvgWorkflow { + MvgWorkflow(); + }; +} +#endif // __cplusplus + +#endif // __WORKFLOW_H \ No newline at end of file