0

嗨,我在 OpenCV 中编写了以下代码。基本上它从文件中读取视频。现在,我想创建一个函数来调整视频大小,但我不确定如何从主函数调用“VideoCapture”类。我已经编写了一个示例函数来查看它是否会读取任何内容,但它可以很好地编译显示来自主函数的内容,但没有来自新创建的函数。有什么帮助吗?PS我不是很有经验,请耐心等待LOL。

     using namespace cv;
     using namespace std;

     void resize_video(VideoCapture capture);

     int main(int argc, char** argv)
     {
        VideoCapture capture; //the C++ API class to capture the video from file

        if(argc == 2)
         capture.open(argv[1]);
        else
         capture.open(0);

        if(!capture.isOpened())
        {
           cout << "Cannot open video file " << endl;
           return -1;
        }

        Mat frame;
        namedWindow("display", CV_WINDOW_AUTOSIZE);
        cout << "Get the video dimensions " << endl;
        int fps = capture.get((int)CV_CAP_PROP_FPS);
        int height = capture.get((int)CV_CAP_PROP_FRAME_HEIGHT);
        int width = capture.get((int)CV_CAP_PROP_FRAME_WIDTH);
        int noF = capture.get((int)CV_CAP_PROP_FRAME_COUNT);
        CvSize size = cvSize(width , height);

        cout << "Dimensions: " << width << height << endl;
        cout << "Number of frames: " << noF << endl;
        cout << "Frames per second: " << fps << endl;


        while(true)
        {
          capture >> frame;
          if(frame.empty())
            break;
          imshow("display", frame);
          if (waitKey(30)== 'i')
            break;
        }
       //resize_video();
  }

  void resize_video(VideoCapture capture)
  {
     cout << "Begin resizing video " << endl;

    //return 0;
  }
4

1 回答 1

0

你想在while循环中调用你的函数,而不是在它之后(为时已晚,程序结束)

所以,它可能看起来像这样:

void resize_video( Mat & image )
{
   //
   // do  your processing
   //
   cout << "Begin resizing video " << endl;
}

并称之为:

while(true)
    {
      capture >> frame;
      if(frame.empty())
        break;

      resize_video(frame);

      imshow("display", frame);
      if (waitKey(30)== 'i')
        break;
    }
于 2013-03-04T14:23:32.283 回答