嗨我有一段时间(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;
}
}
有没有办法跳过前2帧?
答案 0 :(得分: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的版本。
答案 1 :(得分:0)
对于视频文件,您可以使用VideoCapture::set设置下一个要捕获的帧的索引,您可以使用宏CV_CAP_PROP_POS_FRAMES
来设置索引。你应该在进入while()循环之前使用它。