gpt4 book ai didi

c++ - 如何从视频中选择两帧? opencv C++

转载 作者:太空宇宙 更新时间:2023-11-03 22:05:52 28 4
gpt4 key购买 nike

我想从视频中选择两帧。以下是我的代码,但它只能选择第一帧。有人可以帮我吗?谢谢~

long frameOne = 2130;
long frameTwo = 2160;
long currentFrame = frameOne;
bool stop = false;
while(!stop)
{
if(!capture.read(frame))
{
cout << "Failed to read the video!" << endl;
return -1;
}

// select the first image
if(currentFrame == frameOne)
{
frame1 = frame;
}
if(currentFrame == frameTwo)
{
frame2 = frame;
}

if(currentFrame>frameTwo)
{
stop = true;
}
currentFrame++;
}

最佳答案

这里的问题是

long currentFrame = frameOne;

应该是

long currentFrame = 1;

代码:

long frameOne = 2130;
long frameTwo = 2160;
long currentFrame = 1;
bool stop = false;
while(!stop)
{

if(!capture.read(frame))
{
cout << "Failed to read the video!" << endl;
return -1;
}

// select the first image
if(currentFrame == frameOne)
{
// it needs a deep copy, since frame points to the static capture mem
frame1 = frame.clone();
}
if(currentFrame == frameTwo)
{
frame2 = frame.clone();
}

if(currentFrame>frameTwo)
{
stop = true;
}
currentFrame++;
}

关于c++ - 如何从视频中选择两帧? opencv C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22352101/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com