cmske support for libraw
parent
2914357f97
commit
8cb9bc8b59
@ -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,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
|
||||
|
@ -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…
Reference in New Issue