If you are in Matlab,there is a convenient function imclearborder. But I don't very fimilar the OpenCV. So I writer such code
#include<opencv.hpp>
using namespace cv;
int main() {
Mat srcImg = imread("border.jpg",IMREAD_GRAYSCALE),dstImg;
int totalRows = srcImg.rows;
int totalCols = srcImg.cols;
int strt = 0, flg = 0;
int iRows = 0, jCols = 0;
while (iRows < srcImg.rows)
{
if (flg == 1)
totalRows = -1;
Point seed(strt, iRows);
iRows++;
floodFill(dstImg, seed, Scalar(0));
if (iRows == totalRows)
{
flg++;
iRows = 0;
strt = totalCols - 1;
}
}
return 0;
}
But I don't know why my code cannot be compile. This is my test image
This is my expected result
- What error in my code?
- And is there any better method can do this?