87 lines
2.1 KiB
C++
87 lines
2.1 KiB
C++
#include "./image.h"
|
|
|
|
#ifdef __cplusplus
|
|
#include <cereal/archives/binary.hpp>
|
|
#include <openMVG/image/image_io.hpp>
|
|
#include <openMVG/image/image_concat.hpp>
|
|
#include <openMVG/sfm/sfm_view.hpp>
|
|
#include <openMVG/sfm/sfm_view_io.hpp>
|
|
#include <Eigen/src/Core/util/Constants.h>
|
|
#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);
|
|
}
|
|
|
|
|
|
std::vector<u_char> DartOpenmvg::get_image_data_as_vector(const Frame *frame)
|
|
{
|
|
rewind(frame->stream);
|
|
std::vector<unsigned char> imageData;
|
|
if (!openMVG::image::ReadPngStream(frame->stream, &imageData, (int *)&(frame->w), (int *)&(frame->h), (int *)&(frame->depth)))
|
|
{
|
|
throw std::runtime_error("Could not read stream");
|
|
}
|
|
return imageData;
|
|
}
|
|
|
|
#ifdef __cplusplus
|
|
|
|
ImageResult *DartOpenmvg::get_image_data(const Frame *frame)
|
|
{
|
|
try {
|
|
const std::vector<u_char> imageData = get_image_data_as_vector(frame);
|
|
printf("Read %lu bytes.\n", imageData.size());
|
|
const unsigned char *data = imageData.data();
|
|
return image_result_new(data, imageData.size());
|
|
} catch (const std::runtime_error& e) {
|
|
std::cerr << e.what() << std::endl;
|
|
return image_result_new_error(1);
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
_FFI_PLUGIN
|
|
ImageResult *archimedes_get_image_data(const Frame *frame)
|
|
{
|
|
return DartOpenmvg::get_image_data(frame);
|
|
}
|
|
|
|
int DartOpenmvg::images_to_sfm(const Frame **frames, size_t n_frames)
|
|
{
|
|
// TODO
|
|
|
|
|
|
return 0;
|
|
}
|
|
|
|
_FFI_PLUGIN
|
|
int archimedes_images_to_sfm(const Frame **frames, size_t n_frames)
|
|
{
|
|
return DartOpenmvg::images_to_sfm(frames, n_frames);
|
|
} |