title: Split image frame into 8*8 for DCT using OpenCV and C++
body: <p>I need to pass fullPath into method FrameTo8by8(). In FrameTo8by8(), it will split the every frame into 8*8 blocks. (E.g. My video resolution is 1280*720 = 921,600. After that 921,600 / 64(8*8) = 14,400. So there will be total of 14,400 blocks of 8*8).</p>
  
  <p><strong>VideoSplitEngine.h</strong></p>
  
  <pre><code>class VideoSplitEngine
  {
      public:
  
      static VideoCapture capture;
      static Mat fullimage;
  
      //Default constructor
      VideoSplitEngine();
  
      //Declare a virtual destructor:
      virtual ~VideoSplitEngine();
  
      //Method
      Mat Start();    
      void FrameTo8by8() const; 
      string GetFilePath() const;
  
      private:
  };
  </code></pre>
  
  <p><strong>VideoSplitEngine.cpp</strong></p>
  
  <pre><code>#include "StdAfx.h"
  #include "VideoSplitEngine.h"
  #include "UserInfo.h"
  #include "Common.h"
  
  VideoCapture VideoSplitEngine::capture;
  
  Mat VideoSplitEngine::fullimage;
  
  Mat VideoSplitEngine::Start()
  
  string VideoSplitEngine::GetFilePath() const
  {
    cout&lt;&lt; endl;
    cout &lt;&lt; "Place video in Desktop and enter file name (e.g. vid.avi):" &lt;&lt; endl;
    cout&lt;&lt;"----------------------------------------------------------"&lt;&lt; endl;
  
    //Get user desktop file path
    string fullPath;
    string userProfile = getenv("userprofile");   //GetEnvironmentVariable() is to get current userprofile (e.g."C:\Users\L30807")
    string path = userProfile + "\\Desktop\\";
    string vid;
  
    getline (cin, vid);       //Prompt to input file name
    fullPath = path + vid;
    capture.open(fullPath); //Read video
    cout&lt;&lt; endl;
  
    return fullPath;
  }
  
  Mat VideoSplitEngine::Start()
  {
    while(1)
    {
      bool bSuccess = capture.read(fullimage); // read a new frame from video
  
      if (!bSuccess) //if not success, break loop
      {
          cout &lt;&lt; "End of video" &lt;&lt; endl;
          destroyWindow("Original Video");
          break;
      }
  
      imshow("Original Video", fullimage); //show the frame in "Original Video" window
  
      if(waitKey(30) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
      {
          cout &lt;&lt; "esc key is pressed by user" &lt;&lt; endl; 
          break; 
      }
    }
  
  return fullimage;
  }
  
  void VideoSplitEngine::FrameTo8by8() const
  {
      namedWindow("Original", CV_WINDOW_AUTOSIZE); 
      imshow("Original", fullimage); 
  
      int width = fullimage.size().width; 
      int height = fullimage.size().width; 
  
      cout &lt;&lt; "Original image Width x Height is " &lt;&lt; width &lt;&lt; "x" &lt;&lt; height &lt;&lt; endl; 
  
      // Leave original alone, work on a copy 
      Mat dctImage = fullimage.clone();
  
      // Step through the copied image with rectangles size 8x8 
      // For each block, split into planes, do dct, and merge back 
      // into the block. (This will affect the image from 
      // which the block is selected each time.) 
  
      for (int i = 0; i &lt; height; i += 8) 
      { 
          for (int j = 0; j &lt; width; j+= 8) 
          {
              Mat block = dctImage(Rect(i, j, 8, 8));
              vector&lt;Mat&gt; planes; 
              split(block, planes);
              vector&lt;Mat&gt; outplanes(planes.size());
  
              for (size_t k = 0; k &lt; planes.size(); k++)
              {
                  planes[k].convertTo(planes[k], CV_32FC1); 
                  dct(planes[k], outplanes[k]);
                  outplanes[k].convertTo(outplanes[k], CV_8UC1);
              }
                  merge(outplanes, block); 
          } 
      } 
  
      namedWindow("dctBlockImage"); 
      imshow("dctBlockImage", dctImage);
  
      waitKey(30); 
  }
  </code></pre>
  
  <p>I need help on how to split it or is there other methods to do it?</p>