From 8cb9bc8b59d54af09cd6439e84c49833ef65fe2b Mon Sep 17 00:00:00 2001 From: Xiao Song Date: Mon, 11 Apr 2022 22:50:03 -0700 Subject: [PATCH] cmske support for libraw --- .gitignore | 11 ++++++++- CMakeLists.txt | 25 +++++++++++++-------- INSTALL.md | 17 ++++++++++++-- include/hdrplus/align.h | 8 ++++++- include/hdrplus/bayer_image.h | 11 ++++++++- include/hdrplus/burst.h | 2 +- include/hdrplus/finish.h | 3 ++- include/hdrplus/hdrplus_pipeline.h | 15 +++++++------ include/hdrplus/merge.h | 3 ++- src/bayer_image.cpp | 36 ++++++++++++++++++++++++++++-- tests/test_bayer_image.cpp | 15 +++++++++++++ 11 files changed, 120 insertions(+), 26 deletions(-) create mode 100644 tests/test_bayer_image.cpp diff --git a/.gitignore b/.gitignore index f68452a..f1d1082 100644 --- a/.gitignore +++ b/.gitignore @@ -38,4 +38,13 @@ build/ .DS_Store # Example -bin/demo \ No newline at end of file +bin/demo + +# external +external/ + +# Local dataset +dataset/ + +# Unit test +tests/test_bayer_image \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 7efb85b..2981185 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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} ) diff --git a/INSTALL.md b/INSTALL.md index 3bd6650..b9ac912 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -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 \ No newline at end of file +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 + ``` \ No newline at end of file diff --git a/include/hdrplus/align.h b/include/hdrplus/align.h index d2d4c3c..403c6e0 100644 --- a/include/hdrplus/align.h +++ b/include/hdrplus/align.h @@ -1,5 +1,7 @@ #pragma once +#include +#include // std::pair #include // all opencv header namespace hdrplus @@ -7,7 +9,11 @@ namespace hdrplus class align { - + public: + align() = default; + void process( std::vector& bayer_images, \ + int reference_frame_idx,\ + std::vector>>>& aligements ); }; } // namespace hdrplus diff --git a/include/hdrplus/bayer_image.h b/include/hdrplus/bayer_image.h index b4b624a..adfff93 100644 --- a/include/hdrplus/bayer_image.h +++ b/include/hdrplus/bayer_image.h @@ -1,13 +1,22 @@ #pragma once +#include #include // all opencv header +#include 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 diff --git a/include/hdrplus/burst.h b/include/hdrplus/burst.h index 9306ff6..847bcc5 100644 --- a/include/hdrplus/burst.h +++ b/include/hdrplus/burst.h @@ -2,7 +2,7 @@ #include #include // all opencv header -#include +#include "hdrplus/bayer_image.h" namespace hdrplus { diff --git a/include/hdrplus/finish.h b/include/hdrplus/finish.h index 0429fb2..ea310d7 100644 --- a/include/hdrplus/finish.h +++ b/include/hdrplus/finish.h @@ -7,7 +7,8 @@ namespace hdrplus class finish { - + public: + finish() = default; }; } // namespace hdrplus diff --git a/include/hdrplus/hdrplus_pipeline.h b/include/hdrplus/hdrplus_pipeline.h index e319f12..0e992e3 100644 --- a/include/hdrplus/hdrplus_pipeline.h +++ b/include/hdrplus/hdrplus_pipeline.h @@ -1,10 +1,10 @@ #pragma once #include // all opencv header -#include -#include -#include -#include +#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 diff --git a/include/hdrplus/merge.h b/include/hdrplus/merge.h index 1a4bf86..0204c53 100644 --- a/include/hdrplus/merge.h +++ b/include/hdrplus/merge.h @@ -7,7 +7,8 @@ namespace hdrplus class merge { - + public: + merge() = default; }; } // namespace hdrplus diff --git a/src/bayer_image.cpp b/src/bayer_image.cpp index be65eca..5bae59a 100644 --- a/src/bayer_image.cpp +++ b/src/bayer_image.cpp @@ -1,7 +1,39 @@ +#include #include // all opencv header +#include #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(); +} + +} \ No newline at end of file diff --git a/tests/test_bayer_image.cpp b/tests/test_bayer_image.cpp new file mode 100644 index 0000000..22a18dd --- /dev/null +++ b/tests/test_bayer_image.cpp @@ -0,0 +1,15 @@ +#include +#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 ); +} \ No newline at end of file