can successfully compile openmvg into project.

This commit is contained in:
Jordan
2024-03-11 07:36:09 -07:00
parent e3f9413566
commit b3cd0316b7
20 changed files with 5049 additions and 158 deletions

View File

@ -2,30 +2,83 @@
# 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)
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
include(ExternalProject)
function(dump_cmake_variables)
get_cmake_property(_variableNames VARIABLES)
list (SORT _variableNames)
foreach (_variableName ${_variableNames})
if (ARGV0)
unset(MATCHED)
project(archimedes_mobile_lib_library VERSION 0.0.1 LANGUAGES C)
#case sensitive match
# string(REGEX MATCH ${ARGV0} MATCHED ${_variableName})
#
#case insenstitive match
string( TOLOWER "${ARGV0}" ARGV0_lower )
string( TOLOWER "${_variableName}" _variableName_lower )
string(REGEX MATCH ${ARGV0_lower} MATCHED ${_variableName_lower})
ExternalProject_Add(openMVG
GIT_REPOSITORY "git@github.com:src-r-r/openMVG.git"
GIT_TAG "develop"
SOURCE_SUBDIR "src"
CMAKE_ARGS "-DCMAKE_INSTALL_PREFIX=${CMAKE_BUILD_DIR} -DCMAKE_INCLUDE-PATH=${CMAKE_BUILD_DIR}/include"
PREFIX ${CMAKE_BUILD_DIR}
INSTALL_DIR ${CMAKE_BUILD_DIR}
if (NOT MATCHED)
continue()
endif()
endif()
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
endfunction()
project(archimedes_mobile_lib_library VERSION 0.0.1 LANGUAGES CXX)
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(PNG_SHARED ON CACHE BOOL "" FORCE)
set(PNG_STATIC OFF CACHE BOOL "" FORCE)
set(PNG_EXECUTABLES OFF CACHE BOOL "" FORCE) # we only want lib
set(PNG_TESTS OFF CACHE BOOL "" FORCE) # we only want lib
set(SKIP_INSTALL_ALL OFF CACHE BOOL "" FORCE) # we only want lib
# find_package(PNG
# REQUIRED
# HINTS "../"
# )
add_definitions(${PNG_DEFINITIONS})
add_library(archimedes_mobile_lib SHARED
"archimedes_mobile_lib.c"
"image.cxx"
)
target_link_libraries(archimedes_mobile_lib ${OPENMVG_LIBRARIES})
include_directories(${OPENMVG_INCLUDE_DIRS})
set_target_properties(archimedes_mobile_lib PROPERTIES
PUBLIC_HEADER archimedes_mobile_lib.h
dump_cmake_variables("^png")
message("LIBRARIES:" ${OpenMVG_LIBRARIES})
target_link_libraries(
archimedes_mobile_lib
${CMAKE_CURRENT_SOURCE_DIR}/../../libpng/_install/lib/libpng16.so
${CMAKE_CURRENT_SOURCE_DIR}/../../openMVG/build/_install/lib/libopenMVG_image.a
${OPENMVG_LIBRARIES}
)
include_directories(
${FFMPEG_INCLUDE_DIRS}
${OPENMVG_INCLUDE_DIRS}
${ARCHIMEDES_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
)
set_target_properties(archimedes_mobile_lib
PROPERTIES
PUBLIC_HEADER image.h
OUTPUT_NAME "archimedes_mobile_lib"
)
target_link_options(archimedes_mobile_lib PRIVATE "-Wl,-Bstatic")
target_link_options(archimedes_mobile_lib PRIVATE "-Wl,-Bdynamic")
target_compile_definitions(archimedes_mobile_lib PUBLIC DART_SHARED_LIB)
target_compile_definitions(archimedes_mobile_lib PUBLIC DART_SHARED_LIB)

71
src/image.cxx Normal file
View File

@ -0,0 +1,71 @@
#include "./image.h"
#ifdef __cplusplus
#include <openMVG/image/image_io.hpp>
#include <openMVG/image/image_concat.hpp>
#endif // __ cplusplus
const Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth)
{
Frame *f = (Frame *)malloc(sizeof(Frame));
f->stream = stream;
f->w = w;
f->h = h;
f->depth = depth;
return f;
}
FILE *make_buffer(const uint8_t *data, const size_t data_len)
{
FILE *file = fmemopen((char *)data, data_len, "r+");
if (file == NULL)
{
perror("Error opening file");
return NULL;
}
// Seek to the beginning of the file
rewind(file);
// Write the data to the file
fwrite(data, sizeof(uint8_t), data_len, file);
return file;
}
#ifdef __cplusplus
extern "C" __attribute__((visibility("default"))) __attribute((used))
#else
__attribute__((visibility("default"))) __attribute((used))
#endif // __cplusplus
const Frame *
new_frame_from_data(const uint8_t *data, const size_t data_len, int w, int h, int depth)
{
FILE *buf = make_buffer(data, data_len);
return new_frame_from_handle(buf, w, h, depth);
}
#ifdef __cplusplus
extern "C" int Archimedes::get_image_data(const Frame *frame, unsigned char *data)
{
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;
}
#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)
{
return Archimedes::get_image_data(frame, data);
}

54
src/image.h Normal file
View File

@ -0,0 +1,54 @@
#ifdef __cplusplus
#include <openMVG/image/image_io.hpp>
#include <openMVG/image/image_concat.hpp>
#include <openMVG/vector_graphics/svgDrawer.hpp>
#include <openMVG/features/feature.hpp>
#include <forward_list>
#include <openMVG/sfm/sfm.hpp>
#include <openMVG/features/mser/mser.hpp>
#endif // __cplusplus
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <png.h>
extern "C" auto png_sig_cm = png_sig_cmp;
typedef struct _Frame
{
FILE *stream;
int w;
int h;
int depth;
} Frame;
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
const Frame *
new_frame_from_data(const uint8_t *, const size_t, int, int, int);
#ifdef __cplusplus
typedef openMVG::image::Image<openMVG::image::RGBColor> RgbImage;
typedef std::vector<openMVG::features::AffinePointFeature> FeatureVector;
typedef openMVG::image::Image<unsigned char> UImage;
typedef std::vector<openMVG::features::MSER::MSERRegion> RegionVector;
typedef openMVG::sfm::SfM_Data Sfm_Data;
extern "C" namespace Archimedes
{
int get_image_data(const Frame *, unsigned char *data);
}
#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 *);