Example usage for org.opencv.imgproc Imgproc floodFill

List of usage examples for org.opencv.imgproc Imgproc floodFill

Introduction

In this page you can find the example usage for org.opencv.imgproc Imgproc floodFill.

Prototype

public static int floodFill(Mat image, Mat mask, Point seedPoint, Scalar newVal) 

Source Link

Usage

From source file:classes.TextRecognitionPreparer.java

public static ArrayList<String> generateRecognizableImagesNames(Mat img, Scalar userPickedColor, String imageID,
        HttpServletRequest request) {/*from w w w .  j  av a2s  . c  om*/

    ArrayList<String> imageNames = new ArrayList<String>();

    Mat filledImage = img.clone();
    Scalar newVal = new Scalar(userPickedColor.val[2], userPickedColor.val[1], userPickedColor.val[0]);

    Imgproc.floodFill(filledImage, new Mat(), new Point(0, 0), newVal);
    String file1 = imageID + "_filledImage.png";
    //        Highgui.imwrite(file1, filledImage);
    imageNames.add(ImageUtils.saveImage(filledImage, file1, request));

    Mat filledGrayImage = new Mat();
    Imgproc.cvtColor(filledImage, filledGrayImage, Imgproc.COLOR_BGR2GRAY);
    String file2 = imageID + "_filledGrayImage.png";
    //        Highgui.imwrite(file2, filledGrayImage);
    imageNames.add(ImageUtils.saveImage(filledGrayImage, file2, request));

    Mat gaussianGrayImage = new Mat();
    Imgproc.GaussianBlur(filledGrayImage, gaussianGrayImage, new Size(0, 0), 3);
    Core.addWeighted(filledGrayImage, 3.5, gaussianGrayImage, -1, 0, gaussianGrayImage);
    String file3 = imageID + "_sharpenedImage.png";
    //        Highgui.imwrite(file3, gaussianGrayImage);
    imageNames.add(ImageUtils.saveImage(gaussianGrayImage, file3, request));

    //        Mat filledBinarizedImage2 = new Mat();
    //        Imgproc.adaptiveThreshold(filledGrayImage, filledBinarizedImage2, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 75, 10);
    //        String file5 = imageID + "_filledBinarizedImage2.png";  
    ////        Highgui.imwrite(file11, filledBinarizedImage2);
    //        imageNames.add(ImageUtils.saveImage(filledBinarizedImage2, file5));
    //        
    //        Mat filledBinarizedImage1 = new Mat();
    //        Imgproc.adaptiveThreshold(filledGrayImage, filledBinarizedImage1, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 15, 4);
    //        String file4 = imageID + "_filledBinarizedImage1.png";  
    ////        Highgui.imwrite(file4, filledBinarizedImage1);
    //        imageNames.add(ImageUtils.saveImage(filledBinarizedImage1, file4));

    return imageNames;
}

From source file:classes.TextRecognitionPreparer.java

public static ArrayList<BufferedImage> generateRecognizableBufferedImages(Mat img, Scalar backgroundColor,
        Scalar userPickedColor) {/*from w  w w  .  java2 s. c o  m*/

    ArrayList<BufferedImage> images = new ArrayList<BufferedImage>();

    Mat filledImage = img.clone();
    Scalar newVal = new Scalar(userPickedColor.val[2], userPickedColor.val[1], userPickedColor.val[0]);

    Imgproc.floodFill(filledImage, new Mat(), new Point(0, 0), newVal);
    images.add(Util.mat2Img(filledImage));

    Mat filledGrayImage = new Mat();
    Imgproc.cvtColor(filledImage, filledGrayImage, Imgproc.COLOR_BGR2GRAY);
    images.add(Util.mat2Img(filledGrayImage));

    Mat gaussianGrayImage = new Mat();
    Imgproc.GaussianBlur(filledGrayImage, gaussianGrayImage, new Size(0, 0), 3);
    Core.addWeighted(filledGrayImage, 3.5, gaussianGrayImage, -1, 0, gaussianGrayImage);
    images.add(Util.mat2Img(gaussianGrayImage));

    Mat filledBinarizedImage2 = new Mat();
    Imgproc.adaptiveThreshold(filledGrayImage, filledBinarizedImage2, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,
            Imgproc.THRESH_BINARY, 75, 10);
    images.add(Util.mat2Img(filledBinarizedImage2));

    Mat filledBinarizedImage1 = new Mat();
    Imgproc.adaptiveThreshold(filledGrayImage, filledBinarizedImage1, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,
            Imgproc.THRESH_BINARY, 15, 4);
    images.add(Util.mat2Img(filledBinarizedImage1));

    return images;
}

From source file:classes.TextRecognitionPreparer.java

public static ArrayList<Mat> generateRecognizableImages(Mat img, Scalar backgroundColor,
        Scalar userPickedColor) {/*w w  w. ja v  a  2  s  . c o  m*/

    ArrayList<Mat> images = new ArrayList<Mat>();

    Mat filledImage = img.clone();
    Scalar newVal = new Scalar(userPickedColor.val[2], userPickedColor.val[1], userPickedColor.val[0]);
    Imgproc.floodFill(filledImage, new Mat(), new Point(0, 0), newVal);
    String file1 = "filledImage.png";
    //        Highgui.imwrite(file1, filledImage);
    images.add(filledImage);

    Mat filledGrayImage = new Mat();
    Imgproc.cvtColor(filledImage, filledGrayImage, Imgproc.COLOR_BGR2GRAY);
    String file2 = "filledGrayImage.png";
    //        Highgui.imwrite(file2, filledGrayImage);
    images.add(filledGrayImage);

    Mat gaussianGrayImage = new Mat();
    Imgproc.GaussianBlur(filledGrayImage, gaussianGrayImage, new Size(0, 0), 3);
    Core.addWeighted(filledGrayImage, 3.5, gaussianGrayImage, -1, 0, gaussianGrayImage);
    //        Core.addWeighted(filledGrayImage, 2.5, gaussianGrayImage, -0.5, 0, gaussianGrayImage);
    String file3 = "sharpenedImage.png";
    //        Highgui.imwrite(file3, gaussianGrayImage);
    images.add(gaussianGrayImage);

    Mat filledBinarizedImage = new Mat();
    Imgproc.adaptiveThreshold(filledGrayImage, filledBinarizedImage, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,
            Imgproc.THRESH_BINARY, 15, 4);
    String file4 = "filledBinarizedImage.png";
    //        Highgui.imwrite(file4, filledBinarizedImage);
    images.add(filledBinarizedImage);

    //        BackgroundSubtractorMOG2 backgroundSubtractorMOG2 = new BackgroundSubtractorMOG2();
    //        Mat foregroundMask = new Mat();
    //        backgroundSubtractorMOG2.apply(img, foregroundMask);
    //        Highgui.imwrite("mFGMask.png", foregroundMask);

    Scalar fillingColor = cluster(userPickedColor, img, 3);

    Mat replacedColor = replaceColor(img, backgroundColor, fillingColor);
    String file5 = "replacedColor.png";
    //        Highgui.imwrite(file5, replacedColor);
    images.add(replacedColor);

    Mat grayImage = new Mat();
    Imgproc.cvtColor(replacedColor, grayImage, Imgproc.COLOR_BGR2GRAY);
    String file6 = "grayImage.png";
    //        Highgui.imwrite(file6, grayImage);
    images.add(grayImage);

    Mat binarized = new Mat();
    Imgproc.adaptiveThreshold(grayImage, binarized, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY,
            15, 4);
    String file7 = "binarized.png";
    //        Highgui.imwrite(file7, binarized);
    images.add(binarized);

    Mat colorReplacedEqualized = equalizeIntensity(replacedColor);
    String file8 = "colorReplacedEqualized.png";
    //        Highgui.imwrite(file8, colorReplacedEqualized);
    images.add(colorReplacedEqualized);

    Mat colorReducedImage = reduceColor(replacedColor, 64);
    String file9 = "replacedColorColorReduced.png";
    //        Highgui.imwrite(file9, colorReducedImage);
    images.add(colorReducedImage);

    // Equalizing image
    Mat colorReducedEqualized = equalizeIntensity(colorReducedImage);
    String file10 = "colorReducedEqualized.png";
    //        Highgui.imwrite(file10, colorReducedEqualized);
    images.add(colorReducedEqualized);

    return images;

}

From source file:cmib_4_4.Countour.java

public static void main(String args[]) {

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat image = Highgui.imread("input1.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE);
    Mat image1 = Highgui.imread("input1.jpg", Highgui.CV_LOAD_IMAGE_GRAYSCALE);
    Mat image4 = Highgui.imread("input1.jpg");
    Imgproc.threshold(image1, image1, 0, 255, THRESH_OTSU);
    Imgproc.Canny(image1, image1, Imgproc.THRESH_BINARY_INV + Imgproc.THRESH_OTSU,
            Imgproc.THRESH_BINARY_INV + Imgproc.THRESH_OTSU);
    Mat image2 = Mat.zeros(image.rows() + 2, image.cols() + 2, CV_8U);
    List<MatOfPoint> contours = new ArrayList<MatOfPoint>();
    Imgproc.findContours(image1, contours, new Mat(), Imgproc.RETR_LIST, Imgproc.CHAIN_APPROX_SIMPLE);

    for (int i = 0; i < contours.size(); i++) {

        if (Imgproc.contourArea(contours.get(i)) > 100) {

            Rect rect = Imgproc.boundingRect(contours.get(i));
            Imgproc.floodFill(image1, image2, new Point(150, 150), new Scalar(255));
            Rect rectCrop = new Rect(rect.x, rect.y, rect.width, rect.height);
            Mat image_roi_rgb = new Mat(image4, rectCrop);
            Highgui.imwrite("crop2.jpg", image_roi_rgb);
            if (rect.height > 28) {

                Core.rectangle(image, new Point(rect.x, rect.y),
                        new Point(rect.x + rect.width, rect.y + rect.height), new Scalar(0, 0, 255));
            }/* w ww.ja v a2  s  .c o  m*/
        }
    }
    Highgui.imwrite("falciparum2.jpg", image);

}

From source file:org.openpnp.vision.FluentCv.java

License:Open Source License

public FluentCv floodFill(Point seedPoint, Color color, String... tag) {
    Mat mask = new Mat();
    Imgproc.floodFill(mat, mask, seedPoint, colorToScalar(color));
    return store(mat, tag);
}