@@ -80,54 +80,66 @@ std::future<StitcherData> StitcherPipeline::RunLoading(
80
80
81
81
std::future<StitchingResult> StitcherPipeline::RunStitching (
82
82
const StitcherData &data, const StitchingOptions &options) {
83
- std::vector<cv::Mat> imgs;
84
83
auto pano = data.panos [options.pano_id ];
85
-
86
84
return pool_.submit ([pano, &images = data.images , options, this ]() {
87
- int num_tasks = static_cast <int >(pano.ids .size ()) + 1 +
88
- static_cast <int >(options.export_path .has_value ()) +
89
- static_cast <int >(options.full_res );
90
- progress_.Reset (ProgressType::kLoadingImages , num_tasks);
91
- std::vector<cv::Mat> imgs;
85
+ return RunStitchingPipeline (pano, images, options);
86
+ });
87
+ }
88
+
89
+ StitchingResult StitcherPipeline::RunStitchingPipeline (
90
+ const algorithm::Pano &pano, const std::vector<algorithm::Image> &images,
91
+ const StitchingOptions &options) {
92
+ int num_tasks = static_cast <int >(pano.ids .size ()) + 1 +
93
+ static_cast <int >(options.export_path .has_value ()) +
94
+ static_cast <int >(options.full_res );
95
+ progress_.Reset (ProgressType::kLoadingImages , num_tasks);
96
+ std::vector<cv::Mat> imgs;
97
+ if (options.full_res ) {
98
+ BS::multi_future<cv::Mat> imgs_future;
99
+ for (const auto &img_id : pano.ids ) {
100
+ imgs_future.push_back (pool_.submit ([this , &image = images[img_id]]() {
101
+ auto full_res_image = image.GetFullRes ();
102
+ progress_.NotifyTaskDone ();
103
+ return full_res_image;
104
+ }));
105
+ }
106
+ imgs = imgs_future.get ();
107
+ } else {
92
108
for (int img_id : pano.ids ) {
93
- if (options.full_res ) {
94
- imgs.push_back (images[img_id].GetFullRes ());
95
- } else {
96
- imgs.push_back (images[img_id].GetPreview ());
97
- }
109
+ imgs.push_back (images[img_id].GetPreview ());
98
110
progress_.NotifyTaskDone ();
99
111
}
112
+ }
100
113
101
- progress_.SetTaskType (ProgressType::kStitchingPano );
102
- auto [status, pano , mask] =
103
- algorithm::Stitch ( imgs, {. projection = options. projection ,
104
- .return_pano_mask = options.full_res });
105
- progress_.NotifyTaskDone ();
114
+ progress_.SetTaskType (ProgressType::kStitchingPano );
115
+ auto [status, result , mask] = algorithm::Stitch (
116
+ imgs,
117
+ {. projection = options. projection , .return_pano_mask = options.full_res });
118
+ progress_.NotifyTaskDone ();
106
119
107
- if (status != cv::Stitcher::OK) {
108
- return StitchingResult{.pano_id = options.pano_id , .status = status};
109
- }
120
+ if (status != cv::Stitcher::OK) {
121
+ return StitchingResult{.pano_id = options.pano_id , .status = status};
122
+ }
110
123
111
- std::optional<utils::RectRRf> auto_crop;
112
- if (options.full_res ) {
113
- progress_.SetTaskType (ProgressType::kAutoCrop );
114
- auto_crop = algorithm::FindLargestCrop (mask);
115
- progress_.NotifyTaskDone ();
116
- }
124
+ std::optional<utils::RectRRf> auto_crop;
125
+ if (options.full_res ) {
126
+ progress_.SetTaskType (ProgressType::kAutoCrop );
127
+ auto_crop = algorithm::FindLargestCrop (mask);
128
+ progress_.NotifyTaskDone ();
129
+ }
117
130
118
- std::optional<std::string> export_path;
119
- if (options.export_path ) {
120
- progress_.SetTaskType (ProgressType::kExport );
121
- if (cv::imwrite (*options.export_path , pano,
122
- CompressionParameters (options.compression ))) {
123
- export_path = options.export_path ;
124
- }
125
- progress_.NotifyTaskDone ();
131
+ std::optional<std::string> export_path;
132
+ if (options.export_path ) {
133
+ progress_.SetTaskType (ProgressType::kExport );
134
+ if (cv::imwrite (*options.export_path , result,
135
+ CompressionParameters (options.compression ))) {
136
+ export_path = options.export_path ;
126
137
}
138
+ progress_.NotifyTaskDone ();
139
+ }
127
140
128
- return StitchingResult{options.pano_id , options.full_res , status, pano,
129
- auto_crop, export_path};
130
- });
141
+ return StitchingResult{options.pano_id , options.full_res , status,
142
+ result, auto_crop, export_path};
131
143
}
132
144
133
145
std::future<ExportResult> StitcherPipeline::RunExport (
@@ -152,7 +164,7 @@ std::future<ExportResult> StitcherPipeline::RunExport(
152
164
});
153
165
}
154
166
155
- ProgressReport StitcherPipeline::LoadingProgress () const {
167
+ ProgressReport StitcherPipeline::Progress () const {
156
168
return progress_.Progress ();
157
169
}
158
170
0 commit comments