Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdio>
- #include <ctime>
- #include <libraw/libraw.h>
- #include <opencv2/opencv.hpp>
- #include <pybind11/pybind11.h>
- cv::Mat convert_cr3(std::string filename) {
- int ret; // Variable to consume the error-codes
- clock_t x, y, start; // Variables for the profiler
- LibRaw RawProcessor; // Variable for the raw-data
- x = start = clock();
- // Open file - With error recognition
- printf("Opening file %s\n", filename.c_str());
- if ((ret = RawProcessor.open_file(filename.c_str())) != LIBRAW_SUCCESS) {
- printf("\033[0;31mCannot open_file %s: %s\033[0m\n", filename.c_str(), libraw_strerror(ret));
- exit(EXIT_FAILURE);
- }
- y = clock();
- printf("\033[0;32mElapsed time: %f\033[0m\n\n", double(y-x)/CLOCKS_PER_SEC);
- // Unpack file - With error recognition
- printf("Unpacking image data\n");
- if ((ret = RawProcessor.unpack()) != LIBRAW_SUCCESS) {
- printf("\033[0;31mCannot unpack %s: %s\033[0m\n", filename.c_str(), libraw_strerror(ret));
- exit(EXIT_FAILURE);
- }
- x = clock();
- printf("\033[0;32mElapsed time: %f\033[0m\n\n", double(x-y)/CLOCKS_PER_SEC);
- // Post process file - With error recognition
- printf("Postprocessing of image data\n");
- if ((ret = RawProcessor.dcraw_process()) != LIBRAW_SUCCESS) {
- printf("\033[0;31mCannot do postprocessing on %s: %s\033[0m\n", filename.c_str(), libraw_strerror(ret));
- exit(EXIT_FAILURE);
- }
- y = clock();
- printf("\033[0;32mElapsed time: %f\033[0m\n\n", double(y-x)/CLOCKS_PER_SEC);
- // Make OpenCV-Matrix out of LibRaw-format
- printf("Convert to cv::Mat\n");
- libraw_processed_image_t *img = RawProcessor.dcraw_make_mem_image();
- cv::Mat image = cv::Mat(img->height, img->width, CV_8UC3, img->data);
- cv::cvtColor(image, image, cv::COLOR_BGR2RGB);
- if ( !image.data ) {
- printf("\033[0;31mNo image data!\033[0m\n");
- exit(EXIT_FAILURE);
- }
- x = clock();
- printf("\033[0;32mElapsed time: %f\033[0m\n\n", double(x-y)/CLOCKS_PER_SEC);
- printf("\033[0;32mTotal elapsed time: %f\033[0m\n\n", double(x-start)/CLOCKS_PER_SEC);
- return image;
- }
- PYBIND11_MODULE(cr3_to_python, m) {
- m.doc() = "pybind11-plugin to convert an existing .cr3-image to an RGB-array"; // optional module docstring
- m.def("convert_cr3", &convert_cr3, "Convert a .cr3-image to RGB-array");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement