How to delete those border component
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);
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(srcImg, seed, Scalar(0));
if (iRows == totalRows)
{
flg++;
iRows = 0;
strt = totalCols - 1;
}
}
imshow("src", srcImg);
waitKey();
return 0;
}
But I will get a poor result like
This is my border.jpg
This is my expected result
- What error in my code?
- Is there any better method to do this?