Skip to content

Instantly share code, notes, and snippets.

@anujonthemove
Created August 14, 2016 09:22
Show Gist options
  • Save anujonthemove/0d82851819e9f4f2f9a1707ca6036f11 to your computer and use it in GitHub Desktop.
Save anujonthemove/0d82851819e9f4f2f9a1707ca6036f11 to your computer and use it in GitHub Desktop.
Temporal blurring over successive frames.
// OpenCV imports
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/highgui/highgui.hpp>
// C++ imports
#include <iostream>
// namespaces
using namespace std;
using namespace cv;
/*
* This simple code illustrates temporal blurring by averaging N = 3 successive frames
* Concept taken from the paper: Robust lane detection and tracking with Ransac and Kalman filter
* Link: https://www.researchgate.net/publication/221126736_Robust_lane_detection_and_tracking_with_Ransac_and_Kalman_filter
*/
int main( int argc, char **argv ) {
if(argc < 2) {
cerr << "Usage: " << argv[0] << " /path/to/video/" << endl;
cout << "Exiting...." << endl;
return -1;
}
// get file name from the command line
string filename = argv[1];
// capture object
VideoCapture capture(filename);
// mat container to receive images
Mat frame;
// check if capture was successful
if( !capture.isOpened()) throw "Error reading video";
int count = 0;
// vector<int> v;
vector<Mat> images;
while(true) {
// original frame
capture >> frame;
// resized frame - 320x240 / 640x480
resize(frame, frame,Size(640,480), 0,0, INTER_NEAREST);
// deep copy
Mat src = frame.clone();
// grayscale conversion
Mat src_gray;
cvtColor( src, src_gray, CV_BGR2GRAY );
Mat meanmat;
Mat avgImage = Mat::zeros(src.rows, src.cols, CV_8UC1);
if(images.size() > 3) {
images.erase(images.begin()+0);
for(int i = 0; i < images.size(); i++) {
avgImage += images[i];
meanmat = avgImage/3;
imshow("meanmat", meanmat);
}
}
else {
images.push_back(src_gray);
}
/* conceptually implemented*/
// if(v.size() > 2) v.erase(v.begin()+0);
// v.push_back(count++);
// cout << "vector size: " << v.size() << endl;
// for(int i = 0; i < v.size(); i++) {
// cout << v[i] << endl;
// }
waitKey(1);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment