-
Notifications
You must be signed in to change notification settings - Fork 58
/
Copy pathmain.cpp
executable file
·89 lines (65 loc) · 1.98 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/nonfree/nonfree.hpp"
#include "opencv2/flann/flann.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include <opencv2/opencv.hpp>
#include <iostream>
#include <cmath>
#include <fstream>
#include <time.h>
#include <videostab.h>
using namespace std;
using namespace cv;
// This class redirects cv::Exception to our process so that we can catch it and handle it accordingly.
class cvErrorRedirector {
public:
int cvCustomErrorCallback( )
{
std::cout << "A cv::Exception has been caught. Skipping this frame..." << std::endl;
return 0;
}
cvErrorRedirector() {
cvRedirectError((cv::ErrorCallback)cvCustomErrorCallback(), this);
}
};
const int HORIZONTAL_BORDER_CROP = 30;
int main(int argc, char **argv)
{
cvErrorRedirector redir;
//Create a object of stabilization class
VideoStab stab;
//Initialize the VideoCapture object
VideoCapture cap(0);
Mat frame_2, frame2;
Mat frame_1, frame1;
cap >> frame_1;
cvtColor(frame_1, frame1, COLOR_BGR2GRAY);
Mat smoothedMat(2,3,CV_64F);
VideoWriter outputVideo;
outputVideo.open("com.avi" , CV_FOURCC('X' , 'V' , 'I' , 'D'), 30 , frame_1.size());
while(true)
{
try {
cap >> frame_2;
if(frame_2.data == NULL)
{
break;
}
cvtColor(frame_2, frame2, COLOR_BGR2GRAY);
Mat smoothedFrame;
smoothedFrame = stab.stabilize(frame_1 , frame_2);
outputVideo.write(smoothedFrame);
imshow("Stabilized Video" , smoothedFrame);
waitKey(10);
frame_1 = frame_2.clone();
frame2.copyTo(frame1);
} catch (cv::Exception& e) {
cap >> frame_1;
cvtColor(frame_1, frame1, COLOR_BGR2GRAY);
}
}
return 0;
}