#include "ImageApplySplit.h" #include #define BPP(type,index) CImageApplySplit::CImageApplySplit(int multitype,bool split, bool ismulti_filter_red,int colormode) : m_bmulti_filter_red(ismulti_filter_red) , m_split(split) , m_multitype(multitype) , m_colormode(colormode) { } CImageApplySplit::~CImageApplySplit(void) { } std::vector CImageApplySplit::SplitMats(std::vector& mats, bool isTwoSide) { std::vector rets; for (size_t i = 0; i < mats.size(); i++) { if (mats[i].empty()) continue; int bpp = getBpp(i); if(m_split)//²ð·Ö { std::vector retmats = apply(mats[i]); if (bpp != -1) { } else {//½ö²ð·Ö if (m_colormode == 0) bpp = 1;//bw else if (m_colormode == 1) bpp = 8; else bpp = 24; } for (size_t j = 0; j < retmats.size(); j++) { if (!retmats[j].empty()) { MatEx matex(retmats[j], bpp); rets.push_back(matex); } } } else{ MatEx matex(mats[i], bpp); rets.push_back(matex); } } return rets; } std::vector CImageApplySplit::apply(cv::Mat& pDib) { if (pDib.empty()) return std::vector(); std::vector retMats; int heigth = pDib.rows; int width = pDib.cols; if (heigth > width) { cv::Mat matF = pDib(cv::Rect(0, 0, width, (int)(0.5 * heigth))); cv::Mat matB = pDib(cv::Rect(0, (int)(0.5 * heigth), width, (int)(0.5 * heigth))); retMats.push_back(matF); retMats.push_back(matB); } else { cv::Mat matF = pDib(cv::Rect(0, 0, (int)(width*0.5), heigth)); cv::Mat matB = pDib(cv::Rect((int)(width*0.5), 0, (int)(width * 0.5), heigth)); retMats.push_back(matF); retMats.push_back(matB); } return retMats; } int CImageApplySplit::getBpp(int matIndex) { int ret = -1; if (m_bmulti_filter_red) { ret = matIndex == 0 ? 24 : 8; } else { if (m_multitype == -1) return ret; switch (m_multitype) { case 0://all if (matIndex == 0) ret = 24; else if (matIndex == 1) ret = 8; else ret = 1; break; case 1://clolr +gray if (matIndex == 0) ret = 24; else ret = 8; break; case 2://color+bw if (matIndex == 0) ret = 24; else ret = 1; break; case 3://gray+bw if (matIndex == 0) ret = 8; else ret = 1; break; default: break; } } return ret; }