优化缓存的使用

TempBranch
Matthew 9 months ago
parent f95a79ba89
commit 6d421a6cc1

@ -933,6 +933,8 @@ void align::process( const hdrplus::burst& burst_images, \
// Align every image // Align every image
const std::vector<cv::Mat>& ref_grayimg_pyramid = per_grayimg_pyramid[ burst_images.reference_image_idx ]; const std::vector<cv::Mat>& ref_grayimg_pyramid = per_grayimg_pyramid[ burst_images.reference_image_idx ];
std::vector<std::vector<std::pair<int, int>>> curr_alignment;
std::vector<std::vector<std::pair<int, int>>> prev_alignment;
for ( int img_idx = 0; img_idx < burst_images.num_images; ++img_idx ) for ( int img_idx = 0; img_idx < burst_images.num_images; ++img_idx )
{ {
// Do not align with reference image // Do not align with reference image
@ -944,8 +946,8 @@ void align::process( const hdrplus::burst& burst_images, \
// Align every level from coarse to grain // Align every level from coarse to grain
// level 0 : finest level, the original image // level 0 : finest level, the original image
// level 3 : coarsest level // level 3 : coarsest level
std::vector<std::vector<std::pair<int, int>>> curr_alignment; curr_alignment.clear();
std::vector<std::vector<std::pair<int, int>>> prev_alignment; prev_alignment.clear();
for ( int level_i = num_levels - 1; level_i >= 0; level_i-- ) // 3,2,1,0 for ( int level_i = num_levels - 1; level_i >= 0; level_i-- ) // 3,2,1,0
{ {
// make curr alignment as previous alignment // make curr alignment as previous alignment

@ -10,6 +10,10 @@
#include "hdrplus/finish.h" #include "hdrplus/finish.h"
#include <fstream> #include <fstream>
#ifdef __ANDROID__
#include <AndroidHelper.h>
#endif
namespace hdrplus namespace hdrplus
{ {
@ -19,6 +23,7 @@ void hdrplus_pipeline::run_pipeline( \
{ {
// Create burst of images // Create burst of images
burst burst_images( burst_path, reference_image_path ); burst burst_images( burst_path, reference_image_path );
std::vector<std::vector<std::vector<std::pair<int, int>>>> alignments; std::vector<std::vector<std::vector<std::pair<int, int>>>> alignments;
// Run align // Run align
@ -27,6 +32,7 @@ void hdrplus_pipeline::run_pipeline( \
// Run merging // Run merging
merge_module.process( burst_images, alignments ); merge_module.process( burst_images, alignments );
// Run finishing // Run finishing
cv::Mat finalImg; cv::Mat finalImg;
finish_module.process( burst_images, finalImg); finish_module.process( burst_images, finalImg);
@ -39,15 +45,27 @@ bool hdrplus_pipeline::run_pipeline( \
// Create burst of images // Create burst of images
burst burst_images( burst_paths, reference_image_index ); burst burst_images( burst_paths, reference_image_index );
std::vector<std::vector<std::vector<std::pair<int, int>>>> alignments; std::vector<std::vector<std::vector<std::pair<int, int>>>> alignments;
#ifdef __ANDROID__
ALOGI("Finish loading images");
#endif
// Run align // Run align
align_module.process( burst_images, alignments ); align_module.process( burst_images, alignments );
#ifdef __ANDROID__
ALOGI("Finish align");
#endif
// Run merging // Run merging
merge_module.process( burst_images, alignments ); merge_module.process( burst_images, alignments );
#ifdef __ANDROID__
ALOGI("Finish merging");
#endif
// Run finishing // Run finishing
finish_module.process( burst_images, finalImg); finish_module.process( burst_images, finalImg);
#ifdef __ANDROID__
ALOGI("Finish process");
#endif
return true; return true;
} }

@ -116,8 +116,9 @@ namespace hdrplus
// 1. get all four subsets: original (evenly split), horizontal overlapped, // 1. get all four subsets: original (evenly split), horizontal overlapped,
// vertical overlapped, 2D overlapped // vertical overlapped, 2D overlapped
std::vector<std::vector<cv::Mat>> tiles_original; std::vector<std::vector<cv::Mat>> tiles_original;
std::vector<cv::Mat> row;
for (int y = 0; y < num_rows / offset - 1; y += 2) { for (int y = 0; y < num_rows / offset - 1; y += 2) {
std::vector<cv::Mat> row; row.clear();
for (int x = 0; x < num_cols / offset - 1; x += 2) { for (int x = 0; x < num_cols / offset - 1; x += 2) {
row.push_back(tiles[y * (num_cols / offset - 1) + x]); row.push_back(tiles[y * (num_cols / offset - 1) + x]);
} }
@ -125,8 +126,9 @@ namespace hdrplus
} }
std::vector<std::vector<cv::Mat>> tiles_horizontal; std::vector<std::vector<cv::Mat>> tiles_horizontal;
// std::vector<cv::Mat> row;
for (int y = 0; y < num_rows / offset - 1; y += 2) { for (int y = 0; y < num_rows / offset - 1; y += 2) {
std::vector<cv::Mat> row; row.clear();
for (int x = 1; x < num_cols / offset - 1; x += 2) { for (int x = 1; x < num_cols / offset - 1; x += 2) {
row.push_back(tiles[y * (num_cols / offset - 1) + x]); row.push_back(tiles[y * (num_cols / offset - 1) + x]);
} }
@ -134,8 +136,9 @@ namespace hdrplus
} }
std::vector<std::vector<cv::Mat>> tiles_vertical; std::vector<std::vector<cv::Mat>> tiles_vertical;
// std::vector<cv::Mat> row;
for (int y = 1; y < num_rows / offset - 1; y += 2) { for (int y = 1; y < num_rows / offset - 1; y += 2) {
std::vector<cv::Mat> row; row.clear();
for (int x = 0; x < num_cols / offset - 1; x += 2) { for (int x = 0; x < num_cols / offset - 1; x += 2) {
row.push_back(tiles[y * (num_cols / offset - 1) + x]); row.push_back(tiles[y * (num_cols / offset - 1) + x]);
} }
@ -143,8 +146,9 @@ namespace hdrplus
} }
std::vector<std::vector<cv::Mat>> tiles_2d; std::vector<std::vector<cv::Mat>> tiles_2d;
// std::vector<cv::Mat> row;
for (int y = 1; y < num_rows / offset - 1; y += 2) { for (int y = 1; y < num_rows / offset - 1; y += 2) {
std::vector<cv::Mat> row; row.clear();
for (int x = 1; x < num_cols / offset - 1; x += 2) { for (int x = 1; x < num_cols / offset - 1; x += 2) {
row.push_back(tiles[y * (num_cols / offset - 1) + x]); row.push_back(tiles[y * (num_cols / offset - 1) + x]);
} }
@ -190,9 +194,10 @@ namespace hdrplus
std::vector<std::vector<cv::Mat>> alt_tiles_list(reference_tiles.size()); std::vector<std::vector<cv::Mat>> alt_tiles_list(reference_tiles.size());
int num_tiles_row = alternate_channel_i_list[0].rows / offset - 1; int num_tiles_row = alternate_channel_i_list[0].rows / offset - 1;
int num_tiles_col = alternate_channel_i_list[0].cols / offset - 1; int num_tiles_col = alternate_channel_i_list[0].cols / offset - 1;
std::vector<cv::Mat> alt_tiles;
for (int y = 0; y < num_tiles_row; ++y) { for (int y = 0; y < num_tiles_row; ++y) {
for (int x = 0; x < num_tiles_col; ++x) { for (int x = 0; x < num_tiles_col; ++x) {
std::vector<cv::Mat> alt_tiles; alt_tiles.clear();
// Get reference tile location // Get reference tile location
int top_left_y = y * offset; int top_left_y = y * offset;
int top_left_x = x * offset; int top_left_x = x * offset;

Loading…
Cancel
Save