RUSH
Reusable Utilities in Single Headers is a collection of header-only utilities for C++
Loading...
Searching...
No Matches
cv-highgui.hpp
Go to the documentation of this file.
1
8#ifndef RUSH_CV_HIGHGUI_HPP
9#define RUSH_CV_HIGHGUI_HPP
10
11#include <algorithm>
12#include <cstddef>
13#include <opencv2/core.hpp>
14#include <opencv2/core/mat.hpp>
15#include <opencv2/core/mat.inl.hpp>
16#include <opencv2/core/types.hpp>
17#include <opencv2/imgproc.hpp>
18#include <vector>
19
20namespace rush::cv {
21
30inline ::cv::Mat montage(std::vector<std::vector<::cv::Mat>> &images) {
31 ::cv::Mat montage;
32 ::cv::Size ref{images[0][0].size()};
33 std::size_t max_col = 0;
34
35 for(const std::vector<::cv::Mat> &v : images) {
36 for(const ::cv::Mat &i : v) {
37 if(i.size().area() < ref.area()) {
38 ref = i.size();
39 }
40 max_col = std::max(max_col, v.size());
41 }
42 }
43
44 std::vector<::cv::Mat> rows;
45 for(std::vector<::cv::Mat> &v : images) {
46 for(::cv::Mat &i : v) {
47 ::cv::resize(i, i, ref);
48 }
49 while(v.size() < max_col) {
50 v.emplace_back(ref, images[0][0].type(), ::cv::Scalar(0));
51 }
52 rows.emplace_back(v.size() * ref.width, ref.height, images[0][0].type());
53 ::cv::hconcat(v.data(), v.size(), rows.back());
54 }
55 ::cv::vconcat(rows.data(), rows.size(), montage);
56 return montage;
57}
58
69inline ::cv::Mat montage(std::vector<::cv::Mat> &images, std::size_t step = 0) {
70 std::vector<std::vector<::cv::Mat>> img_vector;
71 if(!static_cast<bool>(step)) {
72 step = images.size();
73 }
74 for(std::size_t i = 0; i < images.size(); i += step) {
75 img_vector.emplace_back(images.begin() + static_cast<long>(i), std::min(images.begin() + static_cast<long>(i + step), images.end()));
76 }
77 return montage(img_vector);
78}
79
80} // namespace rush::cv
81
82#endif // RUSH_CV_HIGHGUI_HPP
inline ::cv::Mat montage(std::vector< std::vector<::cv::Mat > > &images)
Create a montage from a matrix of images.
Definition cv-highgui.hpp:30