opencv seamlessClone


void htob(Mat& mat) {
    for (size_t i = 0; i < mat.rows; i++)
    {
        for (size_t j = 0; j < mat.cols; j++)
        {
            if (mat.at<uchar>(i, j) == 255) {
                mat.at<uchar>(i, j) = 0;
            }
            else {
                mat.at<uchar>(i, j) = 255;
            }
        }

    }
}

Mat  dst = imread("a8.jpg");
    Mat  image = imread("c1.jpg");
    if (dst.empty() || image.empty())

{

        return -1;
    }
    Mat  gray ,mask;
    cvtColor(image, gray, COLOR_BGR2GRAY);
    threshold(gray, mask, 0, 255, THRESH_BINARY | THRESH_OTSU);
    htob(mask);
    Mat k = getStructuringElement(MORPH_RECT, Size(35, 35), Point(-1, -1));
    dilate(mask, mask, k);
    imshow("mask", mask);
    imshow("imgae", image);
     Mat  blent;
    seamlessClone(image, dst, mask, Point(1600, 300), blent, 1);
    imwrite("jason.jpg", blent);
    imshow("blent", blent);    waitKey(0);

Result结果:


猜你喜欢

转载自blog.csdn.net/www5256246/article/details/80192530
今日推荐