0
我想讓視頻在循環播放。我想檢查它是否到達視頻的結尾,以便我可以重新實例化它;我如何讓它循環?如何判斷視頻是否在opencv中結束?
VideoStream::VideoStream(Filters* f, char* fileNam):
filter(f),
fileName(fileNam){
TestON = true;
cap = new VideoCapture(fileNam);
};
void VideoStream::readFrame(){
if(!cap->isOpened()) // check if we succeeded
cerr<<"cannot open video file";
if(cap->get(CV_CAP_PROP_POS_AVI_RATIO==1)){
cap = new VideoCapture(fileName);
}
Mat image;
cap->read(image);
if(!image.empty())
imshow("haha", image);
waitKey(1);
image.release();
};
您使用'new'泄漏內存。考慮靜態分配一個'VideoCapture'實例。 – Aurelius