Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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?

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);
click to hide/show revision 2
No.2 Revision

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?

this is the result that I got.. C:\fakepath\Image.PNG

 Mat img_bw;
threshold(grad, img_bw, 128, 255, CV_THRESH_BINARY);

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);

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.. 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);

how to flood fill to differentiate between obstacle and the path that can be taken

I )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.. C:\fakepath\Image.PNG image description

    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);

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 image description[C:\fakepath\box_1.jpg] ![image description](/upfiles/1425435702793171.jpg

this is the result that I got.. after edge detection : image description

last result : image description

    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);

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] ![image description](/upfiles/1425435702793171.jpg

this This is the result that I got.. got..

after edge detection : image description

last result : image description

    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);

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] ![image description](/upfiles/1425435702793171.jpgC:\fakepath\box_1.jpg

This is the result that I got..

after edge detection : image description

last result : image description

    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);