cmske support for libraw

main
Xiao Song 3 years ago
parent 2914357f97
commit 8cb9bc8b59

11
.gitignore vendored

@ -38,4 +38,13 @@ build/
.DS_Store
# Example
bin/demo
bin/demo
# external
external/
# Local dataset
dataset/
# Unit test
tests/test_bayer_image

@ -4,6 +4,8 @@ cmake_minimum_required(VERSION 3.0)
project(hdrplus)
# set c++ standard
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED True)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -march=native -O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -march=native -O3")
@ -21,12 +23,10 @@ else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
endif()
if(NOT APPLE)
# The clang compiler (on osx) is somehow much more strict
# than the compilers on ubuntu and so this does not seem
# possible on OSX just yet.
add_definitions( -Werror )
endif()
# LibRaw-cmake
find_library(LIBRAW_LIBRARY NAMES raw raw_r)
include_directories( BEFORE "/usr/local/include/")
message(STATUS "Found LIBRAW_LIBRARY to be ${LIBRAW_LIBRARY}" )
# dependency opencv
find_package( OpenCV REQUIRED )
@ -34,7 +34,6 @@ include_directories( BEFORE ${OpenCV_INCLUDE_DIRS})
# library
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/include )
add_library(${PROJECT_NAME} SHARED
@ -45,8 +44,9 @@ add_library(${PROJECT_NAME} SHARED
src/hdrplus_pipeline.cpp
src/merge.cpp )
target_link_libraries(${PROJECT_NAME}
${OpenCV_LIBS})
target_link_libraries(${PROJECT_NAME} PRIVATE
${OpenCV_LIBS}
${LIBRAW_LIBRARY} )
# example
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin )
@ -54,3 +54,10 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/bin )
add_executable( demo
bin/demo.cpp )
target_link_libraries( demo ${PROJECT_NAME} )
# unit test
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/tests )
add_executable( test_bayer_image
tests/test_bayer_image.cpp )
target_link_libraries( test_bayer_image ${PROJECT_NAME} )

@ -1,4 +1,17 @@
# Dependency
## Step by step installation
1. [OpenCV](git@github.com:opencv/opencv.git) v4.5.5 build from source through CMake
1. [OpenCV](git@github.com:opencv/opencv.git) v4.5.5 build from source through CMake
2. LibRaw
1. MacOS : `brew install libraw libpng libjpeg`
2. Ubuntu : TODO
3. Run CMake to build
```shell
mkdir build
cd build
cmake ..
make -j 10
```

@ -1,5 +1,7 @@
#pragma once
#include <vector>
#include <utility> // std::pair
#include <opencv2/opencv.hpp> // all opencv header
namespace hdrplus
@ -7,7 +9,11 @@ namespace hdrplus
class align
{
public:
align() = default;
void process( std::vector<cv::Mat>& bayer_images, \
int reference_frame_idx,\
std::vector<std::vector<std::vector<std::pair<int, int>>>>& aligements );
};
} // namespace hdrplus

@ -1,13 +1,22 @@
#pragma once
#include <string>
#include <opencv2/opencv.hpp> // all opencv header
#include <libraw/libraw.h>
namespace hdrplus
{
class bayer_image
{
public:
explicit bayer_image( const std::string& bayer_image_path );
~bayer_image();
LibRaw libraw_processor;
cv::Mat image;
size_t width;
size_t height;
};
} // namespace hdrplus

@ -2,7 +2,7 @@
#include <vector>
#include <opencv2/opencv.hpp> // all opencv header
#include <hdrplus/bayer_image.h>
#include "hdrplus/bayer_image.h"
namespace hdrplus
{

@ -7,7 +7,8 @@ namespace hdrplus
class finish
{
public:
finish() = default;
};
} // namespace hdrplus

@ -1,10 +1,10 @@
#pragma once
#include <opencv2/opencv.hpp> // all opencv header
#include <hdrplus/burst.h>
#include <hdrplus/align.h>
#include <hdrplus/merge.h>
#include <hdrplus/finish.h>
#include "hdrplus/burst.h"
#include "hdrplus/align.h"
#include "hdrplus/merge.h"
#include "hdrplus/finish.h"
namespace hdrplus
{
@ -12,12 +12,13 @@ namespace hdrplus
class hdrplus_pipeline
{
private:
hdrplus::align align;
hdrplus::merge merge;
hdrplus::finish finish;
hdrplus::align align_module;
hdrplus::merge merge_module;
hdrplus::finish finish_module;
public:
void run_pipeline();
hdrplus_pipeline() = default;
};
} // namespace hdrplus

@ -7,7 +7,8 @@ namespace hdrplus
class merge
{
public:
merge() = default;
};
} // namespace hdrplus

@ -1,7 +1,39 @@
#include <string>
#include <opencv2/opencv.hpp> // all opencv header
#include <libraw/libraw.h>
#include "hdrplus/bayer_image.h"
namespace hdrplus
{
} // namespace hdrplus
bayer_image::bayer_image( const std::string& bayer_image_path )
{
// Open RAW image file
int return_code;
if ( ( return_code = libraw_processor.open_file( bayer_image_path.c_str() ) ) != LIBRAW_SUCCESS )
{
libraw_processor.recycle();
throw std::runtime_error("Error opening file " + bayer_image_path + libraw_strerror( return_code ));
}
// Unpack the raw image
if ( ( return_code = libraw_processor.unpack() ) != LIBRAW_SUCCESS )
{
throw std::runtime_error("Error unpack file " + bayer_image_path + libraw_strerror( return_code ));
}
// Get image basic info
width = size_t( libraw_processor.imgdata.rawdata.sizes.raw_width );
height = size_t( libraw_processor.imgdata.rawdata.sizes.raw_height );
// Create CV mat
// https://answers.opencv.org/question/105972/de-bayering-a-cr2-image/
image = cv::Mat( width, height, CV_16U, libraw_processor.imgdata.rawdata.raw_image );
}
bayer_image::~bayer_image()
{
libraw_processor.recycle();
}
}

@ -0,0 +1,15 @@
#include <cstdio>
#include "hdrplus/bayer_image.h"
int main( int argc, char** argv )
{
if ( argc != 2 )
{
printf("Usage: ./test_bayer_image RAW_IMAGE_PATH\n");
exit( -1 );
}
hdrplus::bayer_image raw_bayer_image( argv[1] );
printf("Image of shape h=%d w=%d\n", raw_bayer_image.height, raw_bayer_image.width );
}
Loading…
Cancel
Save