Merge pull request #16080 from TolyaTalamanov:at/fix-mosaic-primitive
G-API: Mosaic handle corner cases * Handle corner cases * Fix mosaic algo * Fix bug with empty rects
This commit is contained in:
committed by
Alexander Alekhin
parent
f270e8d040
commit
4a4ff6749b
@@ -21,13 +21,54 @@ cv::Scalar cvtBGRToYUVC(const cv::Scalar& bgr)
|
||||
|
||||
void drawMosaicRef(const cv::Mat& mat, const cv::Rect &rect, int cellSz)
|
||||
{
|
||||
cv::Mat msc_roi = mat(rect);
|
||||
int crop_x = msc_roi.cols - msc_roi.cols % cellSz;
|
||||
int crop_y = msc_roi.rows - msc_roi.rows % cellSz;
|
||||
cv::Rect mat_rect(0, 0, mat.cols, mat.rows);
|
||||
auto intersection = mat_rect & rect;
|
||||
|
||||
for(int i = 0; i < crop_y; i += cellSz ) {
|
||||
for(int j = 0; j < crop_x; j += cellSz) {
|
||||
auto cell_roi = msc_roi(cv::Rect(j, i, cellSz, cellSz));
|
||||
cv::Mat msc_roi = mat(intersection);
|
||||
|
||||
bool has_crop_x = false;
|
||||
bool has_crop_y = false;
|
||||
|
||||
int cols = msc_roi.cols;
|
||||
int rows = msc_roi.rows;
|
||||
|
||||
if (msc_roi.cols % cellSz != 0)
|
||||
{
|
||||
has_crop_x = true;
|
||||
cols -= msc_roi.cols % cellSz;
|
||||
}
|
||||
|
||||
if (msc_roi.rows % cellSz != 0)
|
||||
{
|
||||
has_crop_y = true;
|
||||
rows -= msc_roi.rows % cellSz;
|
||||
}
|
||||
|
||||
cv::Mat cell_roi;
|
||||
for(int i = 0; i < rows; i += cellSz )
|
||||
{
|
||||
for(int j = 0; j < cols; j += cellSz)
|
||||
{
|
||||
cell_roi = msc_roi(cv::Rect(j, i, cellSz, cellSz));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
if (has_crop_x)
|
||||
{
|
||||
cell_roi = msc_roi(cv::Rect(cols, i, msc_roi.cols - cols, cellSz));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
}
|
||||
|
||||
if (has_crop_y)
|
||||
{
|
||||
for(int j = 0; j < cols; j += cellSz)
|
||||
{
|
||||
cell_roi = msc_roi(cv::Rect(j, rows, cellSz, msc_roi.rows - rows));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
if (has_crop_x)
|
||||
{
|
||||
cell_roi = msc_roi(cv::Rect(cols, rows, msc_roi.cols - cols, msc_roi.rows - rows));
|
||||
cell_roi = cv::mean(cell_roi);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user