i'm new opencv . i writing a remove the background .
my input image
i coded my program as follow steps :
- calculate average pixels
//define roi of image
cv::Rect roi(0, 0, 20 , 20 );
//copies input image in roi
cv::Mat image_roi = imgGray( roi );
//imshow("roi", image_roi);
//computes mean over roi
cv::Scalar avgPixelIntensity = cv::mean( image_roi );
//prints out only .val[0] since image was grayscale
cout << "Pixel intensity over ROI = " << avgPixelIntensity.val[0] << endl;
-create new Mat image base on average pixels values :
//create new mat image base on avgPixelIntensity
cv::Mat areaSampleArv(imgGray.rows, imgGray.cols,imgGray.type(),avgPixelIntensity.val[0]);
imshow("areaSampleArv", areaSampleArv);
-Invert image :
void image_invert(Mat& image){
int height, width, step, channels;
uchar *data;
height = image.cols;
width = image.rows;
step = (int)image.step;
channels = image.channels();
data = (uchar *)image.data;
for(int i = 0; i < height; i++){
for(int j = 0; j < width; j++){
for(int k = 0; k < channels; k++){
data[i*step + j*channels + k] = 255 - data[i*step + j*channels + k];
}
}
}
//imwrite("/Users/thuydungle/Desktop/1234/inverted.png", image);
imshow("inverted", image);}
my image inverted result :
-Add inverted image with original image:
Mat dst;
dst = areaSampleArv + im0;
imshow("dst", dst);
any my image result :
seem it is very bad and i can use thresholding for extraction numbers ?
so , can you tell me how to fix it ?
thank !