我尝试使用某些fps(例如30 fps)的opencv控制qt小部件中的视频播放。
有一个问题是我无法控制两个相邻帧之间的播放间隔。由于项目非常复杂,我只是展示一些代码来描述问题:
while(buffer.get(frame))
{
currentTime = cvGetTickCount();
waitTime = 1000/fps - (currentTime - lastTime)/msUnit;
// I hope the thread waiting for 'waitTime' here.
// I have tried to use QTimer to to control the interval, but it's not
// accurate at the ms level. Therefore, I tried to use
// 'QSemaphore.tryAcquire(1, waitTime )', since I have set the
// resource to be 0, so 'tryAcquire()' always fails and waited for
// expected time. Most of time it worked good, but sometime it didn't,
// awaken in later time.
lastTime= cvGetTickCount();
emit NextFrame(frame);
}
换句话说,我希望控制毫秒级的时间间隔。在qt或opencv或其他方面有什么办法吗?
提前致谢!