Changing part of image doesnt effect orjinal image OpenCV 2.4.11 C++ [closed]

asked 2015-12-04 13:01:43 -0600

Sarp Aykent gravatar image

updated 2015-12-04 14:22:55 -0600

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;

/*
                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: image description

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Sarp Aykent
close date 2015-12-04 18:34:51.621488

Comments

If you skip the processing part, how are we supposed to know what it's going on? Well, apart from the fact that you don't specify your problem...

LorenaGdL gravatar imageLorenaGdL ( 2015-12-04 13:30:55 -0600 )edit

Updated code

Sarp Aykent gravatar imageSarp Aykent ( 2015-12-04 13:52:57 -0600 )edit

i did not understand, your problem is solved or not?

sturkmen gravatar imagesturkmen ( 2015-12-05 09:03:22 -0600 )edit