opencv 读取任意帧

#include
#include
#include
using namespace std;
using namespace cv;
Mat getFrame(string avipath, int id)
{
	Mat frame;
	VideoCapture capture(avipath);
	capture.set(CV_CAP_PROP_POS_FRAMES, id);
	if (!capture.grab())
	{
		cout << "grab in opencv failed!" << endl;
		return frame;
	}
	capture >> frame;
	return frame;
}
int main()
{
	Mat mou;
	mou = getFrame("C:/Users/Administrator/Desktop/1.mp4",23000);
	imshow("sdfg",mou);
	waitKey();
}

你可能感兴趣的:(OPENCV)