【问题标题】:How to skip the first 2 frames?如何跳过前两帧?
【发布时间】:2014-07-28 11:15:31
【问题描述】:

您好,我有一个 while(1) 执行无限循环,有没有办法忽略前 2 帧?

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");
        destroyWindow("dctBlockImage");
        break;
    }

    imshow("Original Video", fullimage);    //show the frame in "Original Video" window

    FrameTo8by8(myinput,3.0);               //Proccess and algorithm

    oVideoWriter.write(dctImage);           //write video to file

    namedWindow("dctBlockImage"); 
    imshow("dctBlockImage", dctImage);      //display watermarked image


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

有没有办法跳过前两帧?

【问题讨论】:

  • capture.read(blah); capture.read(blah); while(true) { ... }?
  • @BoBTFish 感谢您的评论。所以我需要重复 capture.read() 两次并将 while(1) 更改为 while(true)?

标签: c++ opencv video frame


【解决方案1】:

你可以按照评论中提到的做:

capture.read(blah);
capture.read(blah);
while(true) { ... }

或者您可以添加一个计数器并使用它来跳过您想要的帧,如下所示:

std::size_t cntr = 0;
while (true)
{
  // ...
  if (cntr < 2) // here you can add any condition you need
  {
    cntr++; // You can also put this where you need it; I have put it here not to increment if not needed
    continue;
  }
}

但我认为,出于您的目的,最好使用 BoBTFish 的版本。

【讨论】:

    【解决方案2】:

    如果是视频文件,您可以使用VideoCapture::set 设置接下来要捕获的帧的索引,您可以使用宏CV_CAP_PROP_POS_FRAMES 设置索引。您应该在进入 while() 循环之前使用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-09-25
      • 1970-01-01
      • 1970-01-01
      • 2020-03-14
      • 1970-01-01
      • 2019-02-17
      • 2021-05-24
      相关资源
      最近更新 更多