c++、opencv、泊松融合

做泊松融合的时候

 cv::seamlessClone(src, dst, inpaintMask2, center, im_result, cv::NORMAL_CLONE);

中:

dst的大小任意。但是最好保证src和inpaintMask2大小一致。

1、不规则mask图

        //seamlessClone
cv::Mat mask = cv::imread(maskimg_path, CV_8UC1);
vector<vector<cv::Point>> contours; cv::findContours(mask, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); double maxArea = 0; vector<cv::Point> maxContour; for (size_t i = 0; i < contours.size(); i++) { double area = cv::contourArea(contours[i]); if (area > maxArea) { maxArea = area; maxContour = contours[i]; } } cv::Rect maxRect = cv::boundingRect(maxContour); cv::Mat inpaintMask2 = mask(maxRect); cv::Mat src,dst; cv::Point center(maxRect.x + maxRect.width / 2, maxRect.y + maxRect.height / 2); cv::seamlessClone(src, dst, inpaintMask2, center, im_result, cv::NORMAL_CLONE);

2、矩形图,src就是mask

    int NORMAL_or_MIXED = 1;
    cv::Mat src,dst;
cv::Mat result=dst.clone(); cv::Point center(src.cols / 2, src.rows / 2); cv::Mat src_mask = 255 * cv::Mat::ones(src.rows, src.cols, src.depth()); if (NORMAL_or_MIXED == 1) { cv::seamlessClone(src, dst, src_mask, center, result, cv::NORMAL_CLONE); } else { cv::seamlessClone(src, dst, src_mask, center, result, cv::MIXED_CLONE); }

 

posted @ 2020-10-30 17:23  皮卡皮卡妞  阅读(462)  评论(0编辑  收藏  举报