rename project. lean it up. validate image stream test works.

This commit is contained in:
Jordan
2024-03-12 11:53:16 -07:00
parent 330c72acbb
commit 5d05c42411
89 changed files with 376 additions and 2456 deletions
+50 -31
View File
@@ -2,7 +2,8 @@
# installed. You should not increase this version, as doing so will cause
# the plugin to fail to compile for some customers of the plugin.
cmake_minimum_required(VERSION 3.10)
project(archimedes_mobile_lib_library VERSION 0.0.1 LANGUAGES CXX)
set(LIBDART_OPENMVG libdart_openmvg)
project(libdart_openmvg VERSION 0.0.1 LANGUAGES CXX)
enable_language(CXX)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
@@ -31,19 +32,24 @@ function(dump_cmake_variables)
endfunction()
set (OPENMVG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/src)
set (FFMPEG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/../../ffmpeg_install/include)
set (ARCHIMEDES_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR})
find_package(
OpenMVG
REQUIRED
)
set (LIBDART_OPENMVG_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/src)
find_package(JPEG REQUIRED)
find_package(TIFF REQUIRED)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/extlib/cwalk)
# OPENMVG
find_package(OpenMVG
REQUIRED
PATHS "../../openMVG/build/_install"
)
dump_cmake_variables("^OPENMVG")
include_directories(${OpenMVG_INCLUDE_DIRS})
set(PNG_SHARED ON CACHE BOOL "" FORCE)
set(PNG_STATIC OFF CACHE BOOL "" FORCE)
set(PNG_EXECUTABLES OFF CACHE BOOL "" FORCE) # we only want lib
@@ -52,40 +58,43 @@ set(SKIP_INSTALL_ALL OFF CACHE BOOL "" FORCE) # we only want lib
add_definitions(${PNG_DEFINITIONS})
add_library(archimedes_mobile_lib SHARED
add_library(${LIBDART_OPENMVG} SHARED
"image.cxx"
)
target_include_directories(
${LIBDART_OPENMVG}
PRIVATE
${FFMPEG_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
${ARCHIMEDES_INCLUDE_DIRS}
${OPENMVG_INCLUDE_DIRS}/src
)
# dump_cmake_variables("")
message("LIBRARIES:" ${OpenMVG_LIBRARIES})
# message("LIBRARIES:" ${OpenMVG_LIBRARIES})
target_link_libraries(
archimedes_mobile_lib
${LIBDART_OPENMVG}
cwalk
jpeg
tiff
${CMAKE_CURRENT_SOURCE_DIR}/../../libpng/_install/lib/libpng16.so
${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/build/_install/lib/libopenMVG_image.a
${OPENMVG_LIBRARIES}
png
OpenMVG::openMVG_image
OpenMVG::openMVG_numeric
OpenMVG::openMVG_features
OpenMVG::openMVG_sfm
OpenMVG::openMVG_exif
)
include_directories(
${FFMPEG_INCLUDE_DIRS}
${OPENMVG_INCLUDE_DIRS}
${ARCHIMEDES_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
)
set_target_properties(archimedes_mobile_lib
set_target_properties(${LIBDART_OPENMVG}
PROPERTIES
PUBLIC_HEADER image.h
OUTPUT_NAME "archimedes_mobile_lib"
OUTPUT_NAME ${LIBDART_OPENMVG}
)
target_link_options(archimedes_mobile_lib PRIVATE "-Wl,-Bstatic")
target_link_options(archimedes_mobile_lib PRIVATE "-Wl,-Bdynamic")
target_link_options(${LIBDART_OPENMVG} PRIVATE "-Wl,-Bstatic")
target_link_options(${LIBDART_OPENMVG} PRIVATE "-Wl,-Bdynamic")
add_executable(
test_image
@@ -96,11 +105,21 @@ target_link_libraries(
test_image
cunit
cwalk
archimedes_mobile_lib
${CMAKE_CURRENT_SOURCE_DIR}/../../libpng/_install/lib/libpng16.so
${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/build/_install/lib/libopenMVG_image.a
${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/build/_install/lib/libopenMVG_features.a
${OPENMVG_LIBRARIES}
${LIBDART_OPENMVG}
png
OpenMVG::openMVG_image
OpenMVG::openMVG_numeric
OpenMVG::openMVG_features
OpenMVG::openMVG_sfm
OpenMVG::openMVG_features
OpenMVG::openMVG_exif
)
target_include_directories(
test_image
PRIVATE
${LIBDART_OPENMVG_INCLUDE_DIRS}
${OpenMVG_INCLUDE_DIRS}/src
)
set_target_properties(test_image
@@ -111,6 +130,6 @@ LINKER_LANGUAGE CXX
add_test (
NAME test_image
COMMAND test_image
)
)
target_compile_definitions(archimedes_mobile_lib PUBLIC DART_SHARED_LIB)
target_compile_definitions(${LIBDART_OPENMVG} PUBLIC DART_SHARED_LIB)
-23
View File
@@ -1,23 +0,0 @@
#include "archimedes_mobile_lib.h"
// A very short-lived native function.
//
// For very short-lived functions, it is fine to call them on the main isolate.
// They will block the Dart execution while running the native function, so
// only do this for native functions which are guaranteed to be short-lived.
FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b) { return a + b; }
// A longer-lived native function, which occupies the thread calling it.
//
// Do not call these kind of native functions in the main isolate. They will
// block Dart execution. This will cause dropped frames in Flutter applications.
// Instead, call these native functions on a separate isolate.
FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b) {
// Simulate work.
#if _WIN32
Sleep(5000);
#else
usleep(5000 * 1000);
#endif
return a + b;
}
-30
View File
@@ -1,30 +0,0 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#if _WIN32
#include <windows.h>
#else
#include <pthread.h>
#include <unistd.h>
#endif
#if _WIN32
#define FFI_PLUGIN_EXPORT __declspec(dllexport)
#else
#define FFI_PLUGIN_EXPORT
#endif
// A very short-lived native function.
//
// For very short-lived functions, it is fine to call them on the main isolate.
// They will block the Dart execution while running the native function, so
// only do this for native functions which are guaranteed to be short-lived.
FFI_PLUGIN_EXPORT intptr_t sum(intptr_t a, intptr_t b);
// A longer lived native function, which occupies the thread calling it.
//
// Do not call these kind of native functions in the main isolate. They will
// block Dart execution. This will cause dropped frames in Flutter applications.
// Instead, call these native functions on a separate isolate.
FFI_PLUGIN_EXPORT intptr_t sum_long_running(intptr_t a, intptr_t b);
Submodule src/extlib/openMVG added at aff37dd005
+53 -19
View File
@@ -5,6 +5,31 @@
#include <openMVG/image/image_concat.hpp>
#endif // __ cplusplus
_FFI_PLUGIN
ImageResult *image_result_new(const u_char *data, const size_t data_len) {
ImageResult *r = (ImageResult *) malloc(sizeof(ImageResult));
r->data = (u_char *) calloc(sizeof(u_char), data_len);
memcpy(r->data, data, data_len * sizeof(u_char));
r->data_len = data_len;
r->error = 0;
return r;
}
_FFI_PLUGIN
ImageResult *image_result_new_error(const error_t err) {
ImageResult *r = (ImageResult *) malloc(sizeof(ImageResult));
r->data = NULL;
r->data_len = 0;
r->error = err;
return r;
}
_FFI_PLUGIN
void free_image_result(ImageResult *image_result) {
free(image_result->data);
free(image_result);
}
const Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth)
{
Frame *f = (Frame *)malloc(sizeof(Frame));
@@ -17,7 +42,7 @@ const Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth)
FILE *make_buffer(const uint8_t *data, const size_t data_len)
{
FILE *file = fmemopen((void *) data, data_len, "r+");
FILE *file = fmemopen((void *)data, data_len, "r+");
if (file == NULL)
{
@@ -34,11 +59,7 @@ FILE *make_buffer(const uint8_t *data, const size_t data_len)
return file;
}
#ifdef __cplusplus
extern "C" __attribute__((visibility("default"))) __attribute((used))
#else
__attribute__((visibility("default"))) __attribute((used))
#endif // __cplusplus
_FFI_PLUGIN
const Frame *
new_frame_from_data(const uint8_t *data, const size_t data_len, int w, int h, int depth)
{
@@ -48,24 +69,37 @@ new_frame_from_data(const uint8_t *data, const size_t data_len, int w, int h, in
#ifdef __cplusplus
extern "C" int Archimedes::get_image_data(const Frame *frame, unsigned char *data)
extern "C"
ImageResult *Archimedes::get_image_data(const Frame *frame)
{
std::vector<unsigned char> imageData;
openMVG::image::ReadPngStream(frame->stream, &imageData, (int *)&(frame->w), (int *)&(frame->h), (int *)&(frame->depth));
data = (unsigned char *)calloc(imageData.size(), sizeof(imageData[0]));
memcpy(data, imageData.data(), imageData.size() * sizeof(imageData[0]));
return 1;
rewind(frame->stream);
if (!openMVG::image::ReadPngStream(frame->stream, &imageData, (int *)&(frame->w), (int *)&(frame->h), (int *)&(frame->depth))) {
printf("ERROR: Could not read stream!\n");
return image_result_new_error(1);
}
printf("Read %lu bytes.\n", imageData.size());
const unsigned char *data = imageData.data();
return image_result_new(data, imageData.size());
}
#endif
#ifdef __cplusplus
extern "C" __attribute__((visibility("default"))) __attribute((used))
#else
__attribute__((visibility("default"))) __attribute((used))
#endif // __cplusplus
int
archimedes_get_image_data(const Frame *frame, unsigned char *data)
_FFI_PLUGIN
ImageResult *archimedes_get_image_data(const Frame *frame)
{
return Archimedes::get_image_data(frame, data);
return Archimedes::get_image_data(frame);
}
_FFI_PLUGIN
int Archimedes::images_to_sfm(const Frame **frames, size_t n_frames)
{
return 0;
}
_FFI_PLUGIN
int archimedes_images_to_sfm(const Frame **frames, size_t n_frames)
{
return Archimedes::images_to_sfm(frames, n_frames);
}
+50 -18
View File
@@ -6,6 +6,27 @@
#include <forward_list>
#include <openMVG/sfm/sfm.hpp>
#include <openMVG/features/mser/mser.hpp>
#include <openMVG/cameras/Camera_Common.hpp>
#include <openMVG/cameras/Cameras_Common_command_line_helper.hpp>
#include <openMVG/sfm/pipelines/sfm_features_provider.hpp>
#include <openMVG/sfm/pipelines/sfm_matches_provider.hpp>
#include <openMVG/sfm/sfm_data.hpp>
#include <openMVG/sfm/sfm_data_io.hpp>
#include <openMVG/sfm/sfm_report.hpp>
#include <openMVG/sfm/sfm_view.hpp>
#include <openMVG/system/timer.hpp>
#include <openMVG/types.hpp>
// SfM Engines
#include <openMVG/sfm/pipelines/global/GlobalSfM_rotation_averaging.hpp>
#include <openMVG/sfm/pipelines/global/GlobalSfM_translation_averaging.hpp>
#include <openMVG/sfm/pipelines/global/sfm_global_engine_relative_motions.hpp>
#include <openMVG/sfm/pipelines/sequential/sequential_SfM.hpp>
#include <openMVG/sfm/pipelines/sequential/sequential_SfM2.hpp>
#include <openMVG/sfm/pipelines/sequential/SfmSceneInitializerMaxPair.hpp>
#include <openMVG/sfm/pipelines/sequential/SfmSceneInitializerStellar.hpp>
#include <openMVG/sfm/pipelines/stellar/sfm_stellar_engine.hpp>
#endif // __cplusplus
#include <stdio.h>
@@ -13,6 +34,12 @@
#include <stdint.h>
#include <png.h>
#ifdef __cplusplus
# define _FFI_PLUGIN extern "C" __attribute__((visibility("default"))) __attribute__((used))
#else
# define _FFI_PLUGIN __attribute__((visibility("default"))) __attribute__((used))
#endif // __cplusplus
#if defined(__cplusplus)
extern "C" {
@@ -30,17 +57,24 @@ typedef struct _Frame
int depth;
} Frame;
#ifdef __cplusplus
extern "C" __attribute__((visibility("default"))) __attribute((used))
#else
__attribute__((visibility("default"))) __attribute((used))
#endif // __cplusplus
typedef struct _ImageResult
{
u_char *data;
size_t data_len;
error_t error;
} ImageResult;
_FFI_PLUGIN
ImageResult *image_result_new(const u_char *, const size_t data_len);
_FFI_PLUGIN
ImageResult *image_result_new_error(const error_t);
_FFI_PLUGIN
int image_result_free(ImageResult *);
_FFI_PLUGIN
const Frame *new_frame_from_handle(FILE *, int, int, int);
#ifdef __cplusplus
extern "C" __attribute__((visibility("default"))) __attribute((used))
#else
__attribute__((visibility("default"))) __attribute((used))
#endif // __cplusplus
_FFI_PLUGIN
const Frame *
new_frame_from_data(const uint8_t *, const size_t, int, int, int);
@@ -53,14 +87,12 @@ typedef openMVG::sfm::SfM_Data Sfm_Data;
extern "C" namespace Archimedes
{
int get_image_data(const Frame *, unsigned char *data);
ImageResult *get_image_data(const Frame *);
int images_to_sfm(const Frame **, size_t);
}
#endif
#ifdef __cplusplus
extern "C" __attribute__((visibility("default"))) __attribute((used))
#else
__attribute__((visibility("default"))) __attribute((used))
#endif // __cplusplus
int
archimedes_get_image_data(const Frame *, unsigned char *);
_FFI_PLUGIN
ImageResult *archimedes_get_image_data(const Frame *);
_FFI_PLUGIN
int archimedes_images_to_sfm(const Frame **, size_t);
+12 -7
View File
@@ -1,5 +1,5 @@
#include <CUnit/Basic.h>
#include "image.h"
#include "../image.h"
#include <cwalk.h>
#define STRLEN 2048
@@ -39,13 +39,14 @@ size_t read_file(const char *path, uint8_t **contents) {
return file_size;
}
#define HERE __FILE__
int setUp(void)
{
char framesDir[STRLEN];
char *here = __FILE__;
size_t length;
cwk_path_get_dirname(here, &length); // archimedes_mobile_lib/src/tests
cwk_path_join(here, "../../../assets/test/frames", framesDir, 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);
printf("Opening file %s\n", frame1Path);
return 0;
@@ -92,8 +93,11 @@ void test_archimedes_get_data(void)
);
unsigned char *image_data = NULL;
archimedes_get_image_data(f, image_data);
CU_ASSERT_PTR_NOT_NULL(image_data);
size_t image_data_len = 0;
ImageResult *result = archimedes_get_image_data(f);
CU_ASSERT_FALSE(result->error);
CU_ASSERT_PTR_NOT_NULL(result->data);
CU_ASSERT_TRUE(result->data_len > 0);
}
int main() {
@@ -112,7 +116,8 @@ 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, "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)))
{
CU_cleanup_registry();
return CU_get_error();