How to change the background of scanned document in opencv c++
C:\fakepath\Screen Shot 2015-06-19 at 7.57.23 pm.png
I can removed the background from outside of my image (O).how to remove the background gray color inside circle of image.
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));
example image? Own ideas?
If that's your actual image, a simple thresholding will work.
Threshold is not working. I am tried with this code cv::threshold(imgH, imgH, 245, 255, CV_THRESH_TRUNC); And also tried with CV_THRESH_BINARY. both are not working. Actually this not my full image, I cropped the one letter from my output text document.