rename project in pubspect. testing streamingview.

This commit is contained in:
Jordan 2024-03-15 08:22:44 -07:00
parent 59daf14ee4
commit 2f80cb3e55
9 changed files with 97 additions and 39 deletions

View File

@ -1,4 +1,4 @@
name: dart_openmvg
name: libdart_openmvg
description: "Dart Bindings for OpenMVG"
version: 0.0.1
homepage:

View File

@ -64,13 +64,15 @@ add_library(${LIBDART_OPENMVG} SHARED
"image.cxx"
)
set(CEREAL_INCLUDE_DIR ${OpenMVG_DIR}/../../../include/openMVG_dependencies/cereal/include/cereal/)
target_include_directories(
${LIBDART_OPENMVG}
PRIVATE
${FFMPEG_INCLUDE_DIRS}
${PNG_INCLUDE_DIRS}
${ARCHIMEDES_INCLUDE_DIRS}
${OpenMVG_DIR}/../../../include/openMVG_dependencies/cereal/include/cereal/
${CEREAL_INCLUDE_DIR}
)
target_link_libraries(
@ -119,6 +121,7 @@ target_include_directories(
PRIVATE
${LIBDART_OPENMVG_INCLUDE_DIRS}
${OpenMVG_INCLUDE_DIRS}/src
${CEREAL_INCLUDE_DIR}
)
set_target_properties(test_image

View File

@ -20,15 +20,44 @@ FILE *make_buffer(const uint8_t *data, const size_t data_len)
return file;
}
int read_buffer(FILE *file, uint8_t **buffer, size_t *length) {
if (file != NULL) {
// Get the file size
fseek(file, 0, SEEK_END);
(*length) = ftell(file);
fseek(file, 0, SEEK_SET);
const Frame *new_frame_from_data(const uint8_t *data, const size_t data_len, int w, int h, int depth)
// Allocate memory
*buffer = (uint8_t *) malloc((*length) * sizeof(char));
if (buffer == NULL) {
printf("Error: Unable to allocate memory.\n");
return 1;
}
// Read file
size_t newLen = fread(*buffer, sizeof(char), *length, file);
if (newLen == 0) {
if (feof(file)) {
printf("Error: End of file reached.\n");
return 2;
}
printf("Error: Reading file.\n");
return 3;
}
return 4;
}
return 5;
}
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);
}
const Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth)
Frame *new_frame_from_handle(FILE *stream, int w, int h, int depth)
{
Frame *f = (Frame *)malloc(sizeof(Frame));
f->stream = stream;

View File

@ -3,6 +3,10 @@
#include <stdint.h>
#include "./base.hpp"
#ifndef __FRAME_H
#define __FRAME_H
typedef struct _Frame
{
FILE *stream;
@ -13,8 +17,12 @@ typedef struct _Frame
FILE *make_buffer(const uint8_t *, const size_t);
_FFI_PLUGIN
const Frame *new_frame_from_handle(FILE *, int, int, int);
int read_buffer(FILE *, uint8_t **, size_t *);
_FFI_PLUGIN
const Frame *new_frame_from_data(const uint8_t *, const size_t, int, int, int);
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);
#endif // __FRAME_H

View File

@ -95,6 +95,7 @@ int Archimedes::images_to_sfm(const Frame **frames, size_t n_frames)
SfM_Data sfmData {};
sfmData.views = Views();
return 0;
}

View File

@ -48,21 +48,6 @@ extern "C" {
#define error_t int
#ifdef __cplusplus
class StreamedView : openMVG::sfm::View {
private:
const Frame *mFrame;
public:
StreamedView(const Frame *);
};
#endif
typedef struct _ImageResult
{

View File

@ -1,15 +1,21 @@
#include "streamingview.hpp"
#include <string.h>
template<class Archive>
void libdart_openmvg::StreamingView::load(cereal::BinaryOutputArchive &ar) const {
int i = 0;
while (i = fgetc(mFrame->stream) != EOF) {
ar(i);
void libdart_openmvg::StreamingView::load(cereal::BinaryInputArchive &ar) const {
uint8_t *data = NULL;
const size_t dLen1 = (mFrame->w * mFrame->h * mFrame->depth * sizeof(uint8_t));
ar.loadBinary(data, sizeof(uint8_t) * dLen1);
const size_t dlen2 = sizeof(data) * sizeof(uint8_t);
mFrame->stream = make_buffer(data, dlen2);
rewind(mFrame->stream);
}
void libdart_openmvg::StreamingView::save(cereal::BinaryOutputArchive &ar) const {
uint8_t * data = NULL;
size_t data_len = 0;
int ret = 0;
if(ret = read_buffer(mFrame->stream, &data, &data_len)) {
std::cerr << "ERROR: " << ret << std::endl;
}
}
template<class Archive>
void libdart_openmvg::StreamingView::save(cereal::BinaryInputArchive &ar) const {
// int i = 0;
// todo
ar.saveBinary(data, data_len);
}

View File

@ -12,14 +12,12 @@ namespace libdart_openmvg
{
private:
const Frame *mFrame;
Frame *mFrame;
public:
StreamingView(const Frame *frame) : mFrame(frame), View () {}
template <class Archive>
void save(cereal::BinaryInputArchive &) const;
template <class Archive>
void load(cereal::BinaryOutputArchive &) const;
StreamingView(Frame *frame) : mFrame(frame), View () {}
void save(cereal::BinaryOutputArchive &) const;
void load(cereal::BinaryInputArchive &) const;
};
}

View File

@ -1,6 +1,11 @@
#include <archives/binary.hpp>
#include <CUnit/Basic.h>
#include "../image.h"
#include "../streamingview.hpp"
#include <cwalk.h>
#ifdef __cplusplus
#include <iostream>
#endif // __cplusplus
#define STRLEN 2048
@ -100,6 +105,28 @@ void test_archimedes_get_data(void)
CU_ASSERT_TRUE(result->data_len > 0);
}
void test_archimedes_streamed_view(void) {
imageHandle = fopen(frame1Path, "rw+");
Frame *f = new_frame_from_handle(
imageHandle,
768,
768,
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;
cereal::BinaryInputArchive inArchive(inStream);
cereal::BinaryOutputArchive outArchive(outStream);
// view.save(outArchive);
view.load(inArchive);
}
int main() {
CU_pSuite pSuite = NULL;
@ -117,7 +144,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, "data can be retrieved from frame", test_archimedes_get_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();