I try this coding and I got the result..I want the object and wall to be black while the floor which is the path that can be taken by the robot is in white..But, the result that I have obtained is different from what I expected (object and floor are black; wall is white)..can anyone help me?..any suggestion?
this is the result that I got.. C:\fakepath\Image.PNG
Mat img_bw; threshold(grad, img_bw, 128, 255, CV_THRESH_BINARY);
// Loop through the border pixels and if they're black, floodFill from there
cv::Mat mask;
img_bw.copyTo(mask);
for (int j = 0; j < mask.rows; j++)
{
for (int i = 0; i < mask.cols ; i++)
{
if (mask.at<char>(i,j) == 0)
{
cv::floodFill(mask, cv::Point(i, j), 255, 0, 10, 10);
}
else
{
break;
}
}
}
// Compare mask with original.
cv::Mat newImage;
img_bw.copyTo(newImage);
for (int row = 0; row < mask.rows; ++row) {
for (int col = 0; col < mask.cols; ++col) {
if (mask.at<char>(row, col) == 0) {
newImage.at<char>(row, col) = 255;
}
}
}
Mat img_bw1;
threshold(newImage, img_bw1, 128, 255, CV_THRESH_BINARY_INV);