Opencv tutorial, VideoCapture playback, frame skip

Follow

My favourite

  • Opencv tutorial people detection
  • Head people cascade download
  • Opencv tutorial optical flow
  • Opencv Video stabilization
  • Opencv car dataset download
  • Opencv tutorial Transparent mask
  • Opencv videowriter
  • Opencv FFMPEG
  • Opencv Canny edge and hough lines
  • Opencv VideoCapture playback, fast frame replay

    Opencv C++ tutorial how to playback video frames and video loaded into memory, Fast video replay by slider. Simple described and working tutorial working in Visual studio 2015 with simple installation by Nugets Here or also with classical one.. 

    opencv videocapture playback

    This is not something special, but useful. Few days earlier, I post in memory video access by vector<Mat>. Great, fast approach but the short video fills RAM memory and crash the program even if you have 8 GB available. Maybe It is to danger and i decided to cancel this article. 

    In this example, i want to access GOPRO HD faster and skipped frames video and in memory is pure fantasy over minute video length. 

    Opencv VideoCapture property CV_CAP_PROP_POS_FRAMES


    I don't add extra comments. The code is pretty simple. I only highlights the important parts by RED font color. 

    This is only important part. By the slider_position value set the CV_CAP_PROP_POS_FRAMES value.
    cap.set(CV_CAP_PROP_POS_FRAMES, slider_position);

    The retrieved frame is the one on the slider position.
    cap.retrieve

    That's it.



    opencv videocapture playback fast frame access




    #include "opencv2\highgui.hpp"
    #include "opencv2\imgproc.hpp"
    #include <vector>
    #include <stdio.h>
    #include <Windows.h>
    #include <iostream>


    using namespace cv;
    using namespace std;


    int frame_max = 100;
    int slider_position;
    int slider_val;


    void on_trackbar(int, void*)
    {
    // I lost something? no
    }

    int main(int argc, const char** argv)
    {


    VideoCapture cap("GO.MP4");
    int counter = 10;
    frame_max = cap.get(CAP_PROP_FRAME_COUNT);


    for (;;)
    {

    bool Is = cap.grab();
    if (Is == false) {

    cout << "Video Capture Fail" << endl;
    break;
    }
    else {

    cap.set(CV_CAP_PROP_POS_FRAMES, slider_position);

    Mat img;
    Mat original;
    cap.retrieve(img, CV_CAP_OPENNI_BGR_IMAGE);

    img.copyTo(original);
    resize(img, img, Size(640, 480));

    namedWindow("prew", WINDOW_AUTOSIZE);
    imshow("prew", img);
    createTrackbar("rew", "prew", &slider_position, frame_max, on_trackbar);
    on_trackbar(slider_position, 0);

    int key1 = waitKey(20);

    }
    }
    }

    No comments:

    Post a Comment

    ad

    Follow by Email

    Powered by Blogger.