How to remove the background color of image using opencv c++ in ios

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

How to remove the background color of image using opencv c++ in ios

Ashok407
This post has NOT been accepted by the mailing list yet.
Actually i want image background is white.But background is not removed totally. Example: My image having text Ashok,In this background is not removed from O inside circle.

here is my code:

//src have my actual mat object image.
    cv::Mat source(src.rows, src.cols,CV_8UC1);
    cv::addWeighted(src, 2.5, src, -1, 2.0, source);
    cv::GaussianBlur(source, imgH, cv::Size(5, 5), cv::BORDER_WRAP);
    cv::cvtColor(imgH,imgH,CV_BGR2RGB);

    imgH = imgH + cvScalar(-50, -50, -50);

    //Now replace the black background with white color
    cv::floodFill(imgH, cv::Point(10,10), cv::Scalar(255,255,255), (cv::Rect*)0, cv::Scalar(), cv::Scalar(255,255,255));
    cv::floodFill(imgH, cv::Point(imgH.cols-10 ,10), cv::Scalar(255,255,255), (cv::Rect*)0, cv::Scalar(), cv::Scalar(255,255,255));

    cv::floodFill(imgH, cv::Point(10,imgH.rows-10), cv::Scalar(255,255,255), (cv::Rect*)0, cv::Scalar(), cv::Scalar(255,255,255));
    cv::floodFill(imgH, cv::Point(imgH.cols-10,imgH.rows-10), cv::Scalar(255,255,255), (cv::Rect*)0, cv::Scalar(), cv::Scalar(255,255,255));