Hey, I'm processing part of image but it changes orginal image weirdly.
Edit: Found the problem redFilter is returning copy of the image. I changed code create another mat and copy it to tile still dont work.
Here code that I'm using:
Mat redFilter(const Mat& src, int x, int y, int z,int r, int g, int b)
{
assert(src.type() == CV_8UC3);
Mat redOnly;
// Black and tones
inRange(src, Scalar(x,y,z), Scalar(b,g,r), redOnly);
return redOnly;
}
namedWindow("Orginal", WINDOW_NORMAL );
cv::imshow("Orginal", matTestingNumbers);
int N = 8;
for (int c = 0; c < matTestingNumbers.cols; c += N)
{
cv::Mat tile = matTestingNumbers(cv::Range(0, matTestingNumbers.rows),
cv::Range(c, min(c + N, matTestingNumbers.cols)));//no data copying here
cv::cvtColor(tile, matGrayscale, CV_BGR2GRAY);
//computes mean over roi
cv::Scalar avgPixelIntensity = cv::mean( matGrayscale );
matGrayscale.release();
//prints out only .val[0] since image was grayscale
double deger = avgPixelIntensity.val[0];
if(deger > 100)
{
ekle = +((int)deger-100)/2;
}
else
{
ekle = -((int)100-deger);
}
tile = cv::Scalar::all(255) - tile;
// cv::imshow("Cleared 1", matTestingNumbers);
/*
Mat tileExt = tile.clone();
tileExt = redFilter(tileExt,fullData[ocrIndex].Rs, fullData[ocrIndex].Gs, fullData[ocrIndex].Bs, fullData[ocrIndex].Rf+ekle, fullData[ocrIndex].Gf+ekle, fullData[ocrIndex].Bf+ekle); // Convert all colors to black
tileExt.copyTo(tile);
*/
// this part is the problem
inRange(tile, Scalar(fullData[ocrIndex].Rs, fullData[ocrIndex].Gs, fullData[ocrIndex].Bs), Scalar(fullData[ocrIndex].Bf+ekle,fullData[ocrIndex].Gf+ekle,fullData[ocrIndex].Rf+ekle), tile);
tile = cv::Scalar::all(255) - tile;
namedWindow(tostr(c), WINDOW_NORMAL );
cv::imshow(tostr(c), tile);
}
namedWindow("Cleared 1", WINDOW_NORMAL );
cv::imshow("Cleared 1", matTestingNumbers);
Result: