#include #include #include // std::shared_ptr #include // std::runtime_error #include // all opencv header #include #include "hdrplus/bayer_image.h" #include "hdrplus/utility.h" // box_filter_2x2 namespace hdrplus { bayer_image::bayer_image( const std::string& bayer_image_path ) { libraw_processor = std::make_shared(); // 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 = int( libraw_processor->imgdata.rawdata.sizes.raw_width ); height = int( libraw_processor->imgdata.rawdata.sizes.raw_height ); white_level = int( libraw_processor->imgdata.rawdata.color.maximum ); #ifndef NDEBUG printf("%s::%s read bayer image %s with width %zu height %zu\n", \ __FILE__, __func__, bayer_image_path.c_str(), width, height ); fflush( stdout ); #endif // Create CV mat // https://answers.opencv.org/question/105972/de-bayering-a-cr2-image/ // https://www.libraw.org/node/2141 raw_image = cv::Mat( width, height, CV_16U, libraw_processor->imgdata.rawdata.raw_image ).clone(); // 2x2 box filter grayscale_image = box_filter_2x2( raw_image ); } }