This OpenCV tutorial is a very simple code example of GPU Cuda optical flow in OpenCV written in c++. The configuration of the project, code, and explanation are included for farneback Optical Flow method. Farneback algorithm is a dense method that is used to process all the pixels in the given image. The dense methods are slower but more accurate as all the pixels of the image are processed. In the following example, I am displaying just a few pixes based on a grid. I am not displaying all the pixes. In the opposite to dense method the sparse method like Lucas Kanade using just a selected subset of pixels. They are faster. Both methods have specific applications. Lucas-Kanade is widely used in tracking. The farneback can be used for the analysis of more complex movement in image scene and furder segmentation based on these changes. As dense methods are slightly slower, the GPU and Cuda implementation can lead to great performance improvements to calculate optical flow for all pixels o
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..
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.
#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);
}
}
}
Comments
Post a Comment