#include "ImageApplyConcatenation.h" CImageApplyConcatenation::CImageApplyConcatenation() : m_direction(autoDirection) , m_BG_color(0, 0, 0) { } CImageApplyConcatenation::CImageApplyConcatenation(ConcatMode dir, const cv::Scalar& background) : m_direction(dir) , m_BG_color(background) { } CImageApplyConcatenation::~CImageApplyConcatenation(void) { } void CImageApplyConcatenation::apply(cv::Mat& pDib, int side) { (void)pDib; (void)side; } void CImageApplyConcatenation::apply(std::vector& mats, bool isTwoSide) { (void)isTwoSide; if (mats.size() < 2) { mats.clear(); return; } ConcatMode direction; if (m_direction == ConcatMode::autoDirection) direction = (mats[0].cols > mats[0].rows) ? ConcatMode::vertical : ConcatMode::horizontal; else direction = m_direction; cv::Mat dst = concat(mats[0], mats[1], direction); mats.clear(); mats.push_back(dst); } cv::Mat CImageApplyConcatenation::concat(cv::Mat &front, cv::Mat &back, ConcatMode direction) { cv::Mat dst; if (direction == horizontal) { #if 0 int top, bottom; if (front.rows > back.rows) { top = (front.rows - back.rows) / 2; bottom = front.rows - back.rows - top; cv::copyMakeBorder(back, back, top, bottom, 0, 0, cv::BORDER_CONSTANT); } else if (front.rows < back.rows) { top = (back.rows - front.rows) / 2; bottom = back.rows - front.rows - top; cv::copyMakeBorder(front, front, top, bottom, 0, 0, cv::BORDER_CONSTANT); } cv::hconcat(front, back, dst); #else int width = cv::max(front.cols, back.cols) * 2; int height = cv::max(front.rows, back.rows); dst = cv::Mat(height, width, front.type(), m_BG_color); front.copyTo(dst(cv::Rect(0, 0, front.cols, front.rows))); int offset = front.cols; front.release(); back.copyTo(dst(cv::Rect(offset, 0, back.cols, back.rows))); back.release(); #endif } else if (direction == vertical) { #if 0 int left, right; if (front.cols > back.cols) { left = (front.cols - back.cols) / 2; right = front.cols - back.cols - left; cv::copyMakeBorder(back, back, 0, 0, left, right, cv::BORDER_CONSTANT); } else if (front.cols < back.cols) { left = (back.cols - front.cols) / 2; right = back.cols - front.cols - left; cv::copyMakeBorder(front, front, 0, 0, left, right, cv::BORDER_CONSTANT); } cv::vconcat(front, back, dst); #else int width = cv::max(front.cols, back.cols); int height = cv::max(front.rows, back.rows) * 2; dst = cv::Mat(height, width, front.type(), m_BG_color); front.copyTo(dst(cv::Rect(0, 0, front.cols, front.rows))); int offset = front.rows; front.release(); back.copyTo(dst(cv::Rect(0, offset, back.cols, back.rows))); back.release(); #endif } //front.release(); //back.release(); return dst; }