Example usage for org.opencv.core Core bitwise_not

List of usage examples for org.opencv.core Core bitwise_not

Introduction

In this page you can find the example usage for org.opencv.core Core bitwise_not.

Prototype

public static void bitwise_not(Mat src, Mat dst) 

Source Link

Usage

From source file:Questao1.java

void not() {
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

    imagemBinaria();//  w  w  w  . j a  v a2 s  .  c o  m
    Core.bitwise_not(image2bin, output);
    normalizarBinario();

    Imgcodecs.imwrite("not.jpg", output);
    showResult("not.jpg");
}

From source file:arlocros.Utils.java

License:Apache License

static public Mat tresholdContrastBlackWhite(Mat srcImage, int filterBlockSize, double subtractedConstant,
        boolean invertBlackWhiteColor) {

    final Mat transformMat = new Mat(1, 3, CvType.CV_32F);
    final int row = 0;
    final int col = 0;
    transformMat.put(row, col, 0.33, 0.33, 0.34);

    final Mat grayImage = new Mat(srcImage.height(), srcImage.width(), CvType.CV_8UC1);
    Core.transform(srcImage, grayImage, transformMat);

    Mat thresholdedImage = new Mat(grayImage.height(), grayImage.width(), CvType.CV_8UC1);
    Imgproc.adaptiveThreshold(grayImage, thresholdedImage, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C,
            Imgproc.THRESH_BINARY, filterBlockSize, subtractedConstant);
    grayImage.release();//from   w ww  .j av  a 2 s  . c  o m

    if (invertBlackWhiteColor) {
        final Mat invertedImage = new Mat(thresholdedImage.height(), thresholdedImage.width(), CvType.CV_8UC1);
        Core.bitwise_not(thresholdedImage, invertedImage);
        thresholdedImage.release();
        thresholdedImage = invertedImage;
    }

    final Mat coloredImage = new Mat(thresholdedImage.height(), thresholdedImage.width(), CvType.CV_8UC3);
    Imgproc.cvtColor(thresholdedImage, coloredImage, Imgproc.COLOR_GRAY2RGB);
    thresholdedImage.release();
    return coloredImage;
}

From source file:com.astrocytes.core.operationsengine.CoreOperations.java

License:Open Source License

/**
 * Invert image.//from   w ww.jav  a2  s  .  co m
 *
 * @param src - source image.
 * @return inverted image.
 */
public static Mat invert(Mat src) {
    Mat dest = new Mat();
    Core.bitwise_not(src, dest);
    return dest;
}

From source file:com.compta.firstak.notedefrais.MainActivity.java

public void Opencv(String imageName) {
        bitmap = BitmapFactory.decodeFile(imageName);
        Mat imageMat = new Mat();
        org.opencv.android.Utils.bitmapToMat(bitmap, imageMat);

        Imgproc.cvtColor(imageMat, imageMat, Imgproc.COLOR_BGR2GRAY);
        // 1) Apply gaussian blur to remove noise
        Imgproc.GaussianBlur(imageMat, imageMat, new Size(9, 9), 0);
        // 2) AdaptiveThreshold -> classify as either black or white
        Imgproc.adaptiveThreshold(imageMat, imageMat, 255, Imgproc.ADAPTIVE_THRESH_MEAN_C, Imgproc.THRESH_BINARY, 5,
                2);//from  w w  w . ja va  2 s .  c  om

        // 3) Invert the image -> so most of the image is black
        Core.bitwise_not(imageMat, imageMat);

        // 4) Dilate -> fill the image using the MORPH_DILATE
        Mat kernel = Imgproc.getStructuringElement(Imgproc.MORPH_DILATE, new Size(3, 3), new Point(1, 1));
        Imgproc.dilate(imageMat, imageMat, kernel);

        org.opencv.android.Utils.matToBitmap(imageMat, bitmap);
        mImageViewer.setImageBitmap(bitmap);
        ByteArrayOutputStream stream1 = new ByteArrayOutputStream();
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream1);
        byteArray = stream1.toByteArray();
    }

From source file:com.sikulix.core.Finder.java

License:Open Source License

private Mat doFindMatch(Element target, Mat base, Mat probe) {
    if (SX.isNull(probe)) {
        probe = target.getContent();//from  ww w .j av a2s  .  c o m
    }
    Mat result = new Mat();
    Mat plainBase = base;
    Mat plainProbe = probe;
    if (!target.isPlainColor()) {
        Imgproc.matchTemplate(base, probe, result, Imgproc.TM_CCOEFF_NORMED);
    } else {
        if (target.isBlack()) {
            Core.bitwise_not(base, plainBase);
            Core.bitwise_not(probe, plainProbe);
        }
        Imgproc.matchTemplate(plainBase, plainProbe, result, Imgproc.TM_SQDIFF_NORMED);
        Core.subtract(Mat.ones(result.size(), CvType.CV_32F), result, result);
    }
    return result;
}

From source file:ctPrincipal.Operacoes.java

String realizarOperacoes(int op) {
    String resultImgOutput = "";
    switch (op) {
    case 1://and
        imagemBinaria();/*  w  w w  .j a  v a2s  .co  m*/
        Core.bitwise_and(image1bin, image2bin, output);
        normalizarBinario();
        Imgcodecs.imwrite("OutputImg/and.jpg", output);
        resultImgOutput = "OutputImg/and.jpg";
        break;
    case 2://or
        imagemBinaria();
        Core.bitwise_or(image1bin, image2bin, output);
        normalizarBinario();
        Imgcodecs.imwrite("OutputImg/or.jpg", output);
        resultImgOutput = "OutputImg/or.jpg";
        break;
    case 3://xor
        imagemBinaria();
        Core.bitwise_xor(image1bin, image2bin, output);
        normalizarBinario();
        Imgcodecs.imwrite("OutputImg/xor.jpg", output);
        resultImgOutput = "OutputImg/xor.jpg";
        break;
    case 4://not
        Core.bitwise_not(image1bin, output);
        Imgcodecs.imwrite("OutputImg/not.jpg", output);
        resultImgOutput = "OutputImg/not.jpg";
        break;
    case 5://soma
        Core.add(image1, image2, output);
        Imgcodecs.imwrite("OutputImg/soma.jpg", output);
        resultImgOutput = "OutputImg/soma.jpg";
        break;
    case 6://subtracao
        Core.subtract(image1, image2, output);
        Imgcodecs.imwrite("OutputImg/subtracao.jpg", output);
        resultImgOutput = "OutputImg/subtracao.jpg";
        break;
    case 7:// multiplicacao
        Core.multiply(image1, image2, output);
        Imgcodecs.imwrite("OutputImg/multiplicacao.jpg", output);
        resultImgOutput = "OutputImg/multiplicacao.jpg";
        break;
    case 8://divisao
        Core.divide(image1, image2, output);
        Imgcodecs.imwrite("OutputImg/divisao.jpg", output);
        resultImgOutput = "OutputImg/divisao.jpg";
        break;
    }

    return resultImgOutput;
}

From source file:gab.opencv.OpenCV.java

License:Open Source License

/**
 * Invert the image./*from w w w .  j a  v  a 2  s  .c  o  m*/
 * See: http://docs.opencv.org/java/org/opencv/core/Core.html#bitwise_not(org.opencv.core.Mat, org.opencv.core.Mat)
 * 
 */
public void invert() {
    Core.bitwise_not(getCurrentMat(), getCurrentMat());
}

From source file:gab.opencv.OpenCVProcessingUtils.java

License:Open Source License

public void invert() {
    Core.bitwise_not(getCurrentMat(), getCurrentMat());
}

From source file:karthik.Barcode.MatrixBarcode.java

License:Open Source License

private void calcHistograms() {
    /* calculate histogram by masking for angles inside each bin, thresholding to set all those values to 1
       and then creating an integral image. We can now calculate histograms for any size tile within 
       the original image more efficiently than by using the built in calcHist method which would have to 
       recalculate the histogram for every tile size.
    */// w ww  .  j a  va 2 s  .c  o  m
    Mat target;
    angles = img_details.gradient_direction.clone();
    target = img_details.temp_integral;

    for (int binRange = 1, integralIndex = 0; binRange < 181; binRange += img_details.BIN_WIDTH, integralIndex++) {
        target.setTo(ZERO_SCALAR);

        img_details.gradient_direction.copyTo(angles);
        Core.inRange(img_details.gradient_direction, scalarDict.get(binRange),
                scalarDict.get(binRange + img_details.BIN_WIDTH), mask);
        Core.bitwise_not(mask, mask);
        angles.setTo(ZERO_SCALAR, mask);

        Imgproc.threshold(angles, target, 0, 1, Imgproc.THRESH_BINARY);
        Imgproc.integral(target, target);
        target.get(0, 0, img_details.histIntegralArrays[integralIndex]);
    }

    // there is some problem if the created integral image does not have exactly one channel
    assert (target.channels() == 1) : "Integral does not have exactly one channel";

}

From source file:org.sikuli.script.Finder.java

License:MIT License

private Mat doFindMatch(Probe probe, Mat base, Mat target) {
    Mat res = new Mat();
    Mat bi = new Mat();
    Mat pi = new Mat();
    if (!probe.img.isPlainColor()) {
        Imgproc.matchTemplate(base, target, res, Imgproc.TM_CCOEFF_NORMED);
    } else {//  w w w.j a v  a  2s  . c o  m
        if (probe.img.isBlack()) {
            Core.bitwise_not(base, bi);
            Core.bitwise_not(target, pi);
        } else {
            bi = base;
            pi = target;
        }
        Imgproc.matchTemplate(bi, pi, res, Imgproc.TM_SQDIFF_NORMED);
        Core.subtract(Mat.ones(res.size(), CvType.CV_32F), res, res);
    }
    return res;
}