Scan the borders of the image and when you find a white pixel flood fill with black.
You will want something like:
uchar white(255);
// do top and bottom row
for(int y = 0; y < image.rows; y += image.rows-1)
{
uchar* row = image.ptr<uchar>(y)
for(int x = 0; x < image.cols; ++x)
{
if(row[x] == white)
{
cv::floodFill(image, cv::Point(x,y), cv::Scalar(0), (cv::Rect*)0, cv::Scalar(), cv::Scalar(200));
}
}
}
// fix left and right sides
for(int y = 0; y < image.rows; ++y)
{
row = image.ptr<uchar>(y)
for(int x = 0; x < image.cols; x += image.cols - 1)
{
if(row[x] == white)
{
cv::floodFill(image, cv::Point(x,y), cv::Scalar(0), (cv::Rect*)0, cv::Scalar(), cv::Scalar(200));
}
}
}
0
solved How to remove items adjacent to border of image [closed]