OpenCV - How to push back Mat in a queue?

僤鯓⒐⒋嵵緔 提交于 2021-01-28 04:55:36

问题


I am trying to put the frames of a video in a deque. This code does not work. Because the back and front of the queue are both the same as the current frame.

deque<Mat> frameSeq;
int main() {
    Mat frame;
    VideoCapture video("path to video");
    int key = 0;
    while (key != 'q') {
        video >> frame;

        frameSeq.push_back(frame);

        imshow("front", frameSeq.front());
        imshow("back", frameSeq.back());

        key = cvWaitKey(1);
    }
    return 0;
}

But when I resize the frame:

deque<Mat> frameSeq;
int main() {
    Mat frame;
    VideoCapture video("path to video");
    int key = 0;
    while (key != 'q') {
        video >> frame;

        cv::resize(frame, frame, cv::Size(), 1.0 / 2, 1.0 / 2);
        frameSeq.push_back(frame);

        imshow("front", frameSeq.front());
        imshow("back", frameSeq.back());

        key = cvWaitKey(1);
    }
    return 0;
}

It works well. Now frameSeq.back() is the current frame and frameSeq.front() is the initial frame.

How can I make the queue work without having to resize the frame?

来源:https://stackoverflow.com/questions/60609562/opencv-how-to-push-back-mat-in-a-queue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!