start packing
This commit is contained in:
parent
a2f07920c7
commit
8d91216f24
4 changed files with 62 additions and 1 deletions
37
src/pack.cpp
37
src/pack.cpp
|
@ -1,6 +1,43 @@
|
|||
#include "pack.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
Frame pack(const Frame& in_frame, const std::vector<BoundingBox>& bboxes) {
|
||||
// We sort the bounding boxes by maximum area
|
||||
std::vector<BoundingBox> sorted_bboxes = bboxes;
|
||||
std::sort(sorted_bboxes.begin(), sorted_bboxes.end(),
|
||||
[](const auto& a, const auto& b) { return a.area() > b.area(); });
|
||||
|
||||
// We keep a mapping between the sorted bounding boxes and the original
|
||||
// order
|
||||
std::vector<int> mapping(bboxes.size());
|
||||
for (int i = 0; i < sorted_bboxes.size(); ++i) {
|
||||
const auto& s_box = sorted_bboxes[i];
|
||||
for (int j = 0; j < bboxes.size(); ++j) {
|
||||
const auto& box = bboxes[j];
|
||||
if (box == s_box) {
|
||||
mapping[i] = j;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int max_area = 0;
|
||||
for (const auto& box : sorted_bboxes) {
|
||||
int area = box.area();
|
||||
std::cout << "bounding box area: " << area << "\n";
|
||||
max_area += area;
|
||||
}
|
||||
std::cout << "max area: " << max_area << "\n";
|
||||
int min_dim = int(ceil(std::sqrt(max_area)));
|
||||
std::cout << "optimal image dimention: " << min_dim << " x " << min_dim
|
||||
<< "\n";
|
||||
const int in_min_dim = std::min(in_frame.width, in_frame.height);
|
||||
std::cout << "maximum image dimention: " << in_min_dim << " x "
|
||||
<< in_min_dim << "\n";
|
||||
|
||||
// TODO
|
||||
return Frame(in_frame);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue