0

我需要将 fullPath 传递给方法 FrameTo8by8()。在 FrameTo8by8() 中,它将每一帧分割成 8*8 块。(例如,我的视频分辨率是 1280*720 = 921,600。之后是 921,600 / 64(8*8) = 14,400。所以总共会有 14,400 个 8*8 的块)。

VideoSplitEngine.h

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:
};

VideoSplitEngine.cpp

#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<< endl;
  cout << "Place video in Desktop and enter file name (e.g. vid.avi):" << endl;
  cout<<"----------------------------------------------------------"<< 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<< 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 << "End of video" << 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 << "esc key is pressed by user" << 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 << "Original image Width x Height is " << width << "x" << height << 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 < height; i += 8) 
    { 
        for (int j = 0; j < width; j+= 8) 
        {
            Mat block = dctImage(Rect(i, j, 8, 8));
            vector<Mat> planes; 
            split(block, planes);
            vector<Mat> outplanes(planes.size());

            for (size_t k = 0; k < 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); 
}

我需要有关如何拆分它的帮助,还是有其他方法可以做到这一点?

4

1 回答 1

2

1.@berak是对的。函数Rect()的原型是Rect(x,y,width,height)。所以'j'指的是'width'应该是'x'。(实际上我没有找到来自http://docs.opencv.org/2.4/index.html的 Rect() 原型,但 C API 中的 cvRect() 是 cvRect(x,y,width,height)。我认为它们的原型可能相同。 )

2. for (int i = 0; i < height; i += 8)andfor (int j = 0; j < width; j+= 8)会导致错误“”Unhandled exception at ...”。通过将它们更改为for (int i = 0; i < (height/8)*8; i += 8)and for (int j = 0; j < (width/8)*8; j+= 8),这个错误将被解决。

3.@user3743939 如果您设法解决了您的问题,请发布您的解决方案以帮助他人。

问候

于 2016-07-28T13:56:19.713 回答