OpenCV set pixels outside ROI as the nearest pixel value inside the ROI

I have an image with a non-rectangular ROI, defined by a binary mask image.

In OpenCV, how can I set the pixels OUTSIDE my ROI as the nearest pixel value INSIDE the ROI? Something similar to what is in cv::BORDER_REPLICATE , or something similar to what is done in cv::warp


You can make use of cv::inpaint() by restoring the selected region region in an image using the region neighborhood.

In your case, that will be something like:

cv::inpaint(mat_input, 255 - roi, mat_output, inpaint_radius, cv::INPAINT_NS);
链接地址: http://www.djcxy.com/p/89728.html

上一篇: 如何使用opencv和Python在ROI中查找轮廓?

下一篇: OpenCV将ROI之外的像素设置为ROI内的最近像素值