|
@@ -3,6 +3,7 @@
|
|
|
Stacker::Stacker()
|
|
|
{
|
|
|
Stacker::layers = 0;
|
|
|
+ Stacker::trimratio = 0;
|
|
|
cv::setNumThreads(0);
|
|
|
Stacker::stopwatch = clock();
|
|
|
}
|
|
@@ -52,6 +53,10 @@ Stacker::add_frame(unsigned char *data, int width, int height)
|
|
|
warpPerspective(mat, warped, warp_matrix, warped.size(), INTER_LINEAR);
|
|
|
stopwatch_mark("warp image");
|
|
|
|
|
|
+ // Check how much the image should be cropped to hide the warped edges
|
|
|
+ float current_trimratio = cv::videostab::estimateOptimalTrimRatio(warp_matrix, mat.size());
|
|
|
+ Stacker::trimratio = std::max(Stacker::trimratio, current_trimratio);
|
|
|
+
|
|
|
// Add the warped image to the stack
|
|
|
Stacker::stacked += warped;
|
|
|
Stacker::layers += 1;
|
|
@@ -61,6 +66,14 @@ Stacker::add_frame(unsigned char *data, int width, int height)
|
|
|
Mat
|
|
|
Stacker::postprocess_mat(Mat input)
|
|
|
{
|
|
|
+ stopwatch_start();
|
|
|
+ int h_crop = (int) ((float) input.cols * Stacker::trimratio);
|
|
|
+ int v_crop = (int) ((float) input.rows * Stacker::trimratio);
|
|
|
+ printf("crop: %d %d\n", h_crop, v_crop);
|
|
|
+ Mat cropped;
|
|
|
+ input(Rect(h_crop, v_crop, input.cols - h_crop - h_crop, input.rows - v_crop - v_crop)).copyTo(input);
|
|
|
+ stopwatch_mark("trim");
|
|
|
+
|
|
|
stopwatch_start();
|
|
|
Mat blur;
|
|
|
GaussianBlur(input, blur, Size(0, 0), 1.8);
|
|
@@ -131,6 +144,8 @@ Stacker::get_result()
|
|
|
|
|
|
// Run the final-frame postprocessing
|
|
|
Mat result = postprocess_mat(Stacker::stacked);
|
|
|
+ Stacker::export_width = result.cols;
|
|
|
+ Stacker::export_height = result.rows;
|
|
|
|
|
|
// Convert mat to bytes
|
|
|
size_t size = result.total() * result.elemSize();
|
|
@@ -147,6 +162,8 @@ Stacker::postprocess(unsigned char *data, int width, int height)
|
|
|
|
|
|
// Run the final-frame postprocessing
|
|
|
Mat result = postprocess_mat(mat);
|
|
|
+ Stacker::export_width = result.cols;
|
|
|
+ Stacker::export_height = result.rows;
|
|
|
|
|
|
// Convert mat to bytes
|
|
|
size_t size = result.total() * result.elemSize();
|
|
@@ -165,4 +182,16 @@ void
|
|
|
Stacker::stopwatch_mark(const char *name)
|
|
|
{
|
|
|
printf("[%.1fms] %s\n", float(clock() - Stacker::stopwatch) / CLOCKS_PER_SEC * 1000, name);
|
|
|
+}
|
|
|
+
|
|
|
+int
|
|
|
+Stacker::get_width()
|
|
|
+{
|
|
|
+ return Stacker::export_width;
|
|
|
+}
|
|
|
+
|
|
|
+int
|
|
|
+Stacker::get_height()
|
|
|
+{
|
|
|
+ return Stacker::export_height;
|
|
|
}
|