how to flood fill to differentiate between obstacle and the path that can be taken
)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?
the original image : C:\fakepath\box_1.jpg
This is the result that I got..
after edge detection :
last result :
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);
I think that the approach that you are following might be a bit wrong, I think that you need to apply some pre-processing before you threshold the image. If you could upload the original image, which I guess is a depth image or not? might get some feedback.
Okay..I have already upload the original image.. :)