Ask Your Question
0

How to change the background of scanned document in opencv c++

asked 2015-06-09 04:28:20 -0600

ashok gravatar image

updated 2015-06-22 04:15:29 -0600

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));
edit retag flag offensive close merge delete

Comments

3

example image? Own ideas?

FooBar gravatar imageFooBar ( 2015-06-19 04:11:11 -0600 )edit

If that's your actual image, a simple thresholding will work.

LorenaGdL gravatar imageLorenaGdL ( 2015-06-22 04:29:49 -0600 )edit

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.

ashok gravatar imageashok ( 2015-06-22 05:13:02 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2015-06-22 06:18:56 -0600

Flart gravatar image

updated 2015-06-23 04:47:25 -0600

Gray is not so bright, as you suggested at comment. Try CV_THRESH_OTSU or cv::threshold(imgH, imgH, 150, 255, CV_THRESH_TRUNC), it's enough for that kind of images.

edit flag offensive delete link more

Comments

thak you for the code.

ashok gravatar imageashok ( 2015-06-23 06:10:40 -0600 )edit

Question Tools

2 followers

Stats

Asked: 2015-06-09 04:28:20 -0600

Seen: 1,213 times

Last updated: Jun 23 '15