Generating images from .raw files

Ask software engineering and SDK questions for developers working on Mac OS X, Windows or Linux.
  • Author
  • Message
Offline

Nirmal Ramadoss

  • Posts: 2
  • Joined: Thu Mar 30, 2017 3:55 pm

Generating images from .raw files

PostFri Mar 31, 2017 5:01 pm

Dear all,

I have been working with the sdk for quite some time now. I used the executables in Linux/Samples/bin folder to capture video from my Lumix GH4H camera. Now I tried reading the .raw file in c++ and used opencv to pack it and create a jpeg image. However I dont get the desired results. Please find my code below
Code: Select all
    1 #include "opencv2/core/core.hpp"
    2 #include "opencv2/imgproc/imgproc.hpp"
    3 #include "opencv2/calib3d/calib3d.hpp"
    4 #include "opencv2/highgui/highgui.hpp"
    5 #include <fstream>
    6 #include <vector>
    7 #include <iterator>
    8 #include <cstring>
    9 #include <iostream>
   10
   11 cv::Vec3b yuv2rgb(cv::Vec3b yuv) {
   12     float r = yuv[0] + (1.370705 * (yuv[2] - 128));
   13     float g = yuv[0] - (0.698001 * (yuv[2] - 128)) - (0.337633 * (yuv[1] - 128));
   14     float b = yuv[0] + (1.732446 * (yuv[1] - 128));
   15
   16     return cv::Vec3b(int(std::min(255.f, std::max(r, 0.f))),
   17             int(std::min(255.f, std::max(r, 0.f))),
   18             int(std::min(255.f, std::max(r, 0.f))));
   19 }
   20
   21
   22 int main(int argc, char** argv) {
   23     //code for reading the raw file
   24     std::ifstream video_file("vid.raw", std::ios::binary);
   25     if(!video_file.is_open()){
   26         std::cout << "Error Opening file" << std::endl;
   27         return 1;
   28     }
   29     std::vector<char> yuv_byte_values((std::istreambuf_iterator<char>(video_file)),
   30                                 (std::istreambuf_iterator<char>()));
   31     std::vector<float> yuv_values;
   32     for (auto& byte : yuv_byte_values) {
   33         char char_to_float[4];
   34         float yuv;
   35         for (int i=0; i<4; i++)
   36             char_to_float[i] = byte;
   37         std::memcpy(&yuv, &char_to_float, sizeof(yuv));
   38         yuv_values.push_back(yuv);
   39     }
   40     //for (auto& yuv : yuv_values)
   41     //  std::cout << yuv << std::endl;
   42     //std::cout << yuv_values.size() << std::endl;
   43     
   44     cv::Mat rgb_image = cv::Mat(3840, 2160, CV_8UC3);
   45     for (int y=0; y<3840; y++) {
   46         for (int x=0; x<2160; x++) {
   47             cv::Vec3b color;
   48             for (int i=0; i<3; i++){
   49                 color[i] = yuv_values.back();
   50                 yuv_values.pop_back();
   51             }
   52             rgb_image.at<cv::Vec3b>(cv::Point(x,y)) = yuv2rgb(color);
   53         }
   54     }
   55
   56     cv::imwrite("hello.jpg", rgb_image);
   57     
   58     return 0;

I think I am making the mistake when I am reading the raw files. Can someone point me in the right direction for my problem ? Has anyone captured the raw videos from a Camera using Blackmagic products and work on it ? Please help!

Return to Software Developers

Who is online

Users browsing this forum: Ajgor64 and 20 guests