Ask Your Question

Revision history [back]

Floodfill not working also Mat.get(col,row) is returning wrong color

the floodfill is not effecting the bitmap also the Mat.get(col,row) is returning wrong color.

Things I have done:
1) checked that bitmap and matrix are of same size.
2) checked the color both ways RGB and BGR.
3) checked the initial bmp and final bmp (after applying flood fill).
4) checked floodfill with both signatures.

public void flood(int x,int y,int sourceColor,int newColor){ try { Bitmap bmp; if(OpenCVLoader.initDebug()){ image = new Mat(); mat1 = new Mat(); Utils.bitmapToMat(bmp2,mat1); image = Mat.zeros(mat1.rows()+2,mat1.cols()+2,CvType.CV_8U); if(bmp2.getWidth()==mat1.cols()){} } int k = mat1.channels(); int col = bmp2.getPixel(x, y); int alpha = col & 0xFF000000; int red = (col & 0x00FF0000) >> 16; int green = (col & 0x0000FF00) >> 8; int blue = (col & 0x000000FF); double[] tt = (mat1.get(x,y)); Imgproc.cvtColor(mat1,mat1,Imgproc.COLOR_BGRA2BGR); tt = (mat1.get(x,y));

    //Imgproc.floodFill(mat1,image,p1,new Scalar(blue,green,red),new Rect(),new Scalar(230),new Scalar(220),4 + (255<<8) + Imgproc.FLOODFILL_MASK_ONLY);
    Imgproc.floodFill(mat1,image,p1,new Scalar(255,255,255));
    Core.subtract(image, Scalar.all(0), image);
    Rect roi = new Rect(1, 1, mat1.cols() - 2, mat1.rows() - 2);
    Mat temp = new Mat();

    image.submat(roi).copyTo(temp);
    mat1 = temp;
    bmp = Bitmap.createBitmap(mat1.cols(),mat1.rows(),Bitmap.Config.ARGB_8888);
    Utils.matToBitmap(mat1,bmp);
            }catch(CvException ex){
    System.out.println(ex.getMessage());
    ex.getLocalizedMessage();
}

}

click to hide/show revision 2
None

updated 2018-10-03 07:50:25 -0600

berak gravatar image

Floodfill not working also Mat.get(col,row) is returning wrong color

the floodfill is not effecting the bitmap also the Mat.get(col,row) is returning wrong color.

Things I have done:
1) checked that bitmap and matrix are of same size.
2) checked the color both ways RGB and BGR.
3) checked the initial bmp and final bmp (after applying flood fill).
4) checked floodfill with both signatures.

public void flood(int x,int y,int sourceColor,int newColor){
try {
Bitmap bmp;
if(OpenCVLoader.initDebug()){
image = new Mat();
mat1 = new Mat();
Utils.bitmapToMat(bmp2,mat1);
image = Mat.zeros(mat1.rows()+2,mat1.cols()+2,CvType.CV_8U);
if(bmp2.getWidth()==mat1.cols()){}
}
int k = mat1.channels();
int col = bmp2.getPixel(x, y);
int alpha = col & 0xFF000000;
int red = (col & 0x00FF0000) >> 16;
int green = (col & 0x0000FF00) >> 8;
int blue = (col & 0x000000FF);
double[] tt = (mat1.get(x,y));
Imgproc.cvtColor(mat1,mat1,Imgproc.COLOR_BGRA2BGR);
tt = (mat1.get(x,y));

(mat1.get(x,y));
 //Imgproc.floodFill(mat1,image,p1,new Scalar(blue,green,red),new Rect(),new Scalar(230),new Scalar(220),4 + (255<<8) + Imgproc.FLOODFILL_MASK_ONLY);
 Imgproc.floodFill(mat1,image,p1,new Scalar(255,255,255));
  Core.subtract(image, Scalar.all(0), image);
  Rect roi = new Rect(1, 1, mat1.cols() - 2, mat1.rows() - 2);
 Mat temp = new Mat();
 image.submat(roi).copyTo(temp);
 mat1 = temp;
 bmp = Bitmap.createBitmap(mat1.cols(),mat1.rows(),Bitmap.Config.ARGB_8888);
 Utils.matToBitmap(mat1,bmp);
  }catch(CvException ex){
 System.out.println(ex.getMessage());
 ex.getLocalizedMessage();
 }
}

}